summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2010-09-07 17:04:35 -0400
committerEliot Horowitz <eliot@10gen.com>2010-11-20 02:37:38 -0500
commitad8c021c546b687e4bf9327aad50854fa0f0d19c (patch)
treea97858f4c96b8178a7b4339db29a6e1a0d899e65
parent3f469b555721c37ecd989d7b7d86e122d5daca4d (diff)
downloadmongo-ad8c021c546b687e4bf9327aad50854fa0f0d19c.tar.gz
support sub-second timeouts SERVER-1515
-rw-r--r--client/dbclient.h4
-rw-r--r--util/message.cpp2
-rw-r--r--util/message.h4
-rw-r--r--util/sock.h6
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<string,string> > 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;