diff options
Diffstat (limited to 'nuttx/net/net_poll.c')
-rw-r--r-- | nuttx/net/net_poll.c | 19 |
1 files changed, 17 insertions, 2 deletions
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); } |