Socket select in Perl
Jayce^
jason at infogenix.com
Fri Feb 18 09:24:16 MST 2005
On Thursday 17 February 2005 05:15 pm, David Smith wrote:
> Okay, so I guess this would work. Can any Perl monks correct me here?
>
> my $socket = ....
> my $select = = IO::Select->new();
> $select->add( $socket );
> if( $select->can_read( 0.5 ) ) {
> $response = <$socket>;
> print $response . "\n";
> } else {
> print "No data on socket.\n";
> }
>
> Since can_read() returns an array, the if expression should return a count
> of the array elements. If the count is > 0, the if expression is evaluated
> as true, otherwise false. Is this right?
>
> --Dave
Seems ok. I'd probably stick with the code in the example anyways (perldoc
IO::Select) even though you don't necessarily need the full functionality.
But the basic premise is right. You might keep the 'can_read' inside a while
loop, as per the example, and then just grab the first element of the array
for processing (get rid of the extra if the example has).
--
Jayce^
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://plug.org/pipermail/plug/attachments/20050218/d69cead4/attachment.bin
More information about the PLUG
mailing list