Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^5: A non-blocking server using 'select' calls

by tachyon (Chancellor)
on Nov 11, 2004 at 11:47 UTC ( #406999=note: print w/replies, xml ) Need Help??


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

It's not. Add $|++; to the top of your script. I have tested that server on Win2K, WinXp, RH7, Fedora2 and it works as advertised. On Linux you need the $|++ as print passes through STDIO and gets buffered. It will work if you replace the print with syswrite( STDOUT, $_, 1 ) as well.

cheers

tachyon

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://406999]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2018-10-15 16:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When I need money for a bigger acquisition, I usually ...














    Results (82 votes). Check out past polls.

    Notices?