in reply to Re: A suicidal parent OR death of a forking server
in thread A suicidal parent OR death of a forking server
Instead of implementing a limited cooperative multitasking system using select, it's simpler to use threads or Coro.
The following is the Coro equivalent of the code in the parent post.
#!/usr/bin/perl use strict; use warnings; use Coro qw( async ); use IO::Socket::INET qw( ); sub client { my ($sock) = @_; my $host = $client->peerhost; print "[Accepted connection from $host]\n"; while (!eof($sock)) { my $msg = <$sock>; if (!defined($msg)) { print "[Error reading from host $host]\n"; return; } print "$host said '$msg'\n"; last if $msg eq 'quit'; } print "[Connection from $host terminated]\n"; } my $server = IO::Socket::INET->new( ... ) or die("Couldn't create server socket: $!\n"); async(\&client, $server->accept) while 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: A suicidal parent OR death of a forking server
by BrowserUk (Patriarch) on Jun 10, 2010 at 04:04 UTC | |
by ikegami (Patriarch) on Jun 10, 2010 at 04:17 UTC | |
by ikegami (Patriarch) on Jun 10, 2010 at 04:24 UTC |