From d9d5c2d3089345fa858deaf2c0dfbfb304b7a9f6 Mon Sep 17 00:00:00 2001 From: wangzhengquan <wangzhengquan85@126.com> Date: 星期五, 16 十月 2020 20:08:52 +0800 Subject: [PATCH] udpate --- src/socket/net_mod_socket.h | 40 +++++++++++++++++++++++++++++++++++----- 1 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/socket/net_mod_socket.h b/src/socket/net_mod_socket.h index acc6a5d..a68c8cf 100644 --- a/src/socket/net_mod_socket.h +++ b/src/socket/net_mod_socket.h @@ -10,6 +10,8 @@ #define NET_MODE_REQUEST_HEAD_LENGTH 16 #define NET_MODE_RESPONSE_HEAD_LENGTH 4 + + class NetModServerSocket; struct net_node_t @@ -45,11 +47,31 @@ }; class NetModSocket { + struct pool{ /* Represents a pool of connected descriptors */ //line:conc:echoservers:beginpool + int maxfd; /* Largest descriptor in read_set */ + fd_set read_set; /* Set of all active descriptors */ + fd_set ready_read_set; /* Subset of descriptors ready for reading */ + + fd_set write_set; + fd_set ready_write_set; + + fd_set except_set; + fd_set ready_except_set; + + int nready; /* Number of ready descriptors from select */ + int maxi; /* Highwater index into client array */ + int connfd[FD_SETSIZE]; /* Set of active descriptors */ + // net_node_t *nodes[FD_SETSIZE]; + // rio_t clientrio[FD_SETSIZE]; /* Set of active read buffers */ + std::map<int, net_node_t*> connfdNodeMap; + std::map<std::string, int> connectionMap; + } ; + friend class NetModServerSocket; private: - static std::map<std::string, int> connectionMap; - ShmModSocket shmModSocket; - + + ShmModSocket shmModSocket; + pool req_resp_pool; static void * encode_request_head(net_mod_request_head_t & request); static net_mod_request_head_t decode_request_head(void *headbs); @@ -57,8 +79,12 @@ static void * encode_response_head(net_mod_response_head_t & response); static net_mod_response_head_t decode_response_head(void *_headbs); - int connect(const char *host, int port); - void remove_connect(const char *host, int port); + void init_req_rep_req_resp_pool(); + int connect( net_node_t*); + void close_connect(int connfd); + int read_response(int clientfd, net_mod_recv_msg_t *recv_msg); + int write_request(int clientfd, int key, void *send_buf, int send_size); + public: @@ -75,6 +101,10 @@ int sendandrecv(net_node_t *node_arr, int node_arr_len, void *send_buf, int send_size, net_mod_recv_msg_t ** recv_arr, int *recv_arr_size); + + int sendandrecv_safe(net_node_t *node_arr, int node_arr_len, void *send_buf, int send_size, + net_mod_recv_msg_t ** recv_arr, int *recv_arr_size); + /** * 閿�姣乻endandrecv鏂规硶杩斿洖鐨勬秷鎭粍 * @arr 娑堟伅缁� -- Gitblit v1.8.0