有两个连接的套接字。如何互连它们?
- 出现在一个套接字上的数据应该写入另一个套接字。
- EOF/FIN 应该传播良好。如果一个是半封闭的,那么另一个也应该是半封闭的。
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.
Linux可以吗?是否可以通过欺骗连接跟踪来改变现有连接的跟踪状态来完成?
@related Determine how much can I write into a filehandle; copying data from one FH to the other
最佳答案
你知道splice()吗? .根据你的两个问题,我认为这就是你要去的地方。最后我检查了你不能在一个拼接调用中执行此操作,因为两个文件描述符都不能是套接字。但是你应该能够在 2 个调用中完成它(sockin->pipe->sockout)。另请查看 tee() .这些可能不完全是您想要的,但据我所知,它们都在大概范围内。
关于linux - 我如何在 Linux 中使用 "interconnect"两个套接字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2677262/