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

Dear Monks, and my application (or at least I think it is). I have a module that instantiates an HTTP::Daemon and (I'm not yet sure if it's relevant) an IO::Select to tell me when a request is available.
my $d = HTTP::Daemon->new( 'LocalPort' => $port, 'ReuseAddr' => 1 ); print STDERR "DataServer::new: <URL:", $d->url, ">\n"; my $sel = new IO::Select($d);
Then after receiving the request, I call send_response to handle the HTTP request. Everything works fine.. EXCEPT if before I call send_response either the request (times out) or I kill the Http client (currently either wget or another HTTP::Daemon), my entire application dies. I've tried everything to save it. It literally just wants to die. The specific line it dies on lives in HTTP::Daemon in 'send_basic_header' when it tries to write to the socket handle:
print $self "Date: ", time2str(time), $CRLF;
if anyone has any thoughts or interesting ideas, I'm open to all suggestions.. thanks, Michael

Replies are listed 'Best First'.
Re: HTTP::Daemon is killing me
by misc (Friar) on Aug 29, 2007 at 17:47 UTC
    Try caching the sigpipe signal.
    I'm not sure if that's your problem, but it's worth a try.
    Just redefine the signal handler:
    SIG{PIPE} = sub { print "Lost Connection.\n"; };

    hth, michael
      Nice!!! This works beautifully (or at least it doesn't kill my app). Thank you so much, misc.
        It's also the normal way to handle broken pipes/sockets.
        I'm just wondering why there's so few information in the perl documentation..
        (perlvar and perlipc)