From aa88fc315e563345c4a9ab2667563c02edb967aa Mon Sep 17 00:00:00 2001 From: patacongo Date: Mon, 21 Jan 2013 14:17:11 +0000 Subject: [PATCH] poll was not checking if the socket was still connected git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5543 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/net/net_poll.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/nuttx/net/net_poll.c b/nuttx/net/net_poll.c index 815c6a71df..2e73bd73c2 100644 --- a/nuttx/net/net_poll.c +++ b/nuttx/net/net_poll.c @@ -125,16 +125,22 @@ static uint16_t poll_interrupt(struct uip_driver_s *dev, FAR void *conn, if ((flags & UIP_POLL) != 0) { - eventset |= POLLOUT & fds->events; + eventset |= (POLLOUT & fds->events); } - /* Check for a loss of connection events */ + /* Check for a loss of connection events. + * + * REVISIT: Need to call net_lostconnection() here, but don't have + * the psock instance. What should we do? + */ if ((flags & (UIP_CLOSE|UIP_ABORT|UIP_TIMEDOUT)) != 0) { - eventset |= (POLLERR|POLLHUP); + eventset |= (POLLERR | POLLHUP); } + /* Awaken the caller of poll() is requested event occurred. */ + if (eventset) { fds->revents |= eventset; @@ -192,9 +198,9 @@ static inline int net_pollsetup(FAR struct socket *psock, struct pollfd *fds) goto errout_with_irq; } - /* Initialize the callbcack structure */ + /* Initialize the callback structure */ - cb->flags = UIP_NEWDATA|UIP_BACKLOG|UIP_POLL|UIP_CLOSE|UIP_ABORT|UIP_TIMEDOUT; + cb->flags = (UIP_NEWDATA|UIP_BACKLOG|UIP_POLL|UIP_CLOSE|UIP_ABORT|UIP_TIMEDOUT); cb->priv = (FAR void *)fds; cb->event = poll_interrupt; @@ -212,13 +218,23 @@ static inline int net_pollsetup(FAR struct socket *psock, struct pollfd *fds) if (!sq_empty(&conn->readahead)) #endif { - fds->revents = fds->events & POLLIN; - if (fds->revents != 0) - { - /* If data is available now, the signal the poll logic */ + fds->revents |= (POLLOUT & fds->events); + } - sem_post(fds->sem); - } + /* Check for a loss of connection events */ + + if (!_SS_ISCONNECTED(psock->s_flags)) + { + fds->revents |= (POLLERR | POLLHUP); + } + + /* Check if any requested events are already in effect */ + + if (fds->revents != 0) + { + /* Yes.. then signal the poll logic */ + + sem_post(fds->sem); } uip_unlock(flags);