http://qs1969.pair.com?node_id=245526


in reply to •Re: A non-forking server model with issues closing sockets on users
in thread A non-forking server model with issues closing sockets on users

$! is set to 'Bad file descriptor'.
This only further confuses me, I sure hope it tells you something...
The loop is correct, what is returned should absolutely be a handle to a socket.

Update
I just added a 'print $_ "Something\n";' inside the first state checking loop, I don't know why I never thought of checking it before. I get this:
Can't use string ("IO::Socket::INET=GLOB(0x83a8528)") as a symbol ref while "strict refs"
Significant... But I'm unsure why its a string

JP,
-- Alexander Widdlemouse undid his bellybutton and his bum dropped off --

  • Comment on Re: •Re: A non-forking server model with issues closing sockets on users

Replies are listed 'Best First'.
•Re: Re: •Re: A non-forking server model with issues closing sockets on users
by merlyn (Sage) on Mar 24, 2003 at 20:47 UTC
    I see that you're putting handles as keys in hashes. That won't work. Keys are always stringified, destroying the power of the handle object as an object. You'll need to do some redesign.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      Ah.

      Well. That'd be that then. Many thanks, I've been banging my head against a wall on this one... Sure enough, store the socket in the hash, and then do a close() on that stored socket handle - Everything is happy.

      JP,
      -- Alexander Widdlemouse undid his bellybutton and his bum dropped off --

Re: Re: •Re: A non-forking server model with issues closing sockets on users
by pg (Canon) on Mar 24, 2003 at 20:32 UTC
    Most likely it has been closed by the peer already. (From a pure logic point of view, it is also possible that your file descriptor is a bad one anyway, due to other programming errors)

    Following piece of code demos this situation:
    use strict; use IO::Socket; use threads; $| = 1; threads->create(\&server); my $socket = IO::Socket::INET->new(Proto => "tcp", PeerAddr => "localh +ost", PeerPort => 7001) || print "Socket creation error: $!\n"; sleep(5); print "about to close socket on client side\n"; close($socket); print "closed socket on client side\n"; print $!; sub server { my $server = new IO::Socket::INET(Proto => "tcp", LocalPort => 700 +1, Listen => 5) || die "failed to establish socket\n"; my $client = $server->accept; sleep(1); print "about to close socket on server side\n"; close($client); print "closed socket on server side\n"; }