Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

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

by matija (Priest)
on Aug 29, 2004 at 09:16 UTC ( #386712=note: print w/ replies, xml ) Need Help??


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

(I do know about File::Tail, in case anyone was going to suggest that, but I couldn't see how to implement it non-blocking and integrate that with the socket listener.)

Actually, File::Tail has a select for that very purpose. The way to use it is to pass all the socket filehandles to File::Tail's select exactly the way you'd pass them to the regular select.

Then you take all the File::Tail objects, and you put them behind all the other parameters in the select. Select will return when any of the filehandles are ready for reading, and File::Tail's select will do exactly the same, except it will also return if any of the File::Tail objects have stuff to read.

foreach (@ARGV) { push(@files,File::Tail->new(name=>"$_",debug=>$debug)); } while (1) { ($nfound,$timeleft,@pending)= File::Tail::select(undef,undef,undef,60,@files); foreach (@pending) { print $_->{"input"}." (".localtime(time).") ".$_->read; } }
So, to use File::Tail for this, just replace the undefs in the select call with the appropriate bit vectors for your socket filehandles.


Comment on Re: blocking, non-blocking, and semi-blocking
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2014-08-20 21:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (124 votes), past polls