Hmm, the buffering problems outlined in my
select tutorial (
here)
also apply to open2, and indeed any other type of file
that can block. If you're reading from multiple files,
you can use the Multiplex package presented there (and
you can use it to implement timeouts, too). Use
sysread
and
syswrite to write to the filehandles returned by
open2 (if you're only reading from one filehandle, you
don't really need the complexities of using select, and
$SIG{ALRM} will let you interrupt something that's blocking)
Setting the filehandle to nonblocking is probably not the
answer to this, but it may help with the buffering problem.
If you do set the nonblocking flag, use select to avoid
having to poll the filehandle.
Use sysread to read one byte at a time, or set the filehandle nonblocking
and read (say) 256 at a time, but use select to wait for
more to arrive.
Andrew.
(Hrm, I think untitled nodes should be given default names
so we can click on them in newest nodes)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.