int rc = poll(fds,1,-1); 让我们说远程同伴关闭。 socket在这里打破。 在这种情况下,轮询系统调用返回-1或 将返回> 0,并将断开连接报告为FD上的错误事件。是否知道远程套接字是关闭还是断开?
而且,你会轮询0超时回报。 int rc = poll(fds,nfds,0);
int rc = poll(fds,1,-1); 让我们说远程同伴关闭。 socket在这里打破。 在这种情况下,轮询系统调用返回-1或 将返回> 0,并将断开连接报告为FD上的错误事件。是否知道远程套接字是关闭还是断开?
而且,你会轮询0超时回报。 int rc = poll(fds,nfds,0);
如果插座休息,poll()
将返回> 0,那么你将要检查的recv
的返回值,以便知道如果套接字断开(recv()
会在这种情况下返回0)。
而且,你会轮询0超时回报。 int rc = poll(fds,nfds, 0);
poll()
会立即返回,并返回值可以> = 0
你真的应该读the poll()
manpage,有所有你需要知道的。
从手册页:
The field revents is an output parameter, filled by the kernel with the events
that actually occurred. The bits returned in revents can include any of those
specified in events, or one of the values POLLERR, POLLHUP, or POLLNVAL.
(These three bits are meaningless in the events field, and will be set in the
revents field whenever the corresponding condition is true.)
If none of the events requested (and no error) has occurred for any of the file
descriptors, then poll() blocks until one of the events occurs.
Return Value
On success, a positive number is returned; this is the number of structures which
have nonzero revents fields (in other words, those descriptors with events or
errors reported). A value of 0 indicates that the call timed out and no file
descriptors were ready. On error, -1 is returned, and errno is set appropriately.
因此,它明确表示,如果在FD返回值> 0错误,并且revents的领域充满此时,相应的价值。 POLLERR例如。
如果FD [返回值> 0'中存在错误,它不会'清除[说]。它说,如果连接上有一个传入的错误事件,返回值是>零。有一个区别。并且由同伴有序地关闭并不是一个错误,而是一个阅读事件。 – EJP
不,它不。它只知道在套接字上发生了什么,以及它是一个读事件,一个写事件还是一个错误事件。对等方断开连接计为读取事件。
当你尝试过时发生了什么? –