Pass an open SOCKET to a new process?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I've got a WinSock server process which accepts a socket connection and then
needs to create a new process to server the client connection. How do I pass
on the SOCKET connection itself to the new process?

Here's some psuedo code on what I'm trying to do:


SockFd = socket(AF_INET, SOCK_STREAM, 0);

memset(&ServAddr, 0, sizeof(ServAddr));
ServAddr.sin_family = AF_INET;
ServAddr.sin_addr.s_addr = Addr;
ServAddr.sin_port = Port;

bind(SockFd, (struct sockaddr *) &ServAddr, sizeof(ServAddr));

listen(SockFd, 5);

sock = accept(SockFd, ...);

CreateProcess(...);

I need to somehow pass the client connection on "sock" on to the new process
so that the new process can handle all the client's requests, then exit.

I'm using threads to wrap the polling and the client CreateProcess portions
in. I would like to avoid a pure thread model for client processing because
client's do not connection often, but the server is expected to run for many
months at a time without a restart. A seperate process seems like the most
stable way to go.

This is a port of a server from UNIX land. The UNIX code simply does a
fork() which allows the child process to inherit the socket connection from
the client.

I've been trying to see if there's some way of turning the SOCKET into a
HANDLE and then duplicating that so the new process gets the HANDLE, but
there doesn't seem to be a portable way of converting SOCKET to HANDLE.
Several folks have told me that a SOCKET value *is* a HANDLE value, but it's
not written this way and could change with no warning.

Any pointers would be most appreciated.

-mike
.



Relevant Pages

  • Re: How can I write a activeX that support socket communication in web page?
    ... browser since they extend past browser functionality. ... since at least Flash 5. ... Games can use the extra socket connection to send real-time data back ... HTTP for the client to send commands to the server but have an extra ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: socket programming related.
    ... written code for socket connection between client and server. ... sent data to server for server processing (also server echoing back ...
    (comp.lang.python)
  • Re: TCP receive too many small packets
    ... I have a client / server application that communicates with each other ... thru a socket connection. ... Is something wrong with sending small TCP packets? ...
    (microsoft.public.win32.programmer.networks)
  • Re: TCP receive too many small packets
    ... I have a client / server application that communicates with each other ... thru a socket connection. ... Is something wrong with sending small TCP packets? ...
    (microsoft.public.win32.programmer.networks)
  • Re: TCL socket connection
    ... How do i establish a socket connection that stays up and does not cause the client to hang when I issue another echo request to the server? ...
    (comp.lang.tcl)