in reply to Closing Connections using HTTP::Daemon
#... if ($req_method eq 'POST') { DoPost($connex, $peeraddr, $req_content, $req_uri) } elsif ($req_method eq 'GET') { DoGet($connex, $peeraddr, $req_uri) } else { SendNotFound($connex) } } print "Connection $connectno finished.\n"; #sleep 1 while ($connex->connected); $connex->close; print "Connection $connectno closed.\n\n"; } sub DoPost { #dummy Function my ($c,$p,$req,$req_uri) = @_; $c->send_file_response(qq|c:\\temp\\foo.dat|); } sub DoGet { #dummy function my ($c, $p, $uri) = @_; $c->send_file_response(qq|c:\\temp\\foo.dat|); } sub SendNotFound { #dummy function my ($c) = @_; $c->send_file_response(qq|c:\\temp\\foo.dat|); } &RunServer; 1;
With the correct output to the browser/LWP (command shell) each and every time. Perhaps something else in your functions is causing these threads to kill the parent process? Can you post some more of that?... Connection 69 at Fri Nov 11 16:10:53 2005 from 127.0.0.1 Connection: 69 Request: GET / Connection 69 finished. Connection 69 closed. Connection 70 at Fri Nov 11 16:10:53 2005 from 127.0.0.1 Connection: 70 Request: GET / Connection 70 finished. Connection 70 closed. ...
Update: I took a closer look at my Task Manager and noticed 100% utilization with your code in that IO::Select loop, so I rewrote it a bit (using the perldoc example from HTTP::Daemon):
#!/usr/bin/perl -w use strict; use threads; use HTTP::Daemon; $|++; my $coreDaemon = HTTP::Daemon->new(LocalPort=>90) or die $!; my $connectno = 0; print "Listening..."; while(my $c = $coreDaemon->accept){ while (my $r = $c->get_request) { if ($r->method eq 'GET') { my ($thrd) = threads->create(\&GetHandler,$c, ++$connectno); $thrd->detach; #$c->send_file_response("c://temp//foo.dat"); } else { #$c->send_error(RC_FORBIDDEN) $c->send_file_response("c://temp//failed.dat"); } } } #from the old code sub GetHandler { my ($connex, $connectno) = @_; my $peeraddr = $connex->peeraddr; prin2log( "Connection $connectno started."); $connex->send_file_response("c://temp//foo.dat"); prin2log( "Connection $connectno finished."); #sleep 1 while ($connex->connected); $connex->close; prin2log( "Connection $connectno closed.\n"); } #STDOUT messages will now go to this (non-filelocked) file sub prin2log { my ($str) = @_; open(H,qq|>>c:\\temp\\foo.log|) or die qq|Cannot write to log: $!| +; print H $str . qq|\n|; close(H); }
Celebrate Intellectual Diversity
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Closing Connections using HTTP::Daemon
by Dr. Mu (Hermit) on Nov 11, 2005 at 23:28 UTC | |
|
Re^2: Closing Connections using HTTP::Daemon
by Dr. Mu (Hermit) on Nov 11, 2005 at 23:41 UTC |