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.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."
  • 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