| | |
| | | #include "socket_io.h" |
| | | #include <poll.h> |
| | | |
| | | #define OPEN_MAX 1024 |
| | | |
| | | #define GET(p) (*(uint32_t *)(p)) |
| | | #define PUT(p, val) (*(uint32_t *)(p) = (val)) |
| | | |
| | | #define GET_INT32(p) (*(int32_t *)(p)) |
| | | #define PUT_INT32(p, val) (*(int32_t *)(p) = (val)) |
| | | |
| | | |
| | | class NetModServerSocket; |
| | | |
| | |
| | | }; |
| | | |
| | | class NetModSocket { |
| | | struct pool{ /* Represents a pool of connected descriptors */ //line:conc:echoservers:beginpool |
| | | |
| | | int nready; /* Number of ready descriptors from select */ |
| | | int maxi; /* Highwater index into client array */ |
| | | struct pollfd conns[OPEN_MAX]; |
| | | // std::map<std::string, int> connectionMap; |
| | | } ; |
| | | |
| | | |
| | | friend class NetModServerSocket; |
| | | private: |
| | |
| | | // 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); |
| | | |
| | | void init_conn_pool( pool& mpool); |
| | | int connect(pool& mpool, net_node_t* node); |
| | | void close_connect(pool& mpool , int connfd); |
| | | // 销毁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, |