diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2013-01-21 14:17:11 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2013-01-21 14:17:11 +0000 |
commit | aa88fc315e563345c4a9ab2667563c02edb967aa (patch) | |
tree | 678b54db4e147eb7bfbb5710efd5980844226be5 /nuttx/net | |
parent | 70cab4d7975291861185e38a12a75f6c232fae56 (diff) | |
download | px4-firmware-aa88fc315e563345c4a9ab2667563c02edb967aa.tar.gz px4-firmware-aa88fc315e563345c4a9ab2667563c02edb967aa.tar.bz2 px4-firmware-aa88fc315e563345c4a9ab2667563c02edb967aa.zip |
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
Diffstat (limited to 'nuttx/net')
-rw-r--r-- | nuttx/net/net_poll.c | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/nuttx/net/net_poll.c b/nuttx/net/net_poll.c index 815c6a71d..2e73bd73c 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); |