Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

There are two ways of doing this:
- fork() after you accept(), which gets you one child per connection, or
- threads - create multiple worker threads and pass the file descriptor in.

Since a socket isn't really a shared resource, there are restrictions on how you can connect multiple ends to it. A socket is just a file descriptor, and a process can't get access to another processes's FDs (unless it has root privileges). When you fork, the child process already has the filehandle open, and can use it without any problems, but since you can't get any further access to the parent, where the accept()s are going on, you have to die once you're finished with the current client.

Threads however, all live in the same PID, they just each have their own copy of the perl runtime. They can get at the parent's FDs by passing the file descriptor number around, which you get by running fileno($socket).

I posted a thread a couple of months ago here, which ended up with some really helpful example code from BrowserUk: Resource pools and concurrency

In reply to Re: IO::Socket::INET file handler by mattk
in thread IO::Socket::INET file handler by Razvanica

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-03-28 15:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found