I'm still struggling with the idea of sockets, so here's a question with a practical side and a theoretical side.

The practical side: I have a load of sockets from which I am reading. They are IO::Socket objects attached to an IO::Select. I want to loop through them using while (@handles =IO::Select->select ($sel, undef, $self, 1) ) and read a line at a time. The idea is, it is faster to do this than to read each one in turn: I am trying to parallelize my socket reading.

So far, so good... but I have a problem. Normally, with just one socket, I can read the socket "to the end" by using <> in array context. With my new solution, I don't want to read the socket to the end - I just want one line at a time. But I do want to find out when data has finished coming over a socket. Otherwise, I end up going round and round the select() call.

That's the practical question: how do I find out when a data has finished coming over a socket, the same way perl does when I use the angle operator in array context, so as to remove the socket from my IO::Select?

The theoretical question is: what's the underlying mechanism? I know an HTML page is finished cos it says </HTML>. But how does one know a socket is finished? Does it communicate this fact at all? Or are you just supposed to guess because it has stopped talking to you?

Awaiting enlightenment.

dave hj~


In reply to Knowing an IO::Socket handle has reached end-of-file by dash2

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.