Re: trouble with reading from pipes




Daniel Davidson said:
I now have a question about how to handle the partial line reads.  Right
now I am guessing that the best way to do this is to keep a copy of the
last buffer read laying around, and attach that to the next read in case
the data needed is split on last previous, first next boundary.  Then I
can just to a =~/\n(.*?)\n.*?$/ and the last full line will be in $1.
Is there another (better?) preferred way to do this.  Seems like sysseek
should be useful, but I cannot get it to work.

You cannot seek on pipes or sockets -- that's the nature of the beast.

Is there also a way to monitor if any new information has been passed to
a readable filehandle.

Yes, select() and poll() allow you to do this.  BUT BUT BUT, that's exactly
what the IO watch is doing for you!

The IO watch callback will be invoked every time an event happens on the file
descriptor (note, not the file handle, but the fileno associated with it). 
You should slurp out all the available input, process what you can, store the
rest for next time, and then return.

If you are feeling the need to select() or poll() or block in your IO watch
handler, then your code is architected incorrectly and will perform very
badly.


-- 
muppet <scott at asofyet dot org>




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]