WSAEINVAL error from WSASocket on socket duplication
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 ) );
sockF开发者_开发百科d = WSASocket( AF_INET, SOCK_STREAM, IPPROTO_TCP, lpWsaProtocolInfo,
0, 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.
精彩评论