summaryrefslogtreecommitdiff
path: root/util/net
diff options
context:
space:
mode:
authorAntonin Kral <a.kral@bobek.cz>2012-06-05 19:50:34 +0200
committerAntonin Kral <a.kral@bobek.cz>2012-06-05 19:50:34 +0200
commit3703a282eca7e79e91f4bd651b1b861b76dc6c68 (patch)
treeb69552c69c48ebc6899f7bbbe42843793a423237 /util/net
parent61619b3142c1de8f60f91964ff2656054d4f11a6 (diff)
downloadmongodb-3703a282eca7e79e91f4bd651b1b861b76dc6c68.tar.gz
Imported Upstream version 2.0.6
Diffstat (limited to 'util/net')
-rw-r--r--util/net/sock.cpp26
1 files changed, 13 insertions, 13 deletions
diff --git a/util/net/sock.cpp b/util/net/sock.cpp
index ac565c3..a032e50 100644
--- a/util/net/sock.cpp
+++ b/util/net/sock.cpp
@@ -52,10 +52,18 @@ namespace mongo {
tv.tv_usec = (int)((long long)(secs*1000*1000) % (1000*1000));
bool report = logLevel > 3; // solaris doesn't provide these
DEV report = true;
- bool ok = setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *) &tv, sizeof(tv) ) == 0;
- if( report && !ok ) log() << "unabled to set SO_RCVTIMEO" << endl;
- ok = setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (char *) &tv, sizeof(tv) ) == 0;
- DEV if( report && !ok ) log() << "unabled to set SO_RCVTIMEO" << endl;
+#if defined(_WIN32)
+ tv.tv_sec *= 1000; // Windows timeout is a DWORD, in milliseconds.
+ int status = setsockopt( sock, SOL_SOCKET, SO_RCVTIMEO, (char *) &tv.tv_sec, sizeof(DWORD) ) == 0;
+ if( report && (status == SOCKET_ERROR) ) log() << "unable to set SO_RCVTIMEO" << endl;
+ status = setsockopt( sock, SOL_SOCKET, SO_SNDTIMEO, (char *) &tv.tv_sec, sizeof(DWORD) ) == 0;
+ DEV if( report && (status == SOCKET_ERROR) ) log() << "unable to set SO_SNDTIMEO" << endl;
+#else
+ bool ok = setsockopt( sock, SOL_SOCKET, SO_RCVTIMEO, (char *) &tv, sizeof(tv) ) == 0;
+ if( report && !ok ) log() << "unable to set SO_RCVTIMEO" << endl;
+ ok = setsockopt( sock, SOL_SOCKET, SO_SNDTIMEO, (char *) &tv, sizeof(tv) ) == 0;
+ DEV if( report && !ok ) log() << "unable to set SO_SNDTIMEO" << endl;
+#endif
}
#if defined(_WIN32)
@@ -755,15 +763,7 @@ namespace mongo {
}
void Socket::setTimeout( double secs ) {
- struct timeval tv;
- tv.tv_sec = (int)secs;
- tv.tv_usec = (int)((long long)(secs*1000*1000) % (1000*1000));
- bool report = logLevel > 3; // solaris doesn't provide these
- DEV report = true;
- bool ok = setsockopt(_fd, SOL_SOCKET, SO_RCVTIMEO, (char *) &tv, sizeof(tv) ) == 0;
- if( report && !ok ) log() << "unabled to set SO_RCVTIMEO" << endl;
- ok = setsockopt(_fd, SOL_SOCKET, SO_SNDTIMEO, (char *) &tv, sizeof(tv) ) == 0;
- DEV if( report && !ok ) log() << "unabled to set SO_RCVTIMEO" << endl;
+ setSockTimeouts( _fd, secs );
}
#if defined(_WIN32)