Well, I'm already not exactly using pure Ruby, since I'm wrapping
those msvcrt functions with Win32API, so that's not a problem.

WSADuplicateSocket isn't actually needed in my scenario. If the child
process is created with inheritable handles, then the sockets from the
parent propagate and can be used in the child process.

Besides that, I think using WSADuplicateSocket will suffer from the
same problem that my method does: there is code in rb_w32_select that
prevents select() from being called on sockets not created in the
current process by Ruby's own win32 wrappers around socket(),
accept(), etc.. See the extract_fd call -> is_not_socket -> is_socket
-> lookup in socklist.

Thanks
-K

On Fri, Jun 12, 2009 at 8:50 AM, Roger Pack<rogerdpack / gmail.com> wrote:
>> This works on Linux by persisting socket.fileno from the parent process and
>> calling TCPSocket.for_fd in the child process. On Windows, some tweaks to
>> this approach (wrapping _get_osfhandle and _open_osfhandle) will get me most
>> of the way there, but still falls a little short. IÃ×e done enough debugging
>> to point out the code/design in the Ruby source that is causing this
>> failure, in case youÃÅ like me to explain. IÃÎ not committed to this
>> approach, but I havenÃÕ been able to think of another one.
>
> I'm not sure how to do it in pure ruby. ooks lke it is possible
> using WSADuplicateSocket
>
> http://stackoverflow.com/questions/670891/is-there-a-way-for-multiple-processes-to-share-a-listening-socket
>
> if you want to.
> -=r
>
>