in reply to Re^5: Does IO::Select work? Anywhere?
in thread Does IO::Select work? Anywhere?
To get away from your obsession on readline,
Observation is not obsession.
I can kill the client's xterm, before I send any newline, and the server stays responsive to new and other connections.
Sure you can if you fork, but that's a different solution. Ie. a forking server not a multiplexing server.
Here is a perfectly serviceable equivalent using threads:
#! perl -sw use strict; use threads stack_size => 4096; use threads::shared; use IO::Socket; use constant CRLF => chr( 13 ) . chr( 10 ); $/ = $\ = CRLF; my $server = IO::Socket::INET->new( LocalHost => 'localhost', LocalPort => 1025, Listen => SOMAXCONN, Reuse => 1, ) or die "Couldn't create listening socket"; while( 1 ) { my $client = $server->accept; async { my $peerhost = $client->peerhost .':'. $client->peerport; while( <$client> ){ chomp; print $client $_; print "$peerhost:$_"; } }->detach; } close $server;
That will (has) run all day and night without problems.
And here is a 'one-liner' that will launch 1000 clients at it each time:
perl -Mthreads=stack_size,4096 -MIO::Socket -E" async{ my$s=new IO::Socket::INET('localhost:1025') or warn $^E, return; say $s 'Hello'; print scalar <$s>; shutdown $s, 2; close $s; }->detach for 1 .. 1e6"
But as with all forking servers, it is ridiculously resource intensive for an echo daemon.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: Does IO::Select work? Anywhere?
by zentara (Cardinal) on Oct 23, 2012 at 10:01 UTC | |
by BrowserUk (Patriarch) on Oct 23, 2012 at 10:47 UTC | |
by zentara (Cardinal) on Oct 23, 2012 at 14:23 UTC | |
by BrowserUk (Patriarch) on Oct 23, 2012 at 20:50 UTC | |
by zentara (Cardinal) on Oct 24, 2012 at 11:15 UTC |