| | |
| | | /* Wait for listening/connected descriptor(s) to become ready */ |
| | | pool.ready_set = pool.read_set; |
| | | pool.nready = select(pool.maxfd + 1, &pool.ready_set, NULL, NULL, NULL); |
| | | // LoggerFactory::getLogger()->debug("select return \n"); |
| | | /* If listening descriptor ready, add new client to pool */ |
| | | if (FD_ISSET(listenfd, &pool.ready_set)) |
| | | { |
| | |
| | | |
| | | request_head = NetModSocket::decode_request_head(request_head_bs); |
| | | |
| | | // printf("server received request from host = %s:%d, key = %d, timeout=%d,\n", |
| | | // request_head.host, request_head.port , request_head.key, request_head.timeout); |
| | | |
| | | if(request_head.content_length > max_buf) { |
| | | |
| | |
| | | timeout.tv_sec = request_head.timeout / 1000; |
| | | timeout.tv_nsec = (request_head.timeout - timeout.tv_sec * 1000) * 10e6; |
| | | // printf(" timeout.tv_sec = %d, timeout.tv_nsec=%ld\n", timeout.tv_sec, timeout.tv_nsec ); |
| | | ret = shmModSocket.sendandrecv_unsafe_timeout(buf, request_head.content_length, request_head.key, &recv_buf, &recv_size, &timeout); |
| | | ret = shmModSocket.sendandrecv(buf, request_head.content_length, request_head.key, &recv_buf, &recv_size, &timeout, BUS_TIMEOUT_FLAG); |
| | | } |
| | | else if(request_head.timeout == 0) { |
| | | ret = shmModSocket.sendandrecv_unsafe_nowait(buf, request_head.content_length, request_head.key, &recv_buf, &recv_size); |
| | | ret = shmModSocket.sendandrecv(buf, request_head.content_length, request_head.key, &recv_buf, &recv_size, NULL, BUS_NOWAIT_FLAG); |
| | | } |
| | | else if(request_head.timeout == -1) { |
| | | ret = shmModSocket.sendandrecv_unsafe(buf, request_head.content_length, request_head.key, &recv_buf, &recv_size); |
| | | ret = shmModSocket.sendandrecv(buf, request_head.content_length, request_head.key, &recv_buf, &recv_size); |
| | | } |
| | | |
| | | if( ret != 0) { |
| | | logger->error("fail: NetModServerSocket::process_client sendandrecv to %d , %s", request_head.key, bus_strerror(ret)); |
| | | // 转发失败 |
| | | response_head.code = ret; |
| | | response_head.content_length = 0; |
| | |
| | | if (rio_readn(connfd, topic_buf, request_head.topic_length) != request_head.topic_length ) { |
| | | return -1; |
| | | } |
| | | // LoggerFactory::getLogger()->debug("====server pub %s===\n", buf); |
| | | |
| | | memcpy(response_head.host, request_head.host, NI_MAXHOST); |
| | | response_head.port = request_head.port; |
| | | // response_head.key = request_head.key; |
| | |
| | | if(request_head.timeout > 0) { |
| | | timeout.tv_sec = request_head.timeout / 1000; |
| | | timeout.tv_nsec = (request_head.timeout - timeout.tv_sec * 1000) * 10e6; |
| | | ret = shmModSocket.pub_timeout((char*)topic_buf, request_head.topic_length, buf, request_head.content_length, SHM_BUS_KEY, &timeout); |
| | | ret = shmModSocket.pub((char*)topic_buf, request_head.topic_length, buf, request_head.content_length, SHM_BUS_KEY, &timeout, BUS_TIMEOUT_FLAG); |
| | | } |
| | | else if(request_head.timeout == 0) { |
| | | ret = shmModSocket.pub_nowait((char*)topic_buf, request_head.topic_length, buf, request_head.content_length, SHM_BUS_KEY); |
| | | ret = shmModSocket.pub((char*)topic_buf, request_head.topic_length, buf, request_head.content_length, SHM_BUS_KEY, NULL, BUS_NOWAIT_FLAG); |
| | | } |
| | | else if(request_head.timeout == -1) { |
| | | ret = shmModSocket.pub((char*)topic_buf, request_head.topic_length, buf, request_head.content_length, SHM_BUS_KEY); |
| | |
| | | FD_CLR(connfd, &pool.read_set); |
| | | pool.clientfd[i] = -1; |
| | | logger->debug("===server close client %d\n", connfd); |
| | | // printf("===server close client %d\n", connfd); |
| | | } |
| | | |
| | | } |