Good answers on the question you asked. Some comments around the issue though:

1) Why download a file over multiple file handles?

If the answer is 'performance' be very sure to test to see if it is faster in the environment you expect it to be used, because it shouldn't be.
For a large transfer (and why else do a multiple fetch?) TCP should auto-adjust to get the best from the link between the client and server with only one connection.

If the answer is 'to avoid refetching the entire file if one transfer stalls/fails' then I don't think you need to do this - there is support in HTTP for requesting parts of files so you can resume a transfer if it fails.

2) Reading from multiple file descriptors. (I'm not 100% sure about this, but think this is right).

If you read from a file descriptor with <$fh>, perl does a 'blocking read'. This means the process will sleep until data arrives on that connection. In particular you won't get woken up if data arrives on one of your other file descriptors. For this kind of think you want a 'select' statement, to tell the O/S that you want to do some work when data arrives on any one of the specified file descriptors.

When the select returns and tells you there is data waiting, you then need to read from the file handle. Again, if you use <$fh> to read, you need to be careful to check what '$/' is set to, because the read will block until this character sequence is seen.

In summary, a multiple-socket client is a little more tricky than just having more file handles open and also I don't see why you'd need one - but hey - you probably have your reasons.


In reply to RE: I need an array of filehandles. by jbert
in thread I need an array of filehandles. by Punto

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.