以下为个人理解,没用过这个方法
该方法的解释是:Duplicates the socket reference for the target process, and closes the socket for this process.
Parameters
targetProcessId
Type: System.Int32
The ID of the target process where a duplicate of the socket reference is created.
Return Value
Type: System.Net.Sockets.SocketInformation
The socket reference to be passed to the target process.
我的理解是:比如进程A创建了一个套接字,这个套接字(内核中有一个套接字引用,比如k表示。内核空间是进程共享的,也就是这个k,所以的进程其实都可以访问到的)在进程A中的fd为fd1(内核在fd1和k之间存在映射,这个映射是绑在A进程上的)。此时如果我想在B进程用这个套接字,那么我调用DuplicateAndClose(B)后,会返回给我一个info信息,此info进行中包含了我可以在进程B中使用的信息,比如里面有一个fd2.到这个时候,A进行就不能用fd1了(因为内核将映射关系由k和fd1映射改为了k和fd2映射)。当然,A也不能用fd2。此时,如果A进行将info信息(包含fd2信息)通过进程间通信给B进程,那么B进行就可以使用fd2进行socket操作了。