| | |
| | | socklen_t clientlen; |
| | | struct sockaddr_storage clientaddr; |
| | | char portstr[32]; |
| | | if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) err_msg(errno, "signal"); |
| | | if (Signal(SIGPIPE, SIG_IGN) == SIG_ERR) err_msg(errno, "signal"); |
| | | |
| | | //shmModSocket = new ShmModSocket; |
| | | sprintf(portstr, "%d", port); |
| | |
| | | } |
| | | |
| | | request_head = NetModSocket::decode_request_head(request_head_bs); |
| | | // printf("server received request from host = %s:%d\n", request_head.host, request_head.port); |
| | | |
| | | if(request_head.content_length > max_buf) { |
| | | |
| | |
| | | } |
| | | |
| | | if(request_head.mod == REQ_REP) { |
| | | // printf("server response===========\n"); |
| | | |
| | | memcpy(response_head.host, request_head.host, NI_MAXHOST); |
| | | response_head.port = request_head.port; |
| | | response_head.key = request_head.key; |
| | | if(shmModSocket.sendandrecv_unsafe(buf, request_head.content_length, request_head.key, &recv_buf, &recv_size) != 0) { |
| | | |
| | | // 没有对应的key |
| | | response_head.code = 1; |
| | | response_head.content_length = 0; |
| | | if( rio_writen(connfd, NetModSocket::encode_response_head(response_head), NET_MODE_RESPONSE_HEAD_LENGTH) != NET_MODE_RESPONSE_HEAD_LENGTH ) |
| | | return -1; |
| | | //Rio_writen(connfd, recv_buf, recv_size); |
| | | } else { |
| | | // 发送成功 |
| | | response_head.code = 0; |
| | | response_head.content_length = recv_size; |
| | | |