Re: Passing sockets....

Richard B. Johnson (
Wed, 26 Feb 1997 20:04:09 -0500 (EST)

On Wed, 26 Feb 1997, Peter Enderborg wrote:

> I need a kernel function that could pass sockets to other
> processes. I whant to have mutiple servers for the same
> protocol. For example a logon process that validate the
> user, and then pass the socket to a server that handle the
> requests. But I do not whant do create a process. I have
> a single process multi threaded server that I whant to
> hadle the requests. Yes, I could open a new localsocket or
> some thing like that. But than it have to make a lots of extra
> memory copys and context switches. Nice if we had a kernel function
> that could pass the sockets to a other process.
> I have not found this feature in any operatin system, is there
> any operating system with that feature ?
A socket is a file-descriptor. The file-descriptor numbers go from 0 to
N and are process-specific. In other words several tasks may have the
same socket numbers which refer to different things. Therefore, even if
you were to "give" the socket to another process, it couldn't have the
same number. What you seem to need is a "socket server". It would
communicate with your server via a pipe, shared memory, or another
socket. Note that X11 communicates with the server via a socket.

Suppose, instead of using many sockets in your server, you only used
one. You posted a listen() and an accept() on localhost port xxxx.
Your "socket-server" accepted multiple connections on the "real" network
at whatever port you are using. The "socket-server" then just wrote
incomming data to your server after a header that your socket-server
added. It received data from your server using the same header which
contained only the socket-server's socket number. The socket-server
could then forward these data to the correct hosts because the header
contained its socket number.

Dick Johnson
Richard B. Johnson
Project Engineer
Analogic Corporation
Voice : (508) 977-3000 ext. 3754
Fax : (508) 532-6097
Modem : (508) 977-6870
Ftp :
Email :,
Penguin : Linux version 2.1.26 on an i586 machine (66.15 BogoMips).
Warning : It's hard to remain at the trailing edge of technology.