开发者

WSAEINVAL error from WSASocket on socket duplication

开发者 https://www.devze.com 2023-01-11 23:45 出处:网络
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 c

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消