http://www.perlmonks.org?node_id=1072356


in reply to Re^11: Help designing a threaded service
in thread Help designing a threaded service

come out of the polling with a new client socket in a can read state
nonsense. They all (or just some of them) come out of the polling with the listening socket in can read state. Poll/epoll/select don't return any new sockets, for that workers have to call accept, which will return connection only to one worker.
use 5.010; use strict; use warnings; use IO::Socket::INET; use IO::Poll; use Time::HiRes; my $port = shift // 7777; my $sock = IO::Socket::INET->new(LocalPort => $port, Listen => 10); $sock->blocking(0); for ( 1 .. 3 ) { my $pid = fork; unless ($pid) { my $poll = IO::Poll->new; $poll->mask( $sock => POLLIN ); while ( $poll->poll >= 0 ) { say "$$ got out of poll"; my $cli = $sock->accept; if ($cli) { say "$$ accepted connection from " . $cli->peerport; print while <$cli>; exit 0; } else { say "$$ got nothing from accept"; } } } } __END__ 4367 got out of poll 4367 accepted connection from 58442 4365 got out of poll 4366 got out of poll 4366 got nothing from accept 4365 accepted connection from 58446
As you can see when there's an incoming connection, poll may return in several workers, but only one worker can accept the connection.