<br><div class="gmail_quote">On Thu, Apr 12, 2012 at 10:48 AM, Merwin <span dir="ltr"><<a href="mailto:merwin.irc@gmail.com">merwin.irc@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Le 12/04/2012 19:10, Dan Stromberg a écrit :<div class="im"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
I wonder if this'll do what you need:<br>
<a href="https://trac.calendarserver.org/browser/CalendarServer/trunk/twext/python/sendfd.py" target="_blank">https://trac.calendarserver.<u></u>org/browser/CalendarServer/<u></u>trunk/twext/python/sendfd.py</a><br>
</blockquote>
<br></div>
The problem is that this is Linux-only solution, and I would like to keep a multi-platform compatibility.<br></blockquote><div>I suspect it's actually pretty multiplatform, with one likely exception: Windows.  But the code itself is from Apple, and I first learned of the technique in Unix's heyday.<br>
 <br></div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
There are other ways to do this : use a Lock and do the select() directly in the children processes,<br>
but I can't control which process will get the lock, and it's totally possible that only 2 processes on 8<br>
will accept connections alternatively.<br></blockquote><div>If you have all your children bind using SO_REUSEADDR, and then have the parent process pass a "go ahead message" to an available child, you might get what you desire.  The unavailable child would then pass a "I'm available again" message back to the parent when ready for another piece of work.<br>
<br>The children probably should also be able to send a "I'm done with the socket" message to the parent as well, so the parent doesn't ask two children to use the socket at the same time.<br><br>This is kind of weird, but it seems to satisfy your requirement.<br>
<br>I believe SO_REUSEADDR is even more cross-platform than passing a filedescriptor.<br><br>Better still, don't have the children interact with the main socket; just let them get a complete message describing a piece of work from the parent.  This isn't as likely to run into OS idiosyncrasies.<br>
<br><br></div></div><br>