How do I make sure that a socket bound to a port is properly released on process exit such that the port can be reused without bind() failing with EADDRINUSE? I
bind()
Not exactly an answer to your question, but for completeness:
On Windows you can set the TcpTimedWaitDelay registry value to set the timeout for releasing closed TCP connections to as low as 30 seconds.