in reply to Printing to all clients on a socket from a child process

After you fork, parent and child do not share memory in the sense that if the parent changes a variable the child will not see that change and vice-versa. So, even though $read_set will be the same right after the fork, when the parent accepts a new connection and changes $read_set accordingly, the child's value of that variable will not change. Copies of all data structures (including open file and socket connections) are made at the time of the fork, but then they become independent.

Given that the child won't be able to 'see' new client connections to the parent, I think the best option is to place the keep-alive function in the parent and dispense with the child process. Even if you could share sockets between the parent and child which is possible, but tricky), it complicates your protocol since you don't want writes from the parent and child to interfere with each other.

Replies are listed 'Best First'.
Re^2: Printing to all clients on a socket from a child process
by Fredde87 (Initiate) on Mar 11, 2008 at 16:56 UTC
    Have you got any suggestions on where I place my keep alive in the parent? I explored this route but always got stuck as the Keep Alive would never end.
      I would just do it in your I/O processing loop. At the end of the loop, just check if it is time to send the keep-alive message. You can keep track of things on a per-client basis, or just use the same timing for all clients.

      In your can_read call, you'll want to use a timeout value that's equal to your keep-alive period so that you won't miss sending out a keep-alive message on time.