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

Re: socket reading...

by bikeNomad (Priest)
on Jul 28, 2001 at 21:09 UTC ( [id://100571]=note: print w/replies, xml ) Need Help??


in reply to socket reading...

You could put your socket into non-blocking mode and actually look at the return value from sysread. If your responses over the socket are record-oriented and terminated by a particular character (like, say, "\n") you could set $/ to that character and use the <$sock> form. Otherwise, if you have a length indication at the beginning of each response, read that first and then read exactly the right number of bytes.

update: corrected part about blocking if you try to read too many bytes.

Replies are listed 'Best First'.
Re: Re: socket reading...
by kschwab (Vicar) on Jul 28, 2001 at 21:28 UTC
    I don't agree with this assumption:

    When select comes back to you it means that some data is available; it doesn't say how much. Then you try to read 1024 bytes. If there isn't that much data available, and you're in blocking mode, it'll try to wait.

    read() and/or sysread() will read whatever is there without waiting on the remainder of the 1024 bytes. They will block if there's no data to read, but select() says there is data.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-19 13:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found