Bummer, cannot get your error to repeat either on Win2000 or WinXP. If I leave the line in and check the thread count in Windows Task Manager the count goes up with almost every call. With it removed, however, it works fine for me (I had to emulate your handling functions since you didn't post them):
#... 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;

I got:
... 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. ...
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?

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


In reply to Re: Closing Connections using HTTP::Daemon by InfiniteSilence
in thread Closing Connections using HTTP::Daemon by Dr. Mu

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.