Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://386712]
and monks are getting baked in the sun...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2018-02-21 06:14 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (275 votes). Check out past polls.