Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
We don't bite newbies here... much
 
PerlMonks  

Re: fork and HTTP::Daemon freezes on windows (spawn)

by tye (Cardinal)
on Nov 17, 2010 at 16:50 UTC ( #872017=note: print w/ replies, xml ) Need Help??


in reply to fork and HTTP::Daemon freezes on windows

Looks like Win32 "get sock name" can't be done by one thread (by which I mean "Win32 thread" not iThread) while another thread is in the middle of "accept" (on a different socket). It doesn't look like it is Perl locks that are causing the deadlock based on Perl's "accept" and "get sock name" being in the middle of calling Win32's "accept" and "get sock name" (respectively).

So the problem should go away if you replace emulated fork() with spawning, taking care to inherit the parent's file handle in the child. And this method works on Win32 (Apache uses it).

But in trying to quickly throw together the pieces needed to do this in Perl, I have my doubts that Perl can currently support it well (at least in the case of sockets and even more so when trying to use something like HTTP::Daemon).

So, rather than inherit a socket created in the parent, you might just spawn and create separate sockets in each process using

my $d= HTTP::Daemon->new( ... ReuseAddr=>1, ... );

I'm not certain that such "separate but equal" sockets will work as desired, but it seems worth trying.

"Spawn" in Win32 Perl can be spelled something like

system( 1, $^X, $0, @ARGV );

but probably add something to let the child know it is a child. For example, set some %ENV variable or add some extra argument to the child's command line.

- tye        


Comment on Re: fork and HTTP::Daemon freezes on windows (spawn)
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://872017]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2014-04-21 04:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (490 votes), past polls