in reply to Strange blocking issue with HTTP::Daemon
and guess what, it does work. (And on keep-alive connections the pid remains the same). Mh, although I get a lot of "Needs close: 0" messages from non-keep-alive clients. I think I need to think through fork()'ing again...#!/usr/bin/perl use HTTP::Daemon; use Data::Dumper; my $d = HTTP::Daemon->new( LocalAddr => 'localhost', LocalPort => 4242, ReuseAddr => 1 ) || die; my $cnt; # response loop while (my $c = $d->accept) { my $pid = fork(); # We are going to close the new connection on one of two condition +s # 1. The fork failed ($pid is undefined) # 2. We are the parent ($pid != 0) if(!defined $pid || $pid == 0 ) { $c->close; print "Needs close: $pid\n"; next; } # From this point on, we are the child. # $c->close; # Close the listening socket (always done in childre +n) # Handle requests as they come in while (my $request = $c->get_request) { print "Request:\n".Dumper($request); my $response = HTTP::Response->new( 200, 'OK'); $response->header('Content-Type' => 'text/html'), $response->content("$cnt Working! (pid $pid)"); $cnt++; # print "Response:\n".Dumper($response); $c->send_response($response); } $c->close; undef($c); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Strange blocking issue with HTTP::Daemon
by Anonymous Monk on Aug 11, 2010 at 12:48 UTC | |
by isync (Hermit) on Aug 11, 2010 at 13:12 UTC | |
by isync (Hermit) on Aug 11, 2010 at 15:23 UTC | |
by Anonymous Monk on Aug 11, 2010 at 15:47 UTC | |
by isync (Hermit) on Aug 12, 2010 at 10:07 UTC | |
|