Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
How do I use threads to listen for new connections whilst maintaining responsiveness to existing ones

You may not need threads to do that. Although perlipc and perlfunc don't mention it, you can run select on a generic socket, at least on Unix. In more detail:

You open perlipc, find the section labelled 'Internet TCP Clients and Servers', and use the recipe to create a generic server socket: socket(), setsockopt(), bind(), listen(). You now build a bitmask and go into a select loop. (If you've not used select before, perlfunc explains how. select is a way of sleeping until there's some activity on one or more of any number of connections.) When select says there's something ready for your generic socket to read, it means there's an incoming connection attempt: so you accept the connection, flip a bit in your bitmask to represent the new connection, and go back to the top of your select loop. You're now in an interesting position: select will return when you're ready either to accept a new connection or to read data from an existing connection. So, if you can service an incoming packet quickly enough, a single fibre is all you need.

That said, I'd be fascinated to know how to share globs between Perl threads. I threw away a day's work earlier this week because Perl told me it couldn't be done and (as this was work time) I decided not to spend time trying to hack it. At the very least, this restriction should be documented in perlthrtut and/or threads::shared.


In reply to Re^2: Chat server impossible with Perl? by MarkusLaker
in thread Chat server impossible with Perl? by bronto

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?

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2024-05-23 00:45 GMT
Find Nodes?
    Voting Booth?

    No recent polls found