Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^4: How to pass AnyEvent socket handle to pre-forked child process?

by michaelfung (Novice)
on Jan 25, 2013 at 07:56 UTC ( [id://1015283]=note: print w/replies, xml ) Need Help??


in reply to Re^3: How to pass AnyEvent socket handle to pre-forked child process?
in thread How to pass AnyEvent socket handle to pre-forked child process?

Thanks Pavel! Now I know that sockets can be shared between forked childen.

The following skeleton worked for me:

# parent domain ... my $server_socket = IO::Socket::INET->new( Listen => 5, ReuseAddr => 1, LocalAddr => 'a.b.c.d', LocalPort => nnnn, Blocking => 0 ) # fork n children ... # child domain: fh_nonblocking $server_socket, 1; my $w = AE::io $server_socket, 0, sub { while(accept my $client_socket, $server_socket) { # setup handlers for this new client: $handles->{$client_id} = new AnyEvent::Handle( fh => $client_socket, on_read => sub { ... }, on_error => sub { ... }, ); $handles->{$client_id}->push_write ("Child $child_no welcome client + $client_id \015\012"); ...
  • Comment on Re^4: How to pass AnyEvent socket handle to pre-forked child process?
  • Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-23 19:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found