i'm currently working on a daemonized process that collects UDP packets and processes them for database insertion. i'm running into an issue with blocking IO.

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:

if ($nfound = select($rout = $rin, undef, undef, $time_left)) { for (1 .. $nfound) { $sock->recv($msg, $MAX_SIZE) or warn "Socket error!: $@\n"; }
so that once all the messages have been collected from the buffer, the program can move on and do other things.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.