in reply to Re^5: A non-blocking server using 'select' calls
in thread A non-blocking server using 'select' calls

I know it sounds weird. I've tried changing $|. Nothing happens. It still waits for a newline.
-bash-2.05b$ uname -a FreeBSD gateway.intra 5.2-CURRENT FreeBSD 5.2-CURRENT #1: Tue Aug 3 1 +4:26:12 MSD 2004 root@gateway.intra:/usr/obj/usr/src/sys/My i386 -bash-2.05b$ perl -v This is perl, v5.6.1 built for i386-freebsd

Replies are listed 'Best First'.
Re^7: A non-blocking server using 'select' calls
by tachyon (Chancellor) on Nov 11, 2004 at 11:55 UTC
    It is a STDIO buffering thing. s/print;/syswrite(STDOUT,$_,1)/ and bypass it completely.
      I've changed 'print'. The problem is not with print or sysread/syswrite. The problem is with a 'select' call.

      ... while( my @ready = $client->can_read ) { warn "Inside"; for my $fh (@ready) { ...
      Output:
      -bash-2.05b$ ./teletype.pl Inside at ./teletype.pl line 13. Accepted new socket Inside at ./teletype.pl line 13. aInside at ./teletype.pl line 13. aInside at ./teletype.pl line 13. aInside at ./teletype.pl line 13. Inside at ./teletype.pl line 13. ^C -bash-2.05b$
      It looks correct but I get
      Inside at ./teletype.pl line 13. aInside at ./teletype.pl line 13. aInside at ./teletype.pl line 13. aInside at ./teletype.pl line 13. Inside at ./teletype.pl line 13.
      only after a press 'enter' in telnet.
      I'll have a look in IO::Select. It waits for a newline when can_read is executed. The input must be still buffered.

      Cheers

        Perhaps it is your shell. With a telnet client on windows to a remote Linux server this is a teletype when watched via putty. Maybe it is a BSD issue?

        [root@devel3 james.freeman]# cat test.pl #!/usr/bin/perl use IO::Socket; use IO::Select; my $lsn = IO::Socket::INET->new( Listen => 10, LocalAddr => '64.246.xx.xx', 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 { syswrite(STDOUT,$_,1) if sysread($fh,$_,1 ); } } }

        cheers

        tachyon