| | |
| | | |
| | | // 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 |
| | |
| | | |
| | | 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; |
| | | |
| | |
| | | |
| | | // 短连接方式发送 |
| | | 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) { |
| | |
| | | |
| | | // 短连接方式接受 |
| | | 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) { |
| | |
| | | } |
| | | |
| | | 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; |
| | | |
| | |
| | | |
| | | 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); |
| | | |
| | | |
| | | } |
| | | |