Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^5: Sharing sockets between the main script and thread

by BrowserUk (Patriarch)
on Nov 30, 2008 at 15:39 UTC ( [id://726911]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Sharing sockets between the main script and thread
in thread Sharing sockets between the main script and thread

There actually is a bonus question .... If you run the server .... Everything will hang.

Maybe it's a platform difference, but I commented out the select at the top, and then the sleep at the bottom, and nothing changed. No hang. Everything just ran a little faster.

As for the code. You are using a shared hash, locking, and two queues to achieve what this code achieves with a single queue and no locking. And for no benefit that I can perceive.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on Re^5: Sharing sockets between the main script and thread

Replies are listed 'Best First'.
Re^6: Sharing sockets between the main script and thread
by markseger (Beadle) on Nov 30, 2008 at 16:01 UTC
    Clearly the code you posted is more economic and I suspect it will grow as more error handling is added. For example it looks like it opens a socket and keeps writing to it until the socket closes and that's not the behavior I'm looking for. Rather I want my worker thread to manage open/closing the socket while the mainline does the I/O to it. If multiple sockets are opened, the mainline will write the same strings to all of them, dealing with each connections independently closing/reconnecting. The main line should not care how many (if any) connections are active.

    That's probably not all that obvious from looking at the code itself.

    -mark

      All of which is completely irrelevant as I'm only referring to the mechanism of transferring handles from one thread to another. Still, I've noticed that there is a propensity for some people to prefer complicated to simple.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        re complexity - no disagreement and I'm always looking for easier ways to do things. I really like the mechanism for sharing file handles via the file number and it does indeed work like a champ for me. The only challenge I had was to take the traditional socket model which tends to have worker threads doing the I/O and turn it on its head because I need a different model, at least I think I do.

        -mark

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://726911]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-26 00:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found