Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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) ----------------------------------------
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: HTTP::Daemon not working in threads?
by pg (Canon) on Nov 25, 2002 at 02:27 UTC | |
by Anonymous Monk on Nov 25, 2002 at 14:52 UTC | |
|
Re: HTTP::Daemon not working in threads?
by dingus (Friar) on Nov 25, 2002 at 17:45 UTC | |
by rcaputo (Chaplain) on Nov 27, 2002 at 19:13 UTC |