Hi all monks!
I am having trouble using sysread with a standard INET soocket created using IO::Socket::INET. I am trying to read data from a server that sends data in chunks about 1 minute apart then optionally after receiving a chunk of data I might want to send something back to the server. Hence I need to use a sysread with a timeout.
However, my problem is that though I can receive the first block of data, the second block of data which arrives after a minute results in sysread returning 0 which I believe indicates EOF (socket closed?). The results is the same if I use IO::Select or an alarm construct such as:
eval {
local $SIG{ALRM} = sub { die "alarm\n" };
alarm $rx_timeout;
$ncount = sysread($client, $data , 1);
alarm 0;
};
On reading the second block of data sysread will exit immediately and always return 0.
If I don't implement any mechanism to break out of the sysread (including using select statements) then sysread work fine and is able to read subsequent data blocks sent from the server but it does block while doing this which is not what I want.
Any ideas on how to make sysread work in this situation in a non-blocking manner?
Thanks!
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.