0

I'm trying to transfer socket from the one process to the another process constantly. I'm using WSADuplicateSocket on the master process which always works fine. Then I'm calling WSASocket on the child process. However, I do get WSAEINVAL error from WSASocket once in a while.

I check lpWsaProtocolInfo parameter and it's always good. So I really have no idea how this error could happen?

Master:

int err = WSADuplicateSocket( sockFd, childPID, 
                        (LPWSAPROTOCOL_INFO)sockInfo );

Child:

LPWSAPROTOCOL_INFO lpWsaProtocolInfo = 
    (LPWSAPROTOCOL_INFO)malloc( sizeof( *lpWsaProtocolInfo ) );

memcpy( lpWsaProtocolInfo, sockInfo, sizeof( *lpWsaProtocolInfo ) );

sockFd = WSASocket( AF_INET, SOCK_STREAM, IPPROTO_TCP, lpWsaProtocolInfo, 
                    0, 0 );
HcTeP
  • 1
  • 1
  • what's the overall scenario? Could you post the code for the client where you call WSASocket? – obelix Aug 19 '10 at 02:56

1 Answers1

0

Check the Access Rights of the Child process. Make sure that bInheritHandles is true on your call to CreateProcess.

I use CREATE_PRESERVE_CODE_AUTHZ_LEVEL in dwCreationFlags, and it works for me.

Ramon Zarazua B.
  • 7,195
  • 4
  • 22
  • 26