if (!DuplicateHandle(
GetCurrentProcess(),
(HANDLE)connectfd,
GetCurrentProcess(),
(HANDLE *)&duplicate_connectfd,
0,
TRUE, // inheritable
DUPLICATE_SAME_ACCESS)) {
exit(1);
}
rc = getsockopt(duplicate_connectfd, SOL_SOCKET, SO_TYPE, (char
*)&sockettype, &size_sockettype);
if (rc == SOCKET_ERROR) {
printf("testserver: getsockopt failed\n");
exit(1);
}
if (sockettype != SOCK_STREAM) {
printf("testserver: socket %d is not a SOCK_STREAM, it is %d\n",
duplicate_connectfd, sockettype);
} else {
printf("testserver: socket %d is a SOCK_STREAM\n", duplicate_connectfd);
}
If I run this code on Windows 2000 Pro with Service Pack 5, the
DuplicateHandle succeeds but the subsequent getsockopt() call fails! This
works on Windows XP Pro. If I do a closesocket() it also fails. The failure
is "not a socket" (error 10038).
Anyone else seen this and any ideas how to fix it?