1
0
Fork 0

Resolve socket bug under Windows.

This commit is contained in:
Max Neunhoeffer 2014-02-17 14:21:47 +01:00
parent e031c37b2d
commit dd3546ee40
6 changed files with 21 additions and 11 deletions

View File

@ -251,11 +251,18 @@ static inline void TRI_invalidatesocket (TRI_socket_t* socket) {
}
////////////////////////////////////////////////////////////////////////////////
/// @brief get file descriptor
/// @brief get file descriptor or handle, depending on OS
///
/// Note that this returns the fileHandle under Windows which is exactly
/// the right thing we need in all but one places.
////////////////////////////////////////////////////////////////////////////////
static inline int TRI_get_fd_of_socket (TRI_socket_t socket) {
static inline int TRI_get_fd_or_handle_of_socket (TRI_socket_t socket) {
#ifdef _WIN32
return socket.fileHandle;
#else
return socket.fileDescriptor;
#endif
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -103,7 +103,7 @@ namespace triagens {
_maximalHeaderSize(0),
_maximalBodySize(0) {
LOG_TRACE("connection established, client %d, server ip %s, server port %d, client ip %s, client port %d",
TRI_get_fd_of_socket(socket),
TRI_get_fd_or_handle_of_socket(socket),
_connectionInfo.serverAddress.c_str(),
(int) _connectionInfo.serverPort,
_connectionInfo.clientAddress.c_str(),
@ -123,7 +123,7 @@ namespace triagens {
protected:
~GeneralCommTask () {
LOG_TRACE("connection closed, client %d", (int) TRI_get_fd_of_socket(_commSocket));
LOG_TRACE("connection closed, client %d", (int) TRI_get_fd_or_handle_of_socket(_commSocket));
// free write buffers
for (deque<basics::StringBuffer*>::iterator i = _writeBuffers.begin(); i != _writeBuffers.end(); i++) {

View File

@ -276,7 +276,7 @@ namespace triagens {
LOG_DEBUG("trying to establish secure connection");
// convert in a SSL BIO structure
BIO * sbio = BIO_new_socket(TRI_get_fd_of_socket(socket), BIO_NOCLOSE);
BIO * sbio = BIO_new_socket(TRI_get_fd_or_handle_of_socket(socket), BIO_NOCLOSE);
if (sbio == 0) {
LOG_WARNING("cannot build new SSL BIO: %s", triagens::basics::lastSSLError().c_str());

View File

@ -579,7 +579,10 @@ EventToken SchedulerLibev::installSocketEvent (EventLoop loop, EventType type, T
}
ev_io* w = (ev_io*) watcher;
ev_io_init(w, socketCallback, TRI_get_fd_of_socket(socket), flags);
// Note that we do not use TRI_get_fd_or_handle_of_socket here because even
// under Windows we want get the entry fileDescriptor here because
// of the reason that is mentioned above!
ev_io_init(w, socketCallback, socket.fileDescriptor, flags);
ev_io_start(watcher->loop, w);
return watcher->token;

View File

@ -177,7 +177,7 @@ bool ClientConnection::prepare (const double timeout, const bool isWrite) const
tv.tv_usec = ((long) (timeout * 1000000.0)) % 1000000;
FD_ZERO(&fdset);
FD_SET(TRI_get_fd_of_socket(_socket), &fdset);
FD_SET(TRI_get_fd_or_handle_of_socket(_socket), &fdset);
fd_set* readFds = NULL;
fd_set* writeFds = NULL;
@ -189,7 +189,7 @@ bool ClientConnection::prepare (const double timeout, const bool isWrite) const
readFds = &fdset;
}
int sockn = (int) (TRI_get_fd_of_socket(_socket) + 1);
int sockn = (int) (TRI_get_fd_or_handle_of_socket(_socket) + 1);
int res = select(sockn, readFds, writeFds, NULL, &tv);
if (res > 0) {

View File

@ -162,7 +162,7 @@ bool SslClientConnection::connectSocket () {
return false;
}
if (SSL_set_fd(_ssl, TRI_get_fd_of_socket(_socket)) != 1) {
if (SSL_set_fd(_ssl, TRI_get_fd_or_handle_of_socket(_socket)) != 1) {
_endpoint->disconnect();
SSL_free(_ssl);
_ssl = 0;
@ -210,7 +210,7 @@ bool SslClientConnection::prepare (const double timeout, const bool isWrite) con
tv.tv_usec = ((long) (timeout * 1000000.0)) % 1000000;
FD_ZERO(&fdset);
FD_SET(TRI_get_fd_of_socket(_socket), &fdset);
FD_SET(TRI_get_fd_or_handle_of_socket(_socket), &fdset);
fd_set* readFds = NULL;
fd_set* writeFds = NULL;
@ -222,7 +222,7 @@ bool SslClientConnection::prepare (const double timeout, const bool isWrite) con
readFds = &fdset;
}
int sockn = (int) (TRI_get_fd_of_socket(_socket) + 1);
int sockn = (int) (TRI_get_fd_or_handle_of_socket(_socket) + 1);
if (select(sockn, readFds, writeFds, NULL, &tv) > 0) {
return true;
}