wangzhengquan
2020-07-23 950e8841a4eada051108084606c3205e67cac804
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;
      //初始化消息queue
@@ -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);
}