在TCP服务器/客户端中,我们对绑定fd进行轮询(在套接字连接期间收到fd并绑定到某些IP)。我想知道如果我们对侦听套接字进行轮询会有什么影响(在接受呼叫期间接收到套接字fd)?监听套接字上的轮询是否仍会出现与close_wait状态套接字问题相关的问题? 示例代码如下: -
struct pollfd pfd;
pfd.fd = sockfd; /*listening socket fd got during accept call*/
pfd.events = POLLIN;
ret = poll(&pfd, 1, 60000);
if (ret == 0 || errno == EINTR) {
*err = SOCKET_ERR_READ_TIMEOUT;
*size = 0;
return SOCKET_FAILURE;
}else if (ret < 0) {
close(sockfd);
return SOCKET_FAILURE;
}
ret = recv(sockfd, content, *size , 0);
if (ret == -1) {
close(sockfd);
*size = 0;
return SOCKET_FAILURE;
} else if (ret == 0) {
close(sockfd);
*size = 0;
return SOCKET_FAILURE;
}
*size = ret;
return SOCKET_SUCCESS;