Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

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 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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://20561]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2018-05-20 14:54 GMT
Find Nodes?
    Voting Booth?