There are two connected sockets. How can I interconnect them?
int client = get_connected_client_socket(); int proxy = get_connected_proxy_socket(); negotiate_with_proxy(proxy); iterconnect(client, proxy); // Now forgot about both client and proxy. // System should handle IO/shutdown/close. // Ideally even without any support of the user-space process.
Can Linux do it? Can it be done by tricking connection tracking to change tracking status of existing connection?
@related Determine how much can I write into a filehandle; copying data from one FH to the other
You can share a socket between two (or more) processes in Linux and even Windows. Under Linux (Or POSIX type OS), using fork() will cause the forked child to have copies of all the parent's file descriptors.
@premktiw: Yes, multiple client sockets can be bound to the same local IP/port pair at the same time, if they are connected to different server IP/Port pairs so the tuples of local+remote pairs are unique. And yes, it is possible for a client to have more than 64K concurrent connections total.
Sockets are a way to enable inter-process communication between programs running on a server, or between programs running on separate servers. Communication between servers relies on network sockets, which use the Internet Protocol (IP) to encapsulate and handle sending and receiving data.
Sockets allow you to exchange information between processes on the same machine or across a network, distribute work to the most efficient machine, and they easily allow access to centralized data. Socket application program interfaces (APIs) are the network standard for TCP/IP.
Are you aware of splice(). Based on your two questions I think this is where you are headed. Last I checked you can't do this in one splice call because both of file descriptors can't be sockets. But you should be able to do it in 2 calls (sockin->pipe->sockout). Also take a look at tee(). These may not be exactly what you want but from what I can figure they are in the ballpark.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With