Place sockets and file port fixes

This commit is contained in:
Kevin Tew 2011-08-26 14:25:18 -06:00
parent 801e5dbe0e
commit 5d27959c57
3 changed files with 32 additions and 27 deletions

View File

@ -2509,6 +2509,22 @@ void scheme_socket_to_ports(intptr_t s, const char *name, int takeover,
}
}
intptr_t scheme_dup_socket(intptr_t fd) {
#ifdef USE_WINSOCK_TCP
intptr_t nsocket;
WSAPROTOCOL_INFO protocolInfo;
WSADuplicateSocket(fd, GetCurrentProcessId(), &protocolInfo);
nsocket = WSASocket(FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, &protocolInfo, 0, WSA_FLAG_OVERLAPPED);
return nsocket;
#else
intptr_t nfd;
do {
nfd = dup(fd);
} while (nfd == -1 && errno == EINTR);
return nfd;
#endif
}
/*========================================================================*/
/* UDP */
/*========================================================================*/

View File

@ -1030,7 +1030,7 @@ static Scheme_Object *shallow_types_copy(Scheme_Object *so, Scheme_Hash_Table *h
return o;
}
}
else
else if (can_raise_exn)
bad_place_message(so);
break;
case scheme_input_port_type:
@ -1041,9 +1041,6 @@ static Scheme_Object *shallow_types_copy(Scheme_Object *so, Scheme_Hash_Table *h
if (copy) {
new_so = make_serialized_tcp_fd(fd, so->type);
}
else {
bad_place_message(so);
}
}
else if (SCHEME_TRUEP(scheme_file_stream_port_p(1, &so))) {
if (scheme_get_port_file_descriptor(so, &fd)) {
@ -1062,13 +1059,11 @@ static Scheme_Object *shallow_types_copy(Scheme_Object *so, Scheme_Hash_Table *h
sffd->type = so->type;
new_so = (Scheme_Object *) sffd;
}
else {
else if (can_raise_exn)
bad_place_message(so);
}
}
else {
else if (can_raise_exn)
bad_place_message(so);
}
}
break;
case scheme_serialized_tcp_fd_type:
@ -2084,9 +2079,14 @@ static void places_message_cleanup_worker(Scheme_Object **pso, Scheme_Hash_Table
Scheme_Object *out;
int fd = ((Scheme_Simple_Object *) so)->u.two_int_val.int2;
# ifdef USE_WINSOCK_TCP
CloseHandle(fd);
# else
close(fd);
# else
{
intptr_t rc;
do {
rc = close(fd);
} while (rc == -1 && errno == EINTR);
}
# endif
}
break;
@ -2097,7 +2097,12 @@ static void places_message_cleanup_worker(Scheme_Object **pso, Scheme_Hash_Table
#ifdef WINDOWS_FILE_HANDLES
CloseHandle((HANDLE)sffd->fd);
#else
close(sffd->fd);
{
intptr_t rc;
do {
rc = close(sffd->fd);
} while (rc == -1 && errno == EINTR);
}
#endif
}
break;

View File

@ -1185,22 +1185,6 @@ void scheme_collapse_win_fd(void *fds)
#endif
}
intptr_t scheme_dup_socket(intptr_t fd) {
#ifdef USE_WINSOCK_TCP
intptr_t nsocket;
WSAPROTOCOL_INFO protocolInfo;
WSADuplicateSocket(fd, GetCurrentProcessId(), &protocolInfo);
nsocket = WSASocket(FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, &protocolInfo, 0, WSA_FLAG_OVERLAPPED);
return nsocket;
#else
intptr_t nfd;
do {
nfd = dup(fd);
} while (nfd == -1 && errno == EINTR);
return nfd;
#endif
}
intptr_t scheme_dup_file(intptr_t fd) {
#ifdef WINDOWS_FILE_HANDLES
HANDLE newhandle;