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

It is a STDIO buffering thing. s/print;/syswrite(STDOUT,$_,1)/ and bypass it completely.

Replies are listed 'Best First'.
Re^8: A non-blocking server using 'select' calls
by nikos (Scribe) on Nov 11, 2004 at 12:05 UTC
    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

        Yup! You are correct. If I use a telnet client on Windows to connect to the server, I don't have any problems. Even my version works fine. Thank you very much for pointing it out. I'll still experiment with it and see what I get.