Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: select appears to ignore pending data on socket.

by Somni (Friar)
on Nov 04, 2007 at 01:55 UTC ( [id://648829]=note: print w/replies, xml ) Need Help??


in reply to select appears to ignore pending data on socket.

You are mixing buffered operations (print, <$sock>, etc.) with select. This is a no-no. While it can sometimes work, it's probably not going to work well here.

You need to use sysread and syswrite (or send and recv, though the extra arguments are useless to you at this point). Autoflush is also not going to do any good, given it's for flushing buffers that you shouldn't be using.

If you were having a problem sysread/syswrite or send/recv then you should post the code that uses them, and ask questions about it.

  • Comment on Re: select appears to ignore pending data on socket.

Replies are listed 'Best First'.
Re^2: select appears to ignore pending data on socket.
by Zidane (Acolyte) on Nov 04, 2007 at 02:15 UTC

    my problem is, i am going to need to wait on multiple sockets, and receive variable length input. as far as i am aware, recv and sysread only accept a set length of input to pull off the buffer, is this not correct?

    the socket may (or may not) have several lines waiting to be read too, just for that extra added complication.

    whilst i could write a parser to parse a single recv read into multiple lines, i cant block on the socket, and as far as i am aware, using recv to read more data than is available on the buffer will cause it to block.

    is there something else that can be used instead of select? i started out using the event module, but slowly drifted over to select as it seemed much simpler.

      Please stop using recv. It works fine, but it has arguments you are almost certainly not using. Use sysread instead.

      sysread will return on short reads. Meaning you do have to pay attention to the return value; you are not guaranteed to get all that you asked for. As long as select says there's something to read, sysread will not block.

      You are also, therefore, not guaranteed to get a full line on each sysread, so you will have to do your own buffering. Event.pm and POE are designed to abstract away most of these details, as it's tedious and error-prone to implement them yourself.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-25 21:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found