| | |
| | | #include "socket_io.h" |
| | | #include <poll.h> |
| | | #include "socket_def.h" |
| | | |
| | | #include "net_conn_pool.h" |
| | | |
| | | |
| | | class NetModServerSocket; |
| | |
| | | |
| | | ShmModSocket shmModSocket; |
| | | // pool req_resp_pool; |
| | | |
| | | NetConnPool *gpool; |
| | | |
| | | pthread_mutex_t sendMutex; |
| | | |
| | | // request header 编码为网络传输的字节 |
| | | static void * encode_request_head(net_mod_request_head_t & request); |
| | |
| | | static void _destroyConnPool_(void *_pool); |
| | | // 创建thread local key |
| | | static void _createConnPoolKey_(void); |
| | | |
| | | |
| | | NetConnPool* _get_threadlocal_pool(); |
| | | NetConnPool* _get_pool(); |
| | | |
| | | //读取返回信息 |
| | | int read_response(int clientfd, net_mod_recv_msg_t *recv_msg); |
| | |
| | | */ |
| | | int force_bind( int key); |
| | | |
| | | |
| | | |
| | | /** |
| | | * 如果建立连接的节点没有接受到消息会一直等待 |
| | | * @brief 如果建立连接的节点没有接受到消息等待timeout的时间后返回 |
| | | * |
| | | * 向node_arr 中的所有网络节点发送请求消息,节点的返回信息汇总并存储在recv_arr中 |
| | | * @node_arr 网络节点组, @node_arr_len该数组长度.如果IP为空则为本地发送。 |
| | | * @send_buf 发送的消息,@send_size 该消息体的长度 |
| | | * @recv_arr 返回的应答消息组,@recv_arr_size 该数组长度 |
| | | * @timeout 等待时间,单位是千分之一秒 |
| | | * @return 成功发送的节点的个数 |
| | | * |
| | | * 优点:1某个节点的故障不会阻塞其他节点。2 性能好。 3 采用thread local技术即保证了线程安全,又可以使用连接池缓存连接 |
| | | */ |
| | | int sendandrecv(net_node_t *node_arr, int arrlen, void *send_buf, int send_size, |
| | | net_mod_recv_msg_t ** recv_arr, int *recv_arr_size) ; |
| | | |
| | | |
| | | /** |
| | | * 如果建立连接的节点没有接受到消息等待timeout的时间后返回 |
| | | * 向node_arr 中的所有网络节点发送请求消息,节点的返回信息汇总并存储在recv_arr中 |
| | | * @node_arr 网络节点组, @node_arr_len该数组长度.如果IP为空则为本地发送。 |
| | | * @send_buf 发送的消息,@send_size 该消息体的长度 |
| | | * @recv_arr 返回的应答消息组,@recv_arr_size 该数组长度 |
| | | * @timeout 等待时间,单位是千分之一秒 |
| | | */ |
| | | * @return 成功发送的节点的个数 |
| | | * 优点:1某个节点的故障不会阻塞其他节点。2 性能好。 3 采用thread local技术即保证了线程安全,又可以使用连接池缓存连接 |
| | | */ |
| | | int sendandrecv_timeout(net_node_t *node_arr, int arrlen, void *send_buf, int send_size, |
| | | net_mod_recv_msg_t ** recv_arr, int *recv_arr_size, int timeout); |
| | | |
| | |
| | | * 缺点:阻塞的,性能不如sendandrecv |
| | | * |
| | | */ |
| | | 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); |
| | | // 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); |
| | | |
| | | |
| | | /** |