Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

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?

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2016-05-30 09:40 GMT
Find Nodes?
    Voting Booth?