From ad8c021c546b687e4bf9327aad50854fa0f0d19c Mon Sep 17 00:00:00 2001 From: Mathias Stearn Date: Tue, 7 Sep 2010 17:04:35 -0400 Subject: support sub-second timeouts SERVER-1515 --- client/dbclient.h | 4 ++-- util/message.cpp | 2 +- util/message.h | 4 ++-- util/sock.h | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/client/dbclient.h b/client/dbclient.h index 5ca2b8f6345..944805582bc 100644 --- a/client/dbclient.h +++ b/client/dbclient.h @@ -796,7 +796,7 @@ namespace mongo { void _checkConnection(); void checkConnection() { if( failed ) _checkConnection(); } map< string, pair > authCache; - int _timeout; + double _timeout; bool _connect( string& errmsg ); public: @@ -807,7 +807,7 @@ namespace mongo { @param timeout tcp timeout in seconds - this is for read/write, not connect. Connect timeout is fixed, but short, at 5 seconds. */ - DBClientConnection(bool _autoReconnect=false, DBClientReplicaSet* cp=0, int timeout=0) : + DBClientConnection(bool _autoReconnect=false, DBClientReplicaSet* cp=0, double timeout=0) : clientSet(cp), failed(false), autoReconnect(_autoReconnect), lastReconnectTry(0), _timeout(timeout) { } /** Connect to a Mongo database server. diff --git a/util/message.cpp b/util/message.cpp index a809c1fa091..cd19bd590bc 100644 --- a/util/message.cpp +++ b/util/message.cpp @@ -301,7 +301,7 @@ namespace mongo { ports.insert(this); } - MessagingPort::MessagingPort( int timeout, int ll ) : tag(0) { + MessagingPort::MessagingPort( double timeout, int ll ) : tag(0) { _logLevel = ll; ports.insert(this); sock = -1; diff --git a/util/message.h b/util/message.h index 203ad832b99..9651141ad6c 100644 --- a/util/message.h +++ b/util/message.h @@ -98,7 +98,7 @@ namespace mongo { // in some cases the timeout will actually be 2x this value - eg we do a partial send, // then the timeout fires, then we try to send again, then the timeout fires again with // no data sent, then we detect that the other side is down - MessagingPort(int timeout = 0, int logLevel = 0 ); + MessagingPort(double timeout = 0, int logLevel = 0 ); virtual ~MessagingPort(); @@ -133,7 +133,7 @@ namespace mongo { PiggyBackData * piggyBackData; public: SockAddr farEnd; - int _timeout; + double _timeout; int _logLevel; // passed to log() when logging errors static void closeAllSockets(unsigned tagMask = 0xffffffff); diff --git a/util/sock.h b/util/sock.h index 4b4290d2324..897be8a4fc4 100644 --- a/util/sock.h +++ b/util/sock.h @@ -115,10 +115,10 @@ namespace mongo { return "/tmp/mongodb-" + BSONObjBuilder::numStr(port) + ".sock"; } - inline void setSockTimeouts(int sock, int secs) { + inline void setSockTimeouts(int sock, double secs) { struct timeval tv; - tv.tv_sec = secs; - tv.tv_usec = 0; + 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(sock, SOL_SOCKET, SO_RCVTIMEO, (char *) &tv, sizeof(tv) ) == 0; -- cgit v1.2.1