C++ application: Is it possible to pass accepted T

2019-01-26 15:28发布

So I wonder - is it possible to pass accepted TCP connection (on Windows or Unix like OS) from one process to another? Here the point is to pass connection - not data in a way a proxy app would.

2条回答
叼着烟拽天下
2楼-- · 2019-01-26 16:00

On Windows, use WSADuplicateSocket, pass the filled in WSAPROTOCOL_INFO to the other process, use WSPSocket to recreate a socket.

On unix-like OS'es this is possible using the sendmsg() system call. libancillary abstracts this for you.

查看更多
欢心
3楼-- · 2019-01-26 16:15

In Unix, a TCP connection is represented as a socket file descriptor. When you fork a process, the file descriptors are inherited by the child process, including TCP sockets. (Though they may be closed on exec if given the FD_CLOEXEC flag with fcntl.)

It's also possible to transfer file descriptors between unrelated processes using a local (Unix) domain socket; see this question.

I'm not sure about Windows.

查看更多
登录 后发表回答