On Wed, 2015-10-21 at 11:49 +0100, Alan Burlison wrote: > On 21/10/2015 11:25, David Laight wrote: > > >> The problem with poll() is that it returns immediately when passed a FD > >> that is in the listening state. rather than waiting until there's an > >> incoming connection to handle. As I said, that means you can't use > >> poll() to multiplex between read/write/accept sockets. > > > > That seems to work for me... > > In my test case I was setting all the available event bits in > pollfd.events to see what came back. With poll() on a listen() socket > you get an immediate return with bits set in revents indicating the > socket is available for output, which of course it isn't. Indeed an > attempt to write to it fails. If you remove the output event bits in > pollfd.events then the poll() waits as expected until there's an > incoming connection on the socket. > > I suppose one answer is "Well, don't do that then" but returning an > output indication on a socket that's in listen() seems rather odd. > > With POLLOUT|POLLWRNORM|POLLWRBAND: > > main: polling #1 > [returns immediately] > main: poll #1: Success > poll fd: 0 revents: POLLOUT POLLWRBAND > main: write #1: Transport endpoint is not connected > > Without POLLOUT|POLLWRNORM|POLLWRBAND: > > main: polling #1 > [waits for connection] > main: poll #1: Success > poll fd: 0 revents: POLLIN POLLRDNORM >
This works for me. Please double check your programs 242046 poll([{fd=3, events=POLLIN|POLLOUT|POLLWRNORM|POLLWRBAND}], 1, 4294967295 <unfinished ...> 242046 <... poll resumed> ) = 1 ([{fd=3, revents=POLLIN}]) 242046 accept(3, {sa_family=AF_INET6, sin6_port=htons(35888), inet_pton(AF_INET6, "::ffff:10.246.7.151", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, [28]) = 4 242046 close(4) = 0 242046 poll([{fd=3, events=POLLIN|POLLOUT|POLLWRNORM|POLLWRBAND}], 1, 4294967295) = 1 ([{fd=3, revents=POLLIN}]) 242046 accept(3, {sa_family=AF_INET6, sin6_port=htons(35890), inet_pton(AF_INET6, "::ffff:10.246.7.151", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, [28]) = 4 242046 close(4) = 0 242046 poll([{fd=3, events=POLLIN|POLLOUT|POLLWRNORM|POLLWRBAND}], 1, 4294967295) = 1 ([{fd=3, revents=POLLIN}]) 242046 accept(3, {sa_family=AF_INET6, sin6_port=htons(35892), inet_pton(AF_INET6, "::ffff:10.246.7.151", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, [28]) = 4 242046 close(4) = 0 242046 poll([{fd=3, events=POLLIN|POLLOUT|POLLWRNORM|POLLWRBAND}], 1, 4294967295) = 1 ([{fd=3, revents=POLLIN}]) 242046 accept(3, {sa_family=AF_INET6, sin6_port=htons(35894), inet_pton(AF_INET6, "::ffff:10.246.7.151", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, [28]) = 4 242046 close(4) = 0 poll() only cares about POLLIN | POLLRDNORM for a listener. static inline unsigned int inet_csk_listen_poll(const struct sock *sk) { return !reqsk_queue_empty(&inet_csk(sk)->icsk_accept_queue) ? (POLLIN | POLLRDNORM) : 0; } if (sk->sk_state == TCP_LISTEN) return inet_csk_listen_poll(sk); -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html