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;
In reply to Re^2: A suicidal parent OR death of a forking server
by ikegami
in thread A suicidal parent OR death of a forking server
by MonkeyMonk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |