in reply to Re^2: A non-blocking server using 'select' calls
in thread A non-blocking server using 'select' calls
Sorry that aint necessarily so. Here is some trivial code that does the teletype thing. The client(s) have no way to disconnect BTW, that is left as an exercise for the reader yada yade.
#!/usr/bin/perl $|++; use IO::Socket; use IO::Select; my $lsn = IO::Socket::INET->new( Listen => 10, LocalAddr => 'localhost', LocalPort => 9000 ); my $client = new IO::Select( $lsn ); while( my @ready = $client->can_read ) { for my $fh (@ready) { if($fh == $lsn) { warn "Accepted new socket\n"; my $new = $lsn->accept; $client->add($new); } else { # process socket sysread($fh, $_, 1 ); print; # NB syswrite(STDOUT,$_,1) will be unbuffered by +default } } }
Note that sysread bypasses STDIO and all buffering. Read will sort of buffer (newlines only in this one byte reading config). I never use recv so really have NFI what it does.
cheers
tachyon
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: A non-blocking server using 'select' calls
by nikos (Scribe) on Nov 11, 2004 at 11:34 UTC | |
by tachyon (Chancellor) on Nov 11, 2004 at 11:47 UTC | |
by nikos (Scribe) on Nov 11, 2004 at 11:53 UTC | |
by tachyon (Chancellor) on Nov 11, 2004 at 11:55 UTC | |
by nikos (Scribe) on Nov 11, 2004 at 12:05 UTC | |
|