in reply to Socket descriptor passed across fork -- hanging

I'm wondering if there's magic I have to do to avoid conflicts between the parent and the child on that socket. Should I undef it on the parent after forking the child? I'm pretty sure closing it is wrong (tried it).

See my code.

After the fork(), the parent closes the active socket because the parent does not talk to anybody - it only listens for new connections.

After the fork(), the child closes the passive socket because the child doesn't listen for new connections - it only talks on the active socket to the current client.

  • Comment on Re: Socket descriptor passed across fork -- hanging

Replies are listed 'Best First'.
Re^2: Socket descriptor passed across fork -- hanging
by dd-b (Pilgrim) on Oct 13, 2011 at 15:23 UTC

    I was using $socket->close(), rather than your close $socket. They should be equivalent, I thought, but I also thought I had trouble (closed on both sides) when I did the OO version. I've put in your version, and it hasn't broken anything (and will presumably be more stable in heavy use and under adverse conditions).

      close $socket provides exactly the same functionality albeit faster than $socket->close() because a Perl object method call has more run-time overhead than a subroutine call.</c>