Question

Is it possible to join two sockets?

For example, if a process is acting as a router of messages between 2 other processes at some point being able to step aside would save a bunch of socket IO. This seems like it should be possible, but I've never even HEARD of it being done!

If it is possible, is it possible on Linux AND Windows? If so, are different mechanisms used to set this up?

BTW: I just found this:

Linux splice() system call.

This seems close to what I am asking for (assuming of course this works on socket FD's as well), but is there a Windows equivalent?

Was it helpful?

Solution

AFAIK, It is not possible.

A simple example: If your processes runs on three different machines, how could the proxy machine step aside without involving traffic redirection at TCP/UDP/whatever level?

splice is not a solution, it simply optimizes the i/o transfer avoiding unnecessary memory copies but, in any case, you need a process that cycles on input and call splice to "transfer" data to output (and if the sockets are real network sockets, the data have to pass twice through the network card).

LLP, Andrea

OTHER TIPS

The short answer is No.

The slightly longer answer is Not Generally. The splice() system call is Linux-specific, and isn't defined for sockets. If it were to be defined for sockets, then it would be a way to connect a memory mapped file to or from a stream socket. It wouldn't be bidirectional. The gods only know what exists on Windows in this area.

The Excessively Geeky answer is Well, You Could Extend The OS Kernel, But... that might not be what you want. If neither remote address of the two PF_INET or PF_INET6 sockets is node-local, then the router will still be forwarding packets between the two remote hosts, each of which has a socket 5-tuple that references your router host. And no, I will not explain the dark arts of ARP/ND6 spoofing to work around that problem.

I have programed something like this in the past. Assuming, you are the programmer for all three processes it is possible but tricky. If you have socket connection A and socket connection B, you take the information from A, send it to B and have B send a connection request to A. This will require a bit of coding, but it should work. It did for me. Hope that works! Good luck!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top