You probably need to use IO::Select, and the alarm too. Take a look in this example for select, to see how to use it. This example show how to read in the same time 2 sockets, without stop another:
#!/usr/bin/perl ## Open the 2 socket connections: my $sock1 = new IO::Socket::INET( PeerAddr => host1 , PeerPort => 6622 , Proto => 'tcp', Timeout => 30) ; my $sock2 = new IO::Socket::INET( PeerAddr => host2 , PeerPort => 6622 , Proto => 'tcp', Timeout => 30) ; ## Crete the interface for select, with the 2 sockets: my $can_read = IO::Select->new( $sock1 , $sock2 ); ## File to log the data: open (LOG,"./log.txt") ; ## Here the select interface will return to the array ## @has_buf the $sockets with data in the buffer, using ## 1s of delay: while( my @has_buf = $can_read->can_read(1) ) { foreach my $has_buf_i ( @has_buf ) { ## $has_buf_i is one of the + sockets my $buffer ; ## Create another select to can read byte by byte, because ## we just know that the socket have data, but not the length: my $sel = IO::Select->new($has_buf_i) ; ## Read byte by byte: while( $sel->can_read(0.1) ) { sysread($has_buf_i, $buffer , 1 , length($buffer) ) ; } ## Print to the log file: if ($buffer ne '') { print LOG $buffer ;} } } exit;
"The creativity is the expression of the liberty".

In reply to Re: Timeouts when reading from socket Filehandles? by gmpassos
in thread Timeouts when reading from socket Filehandles? by Anonymous Monk

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.