I spent a lot of time dealing with pretty much the same problem when trying to write a module that would be able to handle multiple irc connections simultaneously. A number of suggestions were made on how to do this here. I personally found the threading method easier to work with and "cleaner" from a coding point of view than using a select loop. Even though ithreads have a number of flaws, one of them being the amount of memory they guzzle up, it still gets the job done quite well. Threads take a while to get used to, but when used properly allow for a style of coding you never might have thought possible.

Edit: a little more info.

Perhaps it would be wise to actually elaborate on WHY I prefer threading over a select loop....silly me

With a select loop, from my experience, you have to carefully decide just how often you do the check. The last parameter for select() is a timeout, and if you don't set it to a value you'll be back at square 1, since then select itself will block when no data is available. However, if you're going to check for data every millisecond you'll be spending lots and lots of cpu time, which is something I try to avoid like the plague. Another downside i ran across(there might be solutions to this, in which case I just didn't happen to find one) was that in order to effectively use the select loop, I had to read from the socket 1 byte at a time, glue these bytes to a string until I ran across a "\n", after which I sent the whole line out for processing. Using threading, you can simply have the thread do it's own little thing, reading in data using <> or readline(), and if for some reason the socket dies, be it by accident or intentionally, you can take appropriate action within the actual thread without disturbing the functionality of the main thread where the actual action happens. At some point during testing I had 10 irc connections up and running, all being fed regular data and CPU usage was, well, negligible. Memory use was a different story, but there are certain modules to bring this down a little on CPAN. Take a look at some of the modules starting with Thread:: if you feel you're willing to take a shot at it :)


In reply to Re^2: IO::Socket::INET -- Jettero verses non-blocking in windows by Forsaken
in thread IO::Socket::INET -- jettero verses non-blocking in windows by jettero

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.