Re: socket in LISTENING state after a call to closesocket

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"Ben Voigt [C++ MVP]" <rbv@xxxxxxxxxxxxx> wrote in message news:eprasJWuJHA.5836@xxxxxxxxxxxxxxxxxxxxxxx
The socket is release when I kill the subprocess. I have used
calc.exe as subprocess with the same behavior.

What was your question? It sounds as if subprocesses are being
created with the "inherit handles" capability enabled. Until the
subprocess closes its handle, the socket isn't really closed. Or
something like that.

My question was why the socket was still in LISTENING mode after I
called closesocket but your answer raised another question. "inherit
handles" capability, how does it work and how do I turn it off on a
process started from managed code.

You can't, because it's not an attribute of the process. It's controlled at the time the child process is launched.

In Windows, all methods of starting a process eventually call CreateProcess
http://msdn.microsoft.com/en-us/library/ms682425(loband).aspx

Apparently Process.Start or whatever you are using to start a child task is passing TRUE as the value of bInheritHandles. And if the framework is starting a child task somewhere, somehow, and allowing it to inherit handles.... then you're pretty much at its mercy. But I would be surprised to find out that the framework is doing something so stupid. More likely it's a global Windows hook or other injected DLL (things like multi-monitor management programs often install these) that is making unauthorized duplicates of your handle.
But not all handles are inherited: only those that were created as inheritable (via bInheritHandle field of SECURITY_ATTRIBUTES struct) or if DuplicateHandle() or SetHandleInformation() were called.
Even if socket() creates inheritable handle, it should be possible to change it to non-inheritable: by calling SetHandleInformation() after socket was created.

Boris

.



Relevant Pages

  • Re: socket in LISTENING state after a call to closesocket
    ... created with the "inherit handles" capability enabled. ... subprocess closes its handle, ... Apparently Process.Start or whatever you are using to start a child task is ... to find out that the framework is doing something so stupid. ...
    (microsoft.public.win32.programmer.networks)
  • Re: Python OOP question
    ... ConnectionManager - handling/distributing incoming connections ... Socket - basic async socket object ... to be done is to inherit IOManager or Server object to do it. ...
    (comp.lang.python)
  • Python OOP question
    ... Socket - basic async socket object ... to be done is to inherit IOManager or Server object to do it. ... But there is some feeling about this design that it can be better. ...
    (comp.lang.python)
  • Re: Ask about iherite
    ... >> i want to inherit class Socket in System.Nets.Sockets, ... you have to call the constructor of the ... public class MySocket: Socket ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Help! dynamic classes (shapeshifter)
    ... I want to use simple dynamic function call (callback ... there are two different classes that inherit to that same socket class. ... class test1: public Socket ...
    (comp.lang.cpp)