For the next installation of 'difficult and painful network programming', I would like to do a non blocking socket
open. My searches turned up any number of nodes on non-blocking reads and non-blocking socket accepts, but everyone seems to assume that if you're the one opening a socket, you're a client that can't do anythng until the server tells you to.
Forking isn't really an option, because some of the computers I"m connecting to will boot me after relatively short timeouts.
Essentially I want some code like this:
my @sockets;
foreach ( @hosts ) {
push @sockets, IO::Socket->new(blah blah blah);
}
while ( 1 ) {
foreach ( @sockets ) {
if ( $_->exists && $_->is_open) {
do_stuff($_);
}
}
}
Does anyone know of a solution?
____________________
Jeremy
I didn't believe in evil until I dated it.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.