Hi wizards,

I am trying to change a single process proxy style Perl program to handle multiple connections. On Windows 2000 and AS 5.6.1 fork() never worked for me when trying to do HTTP/LWP/Daemon code, so I just installed AS 5.8.0 and trying to multi-thread. I am using HTTP::Daemon to accept the connections. Problem: The get_request method is stuck in the thread. Do I need to fix my program or is this a bug? Do you know of example of similar program?

I am on Windows 2000 server and just installed AS 5.8.0 beta using MSI (Windows installer).

The bad behavior is that the first two connects are stalled in the thread at the get_request, the third connect will activate the first two connects and is stalled itself.

To use the program just change the browser setting to proxy on 127.0.0.1 port 3126 and try locations www.google.com, then www.yahoo.com, then www.msn.com

This is just a small code to get past the get_request :(

============================ use 5.008; # 5.8 required for stable threading use strict; use warnings; use threads; # threading routines use threads::shared; # and variable sharing routines use HTTP::Daemon; my $daemon = HTTP::Daemon->new( LocalPort => 3126, Listen => 5, Reuse => 1 ); die "Cannot listen\n" unless defined $daemon; $daemon->autoflush(1); my $client; while( 1 ) { $client = $daemon->accept; print STDERR "got connect\n"; threads->create("start_thread", $client ); # threads->new(\&start_thread, $client ); } $daemon->shutdown(2); exit; sub start_thread { threads->self->detach(); print STDERR "Thread started\n"; print STDERR $_[0] . "\n"; my $client= $_[0]; my $request = $client->get_request; print STDERR "====Got request=Start=====\n"; print STDERR $request->as_string; return; } ========================= output: ----------------------- got connect Thread started HTTP::Daemon::ClientConn=GLOB(0x1f2d640) got connect Thread started HTTP::Daemon::ClientConn=GLOB(0x20e8e08) got connect ====Got request=Start===== GET http://www.google.com/ HTTP/1.0 Accept: image/gif, image/jpeg, */* Accept-Language: en Host: www.google.com User-Agent: Mozilla/4.7 (compatible; OffByOne; Windows 2000) Webster Pro V3.2 ====Got request=Start===== GET http://www.yahoo.com/ HTTP/1.0 Accept: image/gif, image/jpeg, */* Accept-Language: en Host: www.yahoo.com User-Agent: Mozilla/4.7 (compatible; OffByOne; Windows 2000) Webster Pro V3.2 Thread started HTTP::Daemon::ClientConn=GLOB(0x33135d8) ----------------------------------------

In reply to HTTP::Daemon not working in threads? by Anonymous Monk

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.