src/socket/net_mod_socket.c | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/socket/net_mod_socket.h | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/socket/net_mod_socket.c
@@ -15,7 +15,8 @@ NetModSocket::NetModSocket() { if (Signal(SIGPIPE, SIG_IGN) == SIG_ERR) err_msg(errno, "signal"); if (Signal(SIGPIPE, SIG_IGN) == SIG_ERR) logger->error(errno, "NetModSocket::NetModSocket signal"); } @@ -56,10 +57,12 @@ /* Free thread-specific data buffer */ void NetModSocket::_destructor_(void *_pool) void NetModSocket::_destroyConnPool_(void *_pool) { NetConnPool *mpool = (NetConnPool *)_pool; delete mpool; logger->debug("destory connPool"); } /* One-time key creation function */ @@ -70,7 +73,7 @@ /* Allocate a unique thread-specific data key and save the address of the destructor for thread-specific data buffers */ ret = pthread_key_create(&poolKey, _destructor_); ret = pthread_key_create(&poolKey, _destroyConnPool_); if (ret != 0) { logger->error(ret, "pthread_key_create"); exit(1); @@ -83,8 +86,6 @@ int i, n, recv_size, connfd; net_node_t *node; void *recv_buf; net_mod_request_head_t request_head = {}; @@ -97,7 +98,6 @@ NetConnPool *mpool; /* Make first caller allocate key for thread-specific data */ ret = pthread_once(&once, _createKey_); if (ret != 0) { LoggerFactory::getLogger()->error(errno, "NetModSocket::_sendandrecv_ pthread_once"); src/socket/net_mod_socket.h
@@ -70,17 +70,22 @@ // pool req_resp_pool; // request header 编码为网络传输的字节 static void * encode_request_head(net_mod_request_head_t & request); // 解码request header static net_mod_request_head_t decode_request_head(void *headbs); static void * encode_response_head(net_mod_response_head_t & response); static net_mod_response_head_t decode_response_head(void *_headbs); static void _destructor_(void *_pool); // 销毁threadlocal pool static void _destroyConnPool_(void *_pool); // 创建thread local key static void _createKey_(void); //读取返回信息 int read_response(int clientfd, net_mod_recv_msg_t *recv_msg); // 发送请求信息 int write_request(int clientfd, net_mod_request_head_t &request_head, void *send_buf, int send_size, void *topic_buf, int topic_size); int _sendandrecv_(net_node_t *node_arr, int node_arr_len, void *send_buf, int send_size,