in reply to Fork is changing up my IO::Select behaviour
Don't use readline (<>) on filehandles you pass to select.
It can block (which defies the purpose of using select), and it can hide waiting data from select (meaning select won't wake up even though data is waiting to be read).
should beforeach $handle1 (@read_from) { $buf = <$new_sock>; if($buf){ print $buf; } }
orforeach my $handle1 (@read_from) { my $buf = ''; my $rv = sysread($handle1, $buf, 64*1024, length($buf)); # Handle error if !defined($rv) # Handle eof if !$rv print $buf; # Whatever we got, including partial lines }
foreach my $handle1 (@read_from) { our $buf; local *buf = \( $buf{fileno($handle1)} ); # alias $buf = '' if !defined($buf); my $rv = sysread($handle1, $buf, 64*1024, length($buf)); # Handle error if !defined($rv) # Handle eof if !$rv while ($buf =~ s/^(.*\n)//) { print $1; # Full line at a time } }
Does that also fix the problem you are reporting?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Fork is changing up my IO::Select behaviour
by Workman (Novice) on Feb 24, 2010 at 00:09 UTC | |
by Workman (Novice) on Feb 24, 2010 at 05:16 UTC | |
by ikegami (Patriarch) on Feb 24, 2010 at 05:37 UTC |