Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

DuplicateSocket fails on Windows 2000 Professional

10 views
Skip to first unread message

Eric Kleinberg

unread,
Sep 18, 2002, 2:24:27 PM9/18/02
to
I call DuplicateSocket() to duplicate a socked handle (connectfd) returned
by accept(). The calls is:

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?


0 new messages