NCW

Foreshortened

Close-up views of Nicholas Wilson

Are TCP SOCKET handles inheritable?

In a fit of pique, I’ve created a wonderful pair of self-answered Stack Overflow questions, to answer the two sides of this Microsoft coin:

  1. If you try to inherit SOCKET handles, will it work? No, unlike other handles, they’re not always usable in child processes. This is by design (although they regret their ’90s short-sightedness: recently they’ve started to “recommend” that developers don’t abuse the TCP stack with Layered Service Providers).
  2. Can you prevent SOCKET handles from being inherited? No, unlike other handles, they default to inheriting, and unlike other handles, it’s not always possible to prevent them being inherited by child processes. This is by design (although they regret their ’90s short-sightedness: they released a hotfix on Vista provide a way for the first time to make non-inheritable SOCKET handles).

A very neat no-win situation! General astonishment all round the office, and a new patch release last week to work around the places where we assumed differently. This is really the rock-bottom of Windows filth, I hope. Naturally, the only firm documentation we can find is in their supplied code samples, which violate our observations and conclusions now we know where to look.