From 76494a2d103c88d1c3888a6f0348a6b7e31b564d Mon Sep 17 00:00:00 2001 From: patacongo Date: Thu, 7 Mar 2013 17:59:21 +0000 Subject: Fix network poll() issue: don't interrupt poll if socket not connected. Listen sockets are not connected and the poll() is waiting for connection events. git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5717 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/net/net_poll.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'nuttx/net') diff --git a/nuttx/net/net_poll.c b/nuttx/net/net_poll.c index 1838f541e..583d469a7 100644 --- a/nuttx/net/net_poll.c +++ b/nuttx/net/net_poll.c @@ -253,9 +253,24 @@ static inline int net_pollsetup(FAR struct socket *psock, fds->revents |= (POLLOUT & fds->events); } - /* Check for a loss of connection events */ + /* Check for a loss of connection events. We need to be careful here. + * There are four possibilities: + * + * 1) The socket is connected and we are waiting for data availability + * events. + * 2) This is a listener socket that was never connected and we are + * waiting for connection events. + * 3) This socket was previously connected, but the peer has gracefully + * closed the connection. + * 4) This socket was previously connected, but we lost the connection + * due to some exceptional event. + * + * We can detect 1) and 3), but 2) and 4) appear the same. So we + * do the best we can for now: We will report POLLHUP if the socket + * has been gracefully closed. + */ - if (!_SS_ISCONNECTED(psock->s_flags)) + if (_SS_ISCLOSED(psock->s_flags)) { fds->revents |= (POLLERR | POLLHUP); } -- cgit v1.2.3