IO:Select - what did I do wrong?

E

Ed W

Can't see what's wrong with this code... It's running under windows XP with
activestate perl 5.6.1 (which may well be part of the issue...).

The following code gives me an error:
Error in select: Bad file descriptor at io_select_test.pl line 11.

....However, it is pretty much straight out of the man pages.

The problem I am trying to solve is how to read from a bunch of sockets with
a blocking select, but also read from Stdin. I guess I could make my select
only block for 1/2 sec or so and then poll stdin, but there must be
something better than this? (in fact I seem to have some probs doing
non-blocking input from stdin under win32... Is this normal, does it work
for other people...)

#!perl -w
use strict;
use warnings;
use IO::Socket;
use IO::Select;

my $r = IO::Select->new(\*STDIN);

$|=1;

my ($rr) = IO::Select->select( $r )
or die "Error in select: $!";

print "Success";
 
G

Greg Bacon

: Can't see what's wrong with this code... It's running under windows XP with
: activestate perl 5.6.1 (which may well be part of the issue...).
:
: The following code gives me an error:
:
: [my $r = IO::Select->new(\*STDIN);]
:
: Error in select: Bad file descriptor at io_select_test.pl line 11.

According to the perlport manpage:

select RBITS,WBITS,EBITS,TIMEOUT

Only implemented on sockets. (Win32, VMS)

Hope this helps,
Greg
 
E

Edward Wildgoose

Greg Bacon said:
: Can't see what's wrong with this code... It's running under windows XP with
: activestate perl 5.6.1 (which may well be part of the issue...).
:
: The following code gives me an error:
:
: [my $r = IO::Select->new(\*STDIN);]
:
: Error in select: Bad file descriptor at io_select_test.pl line 11.

According to the perlport manpage:

select RBITS,WBITS,EBITS,TIMEOUT

Only implemented on sockets. (Win32, VMS)

Hope this helps,

Ahh nuts. Thanks. I hadn't thought to look in the perlport manpage.

Any suggestions for the best way to do this? I thought either:

a) writing a socket interface into my code
b) converting to "wheel" type code, or perhaps wxwindows (since my GUI app
will be in this)
c) run a blocking select with timeout and check stdin occasionally

Anything else I should look at...?

Ta

Ed W
 
G

Greg Bacon

: [...]
:
: Anything else I should look at...?

Install an operating system? :) :) :)

Greg
 
E

Ed W

: Anything else I should look at...?
Install an operating system? :) :) :)

Yeah, fair enough....

....It's going to be used by other people though, and the spec indicates MS
windows....

....oh well

Thanks

Ed W
 
G

Greg Bacon

: > Install an operating system? :) :) :)
:
: Yeah, fair enough....
:
: ...It's going to be used by other people though, and the spec indicates MS
: windows....
:
: ...oh well

Have you considered feeding STDIN to a socket and adding the target
socket to your fd_set? Lucky for you that recent versions of perl on
Win32 have fork emulation.

Greg
 

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

Forum statistics

Threads
474,138
Messages
2,570,804
Members
47,349
Latest member
jojonoy597

Latest Threads

Top