My reading of your problem is that you need to use more than 64-110 sockets in a program.

The best solution is to use an event driven framework for your program. As suggested previously, the POE (poe.perl.org) framwork is great. I use it extensively. I use it regularly to connect and interact with hundreds of sockets simultaneously. Actually, I've done upwards of two thousand concurrent sockets, but that was just to connect and disconnect quickly across several thousand hosts.

My opinion on Perl Threads is that perl5-dev has not figured out how to do threads well yet and the code is shaky. Clearly, perl5-dev chose not to "share-all", and you can do "share-none" quite nicely with fork(). So they are playing games with "share-some" and "share-explicitly". Figuring out what memory to share seems to me very difficult in a generic case.

You need to know that a perl file handler is a perl memory thing that contains a file descriptor, aka $fh->fileno(). Even if you are using perl threads, you need to pass the file descriptor then on the receiving end wrap the file descriptor in a perl file handle ala IO::Handle->fdopen($fd) .

You might be able to pass the file descriptor from one thread to another with Thread::Queue cuz the file descriptor is just an integer and perl threads are really all in the same process.

However, if you use separate processes via fork() you need to pass the file descriptor over a Unix Domain socket. See Advanced Programming in the Unix Environment by W. Richard Stevens. The chapter is "Advanced Interprocess Communication" section "Passing File Descriptors".

However you are in luck. There is a CPAN module tested under Linux and Solaris for passing file descriptors called Socket::PassAccessRights.

But like I said, use POE. There might be a learning curve, but it is totally worth it, you will thank me. Barring that, stop using perl thread and use processes, then do this file descriptor passing thing.


Good Luck.


In reply to Re: How to pass sockets to different threads? by LunaticLeo
in thread How to pass sockets to different threads? by noslenj123

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.