| | |
| | | } |
| | | |
| | | |
| | | NetModSocket::~NetModSocket() { |
| | | |
| | | } |
| | | |
| | | int NetModSocket::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) { |
| | | |
| | |
| | | char mapKey[256]; |
| | | void *recv_buf; |
| | | int recv_size; |
| | | char response_head_bs[NET_MODE_RESPONSE_HEAD_LENGTH]; |
| | | net_mod_request_head_t request_head; |
| | | net_mod_response_head_t response_head; |
| | | std::map<std::string, rio_t*>::iterator mapIter; |
| | |
| | | request_head.mod = REQ_REP; |
| | | request_head.key = node->key; |
| | | request_head.content_length = send_size; |
| | | if( (n = rio_writen(rio->rio_fd, &request_head, sizeof(request_head))) != sizeof(request_head)) { |
| | | if(rio_writen(rio->rio_fd, NetModSocket::encode_request_head(request_head), NET_MODE_REQUEST_HEAD_LENGTH) != NET_MODE_REQUEST_HEAD_LENGTH) { |
| | | err_exit(errno, "NetModSocket::send head rio_writen"); |
| | | |
| | | } |
| | | |
| | | if( (n = rio_writen(rio->rio_fd, send_buf, send_size)) != send_size ) { |
| | | if(rio_writen(rio->rio_fd, send_buf, send_size) != send_size ) { |
| | | err_exit(errno, "NetModSocket::send conent rio_writen"); |
| | | } |
| | | |
| | | if ((n = rio_readnb(rio, &response_head, sizeof(response_head))) != sizeof(response_head)) { |
| | | |
| | | if ( rio_readnb(rio, response_head_bs, NET_MODE_RESPONSE_HEAD_LENGTH) != NET_MODE_RESPONSE_HEAD_LENGTH) { |
| | | err_exit(errno, "NetModSocket::send rio_readnb"); |
| | | } |
| | | |
| | | response_head = NetModSocket::decode_response_head(response_head_bs); |
| | | |
| | | recv_buf = malloc(response_head.content_length); |
| | | if(recv_buf == NULL) { |
| | |
| | | |
| | | // } |
| | | |
| | | NetModSocket::~NetModSocket() { |
| | | |
| | | void * NetModSocket::encode_request_head(net_mod_request_head_t & request) { |
| | | char * head = (char *)malloc(NET_MODE_REQUEST_HEAD_LENGTH); |
| | | PUT(head, htonl(request.mod)); |
| | | PUT(head + 4, htonl(request.key)); |
| | | PUT(head + 8, htonl(request.content_length)); |
| | | return head; |
| | | } |
| | | |
| | | net_mod_request_head_t NetModSocket::decode_request_head(void *_headbs) { |
| | | char *headbs = (char *)_headbs; |
| | | net_mod_request_head_t head; |
| | | head.mod = ntohl(GET(headbs)); |
| | | head.key = ntohl(GET(headbs + 4)); |
| | | head.content_length = ntohl(GET(headbs + 8)); |
| | | return head; |
| | | } |
| | | |
| | | void * NetModSocket::encode_response_head(net_mod_response_head_t & response) { |
| | | char * head = (char *)malloc(NET_MODE_RESPONSE_HEAD_LENGTH); |
| | | PUT(head, htonl(response.content_length)); |
| | | return head; |
| | | } |
| | | |
| | | net_mod_response_head_t NetModSocket::decode_response_head(void *_headbs) { |
| | | char *headbs = (char *)_headbs; |
| | | net_mod_response_head_t head; |
| | | head.content_length = ntohl(GET(headbs)); |
| | | return head; |
| | | } |