chanson has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks-

I am using a IO::Select object to manage multiple network connections. Currenty I am having trouble removing a socket from my select. If I run the following code:

#!/usr/bin/perl use IO::Select; use Data::Dumper; $sel = IO::Select->new(STDIN, STDOUT, STDERR); @hand = $sel->handles(); print Dumper \@hand; $sel->remove(STDIN); @hand = $sel->handles(); print Dumper \@hand;
I get the following expected output:
$VAR1 = [ 'STDIN', 'STDOUT', 'STDERR' ]; $VAR1 = [ 'STDOUT', 'STDERR' ];
In my system I have a little method called remove socket.
sub removeSocket { my ($self, $socket) = @_; my $select = $self->{'select'}; print STDERR 'dumping: ',Dumper $socket; my @handles = $select->handles(); print STDERR '>>before: ',Dumper \@handles; my $retVal = $select->remove($socket); print STDERR $retVal, $/; my @handles2 = $select->handles(); print STDERR '>>after: ',Dumper \@handles2; }
Which gives the following, and in my mind very confusing, output when run in the larger system:
dumping: $VAR1 = \bless( \*Symbol::GEN1, 'IO::Socket::INET' ); >>before: $VAR1 = [ bless( \*Symbol::GEN0, 'IO::Socket::INET' ), bless( \*Symbol::GEN1, 'IO::Socket::INET' ) ]; 0 >>after: $VAR1 = [ bless( \*Symbol::GEN0, 'IO::Socket::INET' ), bless( \*Symbol::GEN1, 'IO::Socket::INET' ) ];
Any thoughts? Thanks in advance. (btw although I have been a perl programmer for 5 years I have not done a lot of socket programming, and also have not spent any time on perlmonks)

Replies are listed 'Best First'.
Re: IO::Select behavior
by pg (Canon) on Mar 13, 2003 at 20:44 UTC
    I think it should be fine, and tested with the following code: (the way you pass parameter is wrong? pure guess, as I don't have that part of your code)
    #!/usr/bin/perl use IO::Socket::INET; use IO::Select; use threads; use Data::Dumper; threads->create(\&server); my $c1 = new IO::Socket::INET(Proto => "tcp", PeerAddr => "127.1", Pee +rPort => 3000); my $c2 = new IO::Socket::INET(Proto => "tcp", PeerAddr => "127.1", Pee +rPort => 3000); my $select = new IO::Select($c1, $c2); my @handles = $select->handles(); print Dumper \@handles; $select->remove($c1); my @handles2 = $select->handles(); print Dumper \@handles2; sub server { my $s = new IO::Socket::INET(Proto => "tcp", LocalAddr => "127.1", + LocalPort => 3000, Listen => 1); while (1) { $s->accept(); } }
    And I got:
    $VAR1 = [ bless( \*Symbol::GEN0, 'IO::Socket::INET' ), bless( \*Symbol::GEN1, 'IO::Socket::INET' ) ]; $VAR1 = [ bless( \*Symbol::GEN1, 'IO::Socket::INET' ) ];