Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: blocking, non-blocking, and semi-blocking

by etcshadow (Priest)
on Aug 29, 2004 at 05:37 UTC ( #386699=note: print w/replies, xml ) Need Help??


in reply to blocking, non-blocking, and semi-blocking

You're misunderstanding what can_read (or the analogous call to select) means. They don't exactly mean "which handles have waiting data"... they mean "for which handles will a read return imediately". So, for a file, a read will always return imediately, so a file will always return from can_read. Even if you have read to the end of the file, reading from it again will just return you no data, but it will do so without blocking.

Select is more about direct inter-process communication (like sockets and pipes), not inderect interprocess communication (by writing and reading from files).

I know you don't want to use it, but what you really seem to be talking about is the same sort of thing that File::FindTail does, which is to poll a file for changes in length every so often. To work that into what you're doing, just do your IO::Select call with a brief timeout (like 1 second or so), and check to see if the file has changed it's length in the interim. If so, seek to it's previous length, and read from there.

Update: added to the last paragraph a little so that it doesn't just say what is wrong but also says what you should do.

------------ :Wq Not an editor command: Wq

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2019-10-21 00:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?