Using select(2)

M

memyself_

Dear,

using the following:

 my($scount, $stime)=
 CORE::select( $read_bits,
                $write_bits,
                $err_bits, 1);

In my program, $scount is allways equal to -1,
and $read_bits, $write_bits, $err_bits, to 0.

Does anybody know in wich case it can happen?

thank's in advance
 
J

Joe Smith

memyself_ said:
my($scount, $stime)=
CORE::select( $read_bits,
$write_bits,
$err_bits, 1);

In my program, $scount is allways equal to -1,
and $read_bits, $write_bits, $err_bits, to 0.

You did not show us where you were setting $read_bits and such
to be nonzero. You have to set them before each time select()
is called.

$rb = one bit for each file handle you will be reading from
$wb = one bit for each file handle you will be writing to
$eb = $rb | $wb;
$ms = 1.0; # seconds for the timeout
($scount,$stime) = select( $read_bits=$rb, $write_bits=$wb,
$error_bits=$eb, $ms);
warn "Invalid arguments presented to select()" if $scount < 0;
if ($scount == 0) {
print "No file handles are ready for I/O\n";
} else {
print "Can do I/O: r=$read_bits w=$write_bits e=$error_bits\n";
}
print "$stime seconds left before timeout\n" if $stime;

Use 'perldoc -f select' for more info.
Use comp.lang.perl.misc (and not comp.lang.perl) next time.
-Joe
 
J

Jim Gibson

memyself_ <[email protected]> said:
Dear,

using the following:

 my($scount, $stime)=
 CORE::select( $read_bits,
                $write_bits,
                $err_bits, 1);

In my program, $scount is allways equal to -1,
and $read_bits, $write_bits, $err_bits, to 0.

Sorry, but I am not familiar with the CORE module, and it is not
mentioned in my Perl book nor found on CPAN. Assuming it is just the
Perl built-in select function that calls the normal Unix select system
call, then you need to set the appropriate bits of $read_bits,
$write_bits, and $err_bits in order for this call to do anything. If
these are all zero, select will return after waiting for the specified
amount of time (1 second in your example) and will never set any bits
in the argument variables.

See 'perldoc -f select' to see how to set and inspect the appropriate
bits to check a particular file handle.

FYI: this newsgroup is defunct; use comp.lang.perl.misc in the future.
 
M

memyself_

Jim said:
Sorry, but I am not familiar with the CORE module, and it is not
mentioned in my Perl book nor found on CPAN. Assuming it is just the
Perl built-in select function that calls the normal Unix select system
call, then you need to set the appropriate bits of $read_bits,
$write_bits, and $err_bits in order for this call to do anything. If
these are all zero, select will return after waiting for the specified
amount of time (1 second in your example) and will never set any bits
in the argument variables.

The CORE module is for the perl built-in functions,
to distinguish thelmseve from user functions.
I write it like that to have a high level select subroutine slighty
different from the IO::Select module.

I found the reason by myself today. select return -1 because none of the
bits string are set. I know where to find the bug now.

Thank's for your answers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top