in reply to Re^3: Handling sockets in a server
in thread Handling sockets in a server

Thanks for the information. This was helpful. Can you tell me though what is the difference in return for closing the socket as apposed to the socket connection? What value am I getting out of closing each?

close($new_sock); # Closes connection, I think your statement on return values applies to this close

But what about

close($sock); # What value am I getting out of checking the close of this, the actual socket, not a connection?

Still waiting for 3 and 4 :)

Shannon Kerr

Replies are listed 'Best First'.
Re^5: Handling sockets in a server
by BrowserUk (Patriarch) on Oct 21, 2005 at 19:14 UTC

    I would think that either error return was equally valid from either.

  • In the case of EBADF, you probably don't care--you wanted it closed and it is--but it could be a useful indication of something wrong, a timing or logic error with your application. A warning to stderr or logfile might prove useful.
  • In the case of EINTR, it would mean that the process of clean up was interupted by an external signal, and therefore incomplete. The proper response would be to issue the close again, I think.

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re^5: Handling sockets in a server
by skerr1 (Sexton) on Oct 23, 2005 at 03:07 UTC

    Hopefully someone can answer questions 3 and 4. Here they are again. I didn't copy my example code but it is in the orginial post. Thanks

    3. If the child process is executing a command like system("echo Hello");, I need to reap child processes before closing the forked child process so as not to leave "zombies" right? Or is my handling that via capturing the CHLD signal ($SIG{'CHLD'} = 'IGNORE';) before I even start up the socket sufficient? I wasn't sure I needed to do one of these:

    while ( my $child_process = waitpid(-1,WNOHANG) > 0 ) { }

    before I close the child each time.

    4. In Perl 5.6.1, after each accepted connection do I need to reset STDERR and STDOUT that I set prior creating the socket? Previously in Perl 5.005_02 I was having to reset these with each new connection. If that's the same, can someone tell me why?

    Shannon Kerr

      Is there anyone that can help out with questions 3 and 4 in the original post of this thread 501889. Thanks!

      Shannon Kerr

        For 3, the answer is my handling via $SIG{'CHLD'} is sufficient, if done properly. I wanted the parent process to check the return value of each child process, and wanted the child processes of the parent to just reap their child processes, so the function called when receiving the child signal had to handle the reaping differently for the parent than the children.

        For 4, yes, you have to reset the STDERR and STDOUT if you want them redirected in the child processes.

        Shannon Kerr