1
0
Fork 0

Change Windows version to pass SOCKET handles to libev.

One has to use the corresponding change in the ArangoDB-Windows
repository as well, where libev is patched for this purpose.
This commit is contained in:
Max Neunhoeffer 2014-03-10 15:38:03 +01:00
parent f3b755b6f7
commit 5110b45c26
3 changed files with 27 additions and 10 deletions

View File

@ -73,14 +73,19 @@ int TRI_closesocket (TRI_socket_t s) {
if (res != 0) {
LOG_WARNING("socket close error: %d", WSAGetLastError());
}
if (s.fileDescriptor != -1) {
res = _close(s.fileDescriptor);
/*
To close a file opened with _open_osfhandle, call _close.
The underlying handle is also closed by a call to _close,
so it is not necessary to call the Win32 function CloseHandle on the original handle.
*/
}
// We patch libev on Windows lightly to not really distinguish between
// socket handles and file descriptors, therefore, we do not have to do the
// following any more:
// if (s.fileDescriptor != -1) {
// res = _close(s.fileDescriptor);
// "To close a file opened with _open_osfhandle, call _close."
// The underlying handle is also closed by a call to _close,
// so it is not necessary to call the Win32 function CloseHandle
// on the original handle.
// However, we do want to do the special shutdown/recv magic above
// because only then we can reuse the port quickly, which we want
// to do directly after a port test.
// }
}
#else
if (s.fileDescriptor != TRI_INVALID_SOCKET) {

View File

@ -113,7 +113,13 @@ bool ListenTask::setup (Scheduler* scheduler, EventLoop loop) {
return false;
}
int res = _open_osfhandle (_listenSocket.fileHandle, 0);
// For the official version of libev we would do this:
// int res = _open_osfhandle (_listenSocket.fileHandle, 0);
// However, this opens a whole lot of problems and in general one should
// never use _open_osfhandle for sockets.
// Therefore, we do the following, although it has the potential to
// lose the higher bits of the socket handle:
int res = (int)_listenSocket.fileHandle;
if (res == - 1) {
LOG_ERROR("In ListenTask::setup could not convert socket handle to socket descriptor -- _open_osfhandle(...) failed");

View File

@ -429,7 +429,13 @@ bool SocketTask::setup (Scheduler* scheduler, EventLoop loop) {
return false;
}
int res = _open_osfhandle(_commSocket.fileHandle, 0);
// For the official version of libev we would do this:
// int res = _open_osfhandle(_commSocket.fileHandle, 0);
// However, this opens a whole lot of problems and in general one should
// never use _open_osfhandle for sockets.
// Therefore, we do the following, although it has the potential to
// lose the higher bits of the socket handle:
int res = (int)_commSocket.fileHandle;
if (res == -1) {
LOG_ERROR("In SocketTask::setup could not convert socket handle to socket descriptor -- _open_osfhandle(...) failed");