when you create a socket on win NT or later (e.g. 2k, XP, etc) it creates 2 underlying handles (visible in process explorer)
device\Tcp
device\Afd\Endpoint
It's possible to mark the device\Tcp handle non-inheritable using SetHandleInformation(), however I can't find any way to access the device\Afd\Endpoint handle to mark it not-inheritable. Therefore any child process our process spawns inherits a handle called device\Afd\Endpoint for every socket in our host application (which can be VERY many).
I've looked into WSADuplicateSocket, and that is useless (only usable to duplicate a socket into another process, and can't set inheritance flags).
MSDN docs say you can't call DuplicateHandle on a SOCKET. Presumably because of this problem above (2 handles). It does seem to perform the same function as SetHandleInformation.
My question - does anyone know of a way to mark the entire socket (both handles) non-inheritable? Or a way to set the default mode of socket creation to only create non-inheritable sockets?
Thanks
Start Free Trial