From 950e8841a4eada051108084606c3205e67cac804 Mon Sep 17 00:00:00 2001
From: wangzhengquan <wangzhengquan85@126.com>
Date: 星期四, 23 七月 2020 17:11:03 +0800
Subject: [PATCH] commit

---
 src/socket/shm_socket.c |   20 ++++++++++++++++----
 1 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/socket/shm_socket.c b/src/socket/shm_socket.c
index 6708469..185ecaf 100644
--- a/src/socket/shm_socket.c
+++ b/src/socket/shm_socket.c
@@ -96,7 +96,8 @@
 
 // print_msg("===accept:", src);
 		client_port = src.port;
-		client_socket = (shm_socket_t *)malloc(sizeof(shm_socket_t));
+		// client_socket = (shm_socket_t *)malloc(sizeof(shm_socket_t));
+		client_socket = shm_open_socket(socket->socket_type);
 		client_socket->port = socket->port;
 		// client_socket->queue= socket->queue;
 		//鍒濆鍖栨秷鎭痲ueue
@@ -211,7 +212,7 @@
 
 int shm_recv(shm_socket_t* socket, void **buf, int *size) {
 	if(socket->socket_type != SHM_SOCKET_STREAM) {
-		err_exit(0, "can not invoke shm_recv method with a socket which is not a SHM_SOCKET_STREAM socket");
+		err_exit(0, "can not invoke shm_recv method in a %d type socket  which is not a SHM_SOCKET_STREAM socket ", socket->socket_type);
 	}
 	shm_msg_t src;
 
@@ -232,6 +233,9 @@
 
 // 鐭繛鎺ユ柟寮忓彂閫�
 int shm_sendto(shm_socket_t *socket, const void *buf, const int size, const int port) {
+	if(socket->socket_type != SHM_SOCKET_DGRAM) {
+		err_exit(0, "Can't invoke shm_sendto method in a %d type socket  which is not a SHM_SOCKET_DGRAM socket ", socket->socket_type);
+	}
 	hashtable_t *hashtable = mm_get_hashtable();
 
 	if(socket->queue == NULL) {
@@ -272,6 +276,9 @@
 
 // 鐭繛鎺ユ柟寮忔帴鍙�
 int shm_recvfrom(shm_socket_t *socket, void **buf, int *size, int *port){
+	if(socket->socket_type != SHM_SOCKET_DGRAM) {
+		err_exit(0, "Can't invoke shm_recvfrom method in a %d type socket  which is not a SHM_SOCKET_DGRAM socket ", socket->socket_type);
+	}
 	hashtable_t *hashtable = mm_get_hashtable();
 	if(socket->queue == NULL) {
 		if(socket->port == -1) {
@@ -303,6 +310,9 @@
 }
 
 int shm_sendandrecv(shm_socket_t *socket, const void *send_buf, const int send_size, const int send_port, void **recv_buf, int *recv_size) {
+	if(socket->socket_type != SHM_SOCKET_DGRAM) {
+		err_exit(0, "Can't invoke shm_sendandrecv method in a %d type socket  which is not a SHM_SOCKET_DGRAM socket ", socket->socket_type);
+	}
 	int recv_port;
 	int rv;
 
@@ -336,11 +346,13 @@
 
 void _server_close_conn_to_client(shm_socket_t* socket, int port) {
 	shm_socket_t *client_socket;
-	auto iter = socket->clientSocketMap->find(port);
+	std::map<int, shm_socket_t* >::iterator iter = socket->clientSocketMap->find(port);
 	if( iter !=  socket->clientSocketMap->end() ) {
+		client_socket = iter->second;
+		free((void *)client_socket);
 		socket->clientSocketMap->erase(iter);
 	}
-	free((void *)client_socket);
+	
 
 }
 

--
Gitblit v1.8.0