Your skill will accomplish what the force of many cannot |
|
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
If you're willing to get down and dirty, you can use select()
like the rest of them. Earlier, reyjrar was asking about
doing the same sort of thing on a socket. The same principles
apply since file-handles and socket handles are really quite
the same. That post is here.
I've extracted the relevant bits of that code and posted it here as an example on how to check up on a filehandle without blocking: Explanation: POSIX calls such as select() use a slightly different view of the world when compared with Perl. Most of the time Perl will convert for you automatically, but there are a few cases where you have to help out. select() polls a number of file-handles (or sockets) and can report if they are ready to read, write, or if they have experienced an error. The documentation on select() is a little thin, and it will take a bit of experimentation to get a good handle on it. Note that select() can be configured to block or to be non-blocking, the trick is in the "$timeout" parameter. A zero timeout will put it into non-blocking mode. In order to tell select which filehandles you want to monitor, vec() is used to create a bit-mask with bit number zero representing filehandle 0, bit 1 for filehandle 1, etc. These filehandles are a bit different from Perl filehandles, so a quick conversion with fileno() will get things on track. This code uses "scalar"-style filehandles here because they are easier to pass between functions, and they work the same in most circumstances. In reply to Re: Non blocking read on a filehandle
by tadman
|
|