Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: When do I stop reading?

by ahunter (Monk)
on Jun 30, 2000 at 12:16 UTC ( #20561=note: print w/ replies, xml ) Need Help??


in reply to When do I stop reading?

This sounds like a buffering problem - close the socket on the client when you've finished sending data, or use sysread() and syswrite() (and no other IO calls) to access the socket data. I wrote a longer article on this at Socket.pm nonblocking.

Update: This happens because all of perl's standard file operators - including things like eof() - are buffered, and read ahead when called. This usually isn't a problem, but with a filehandle that may block (eg a socket or a pipe), perl may block while reading ahead, so you don't see the data until it finishes. Sometimes you write some data to a socket and close it straight away - you won't see the problem here, as perl will stop reading when it gets the EOF. However, if you are trying to do something interactively, where the client socket stays open, you may find perl blocks before you get all the data that is available. sysread() and syswrite() bypass all this, so you can read right up to the last byte using them :-) Remember to check the return values for errors and EOF.


Comment on Re: When do I stop reading?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2014-09-20 12:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (159 votes), past polls