I've been using IO::Select and IO::Socket to create the needed sockets, and check if they're available for reading, but one of the collection sockets ( the UDP socket ) blocks if the UDP buffer has been emptied.
i've looked at the select function, and ( after the annoying vector packing, etc ) it can be used to return the number of packets in the message buffer, so something like this can be achieved:
so that once all the messages have been collected from the buffer, the program can move on and do other things.if ($nfound = select($rout = $rin, undef, undef, $time_left)) { for (1 .. $nfound) { $sock->recv($msg, $MAX_SIZE) or warn "Socket error!: $@\n"; }
my question: is there a similar method in IO::Select ( or IO::Socket )? i've read through the perldoc for both, and haven't seen one ( but i may be experiencing tunnel vision ).
the code i've been using ( that blocks ):
my $incoming = IO::Socket::INET->new( LocalPort => $MSGPORT, Proto => 'udp', Timeout => 1); ## some more code... while ( $incoming->recv( $msg, $MAX_SIZE ) ) { my ( $port, $addr ) = unpack_sockaddr_in( $incoming->peername +); push @messages, [ $addr, $msg ]; last if @messages > $MAX_INC_Q_SIZE; }
which works fine, until the message buffer only contains $MAX_INC_Q_SIZE - 1 messages. then, the socket sits and waits for that one last message before exiting the collect loop and processing.
In reply to IO::Select vs select function by geektron
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |