I'm trying to write a package that does a non-blocking multi-homed connect using IO::Socket::INET. As I understand it, IO::Socket::INET cannot connect to a multi-homed host when set to non-blocking mode:

Although it is not illegal, the use of "MultiHomed" on a socket which is in non-blocking mode is of little use. This is because the first connect will never fail with a timeout as the connect call will not block.

The package holds a copy of the socket and a list of the multi-homed IP addresses. If the connection attempt timesout or is refused, I try the next IP in the list.

The problem I'm having is that I can't reuse the socket I created after the first connect call. When I create a new IO::Socket::INET object within the package, I get the error "can't call method "foo" on an unblessed reference".

Is there a way to reuse the IO::Socket::INET object?

Can I associate a new IO::Socket::INET object to the class until all the IP addresses are exausted, or the connection attempt succeeds. How can I do this without unblessing?


In reply to Multihoming a non-blocking IO::Socket::INET by vancetech

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.