views:

157

answers:

2
+2  Q: 

Joining 2 Sockets?

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 their a Windows equivalent?

+1  A: 

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

andcoz
I realized after I posted this that to truly do this would require support at the tcp/ip layer... If a router could send some out of band packet to the client that said "seamlessly switch all destination addresses to x.x.x.x for this socket"... then it would work...
dicroce
A: 

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.

james woodyatt