c# - Error passing socket to child process when using STARTF_USESTDHANDLES flag with CreateProcess() -


I am trying to call a FastCGI application from the Net - this means that I have a socket in a socket The child's procedure must pass.

But what I see is that if I use the flag, the child application fails when he tries to read from the socket.

I did this job that I do not specify STARTF_USESTDHANDLES , but I want to understand why . , especially as my understanding

This is my C # application (error checking etc ... has been removed for brevity)

  string Command = @ "fastcgi.exe"; Socket Listener = New Socket (Address Family.Inter Network, SocketType.Stream, ProtocolType.Tcp); Listner. Bine (new IPPpoint (IP address no., 8221)); // Duplicate the socket handles so that this unsafe protected filehandsal childhandle; Basic methods. Duplicate Handle (Native Methams.GetContrent Process ()), New SafeFileHandle (Audience Handle, False), Basic Methods. GateContent Process (); Out-of-child Handle, 0, True, Basic Methods .DUPLICATE_SAME_ACCESS); Basic methods. STARTUPINFO startupInfo = New Basic Methods STARTUPINFO (); StartupInfo.hStdInput = childHandle; // Unloading the following line causes problems / / startupInfo.dwFlags = NativeMethods.STARTF_USESTDHANDLES; // Basic Process Start the NativeMethods.PROCESS_INFORMATION process; Basic methods. Create process (empty, command, empty, empty, true, 0, intit. Zero, blank, startup infonfo, outside process information); // To stop the process of shutting down the socket handle console. Readkey ();  

My child process is a fastcgi application sample, which is a failed line:

  BOOL ret = ReadFile (hStdin, pBuffer, dwSize, Amp; nNumberOfBytes, NULL); If (! Ret) {// dw = 87 (ERROR_INVALID_PARAMETER) DWORD dw = GetLastError (); }  

I am relatively new to both socket and handle programming, so why does this happen in any insight that it will be highly appreciated.

You can also try specifying the handle for std err and std out. When you specify STARTF_USESTDHANDLES, they need to be set explicitly.

This is done in unmanaged C / C ++:

  STARTUPINFO si; Zoramori (& amp; si, size (STARTUPINFO)); Si.cb = size (STARTUPINFO); ... si.dwFlags = STARTF_USESTDHANDLES; Si.hStdInput = myInheritableHandle; Si.hStdOutput = GetStdHandle (STD_OUTPUT_HANDLE); Si.hStdError = GetStdHandle (STD_ERROR_HANDLE);  

In addition, I hope you have to specify an already connected socket - that is, you can not just bind.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -