diff options
author | Eliot Horowitz <eliot@10gen.com> | 2011-04-28 13:15:34 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2011-05-02 13:00:38 -0400 |
commit | 5347089eaffb4f1a932924ad93cde341cdc4935a (patch) | |
tree | df64e49e7e226ac77a4ebf7a6768b4142f7f2d39 | |
parent | 00a41661dbfb4ee8456fbb17f211d9b50d1cd1fe (diff) | |
download | mongo-5347089eaffb4f1a932924ad93cde341cdc4935a.tar.gz |
fix socket time SERVER-3014
-rw-r--r-- | util/message.cpp | 45 |
1 files changed, 21 insertions, 24 deletions
diff --git a/util/message.cpp b/util/message.cpp index 916aa342ce9..bcb1772a8d1 100644 --- a/util/message.cpp +++ b/util/message.cpp @@ -359,7 +359,7 @@ namespace mongo { ConnectBG(int sock, SockAddr farEnd) : _sock(sock), _farEnd(farEnd) { } void run() { _res = ::connect(_sock, _farEnd.raw(), _farEnd.addressSize); } - string name() const { return ""; /* too short lived to need to name */ } + string name() const { return "ConnectBG"; } int inError() const { return _res; } private: @@ -628,12 +628,20 @@ again: unsigned retries = 0; while( len > 0 ) { int ret = ::recv( sock , buf , len , portRecvFlags ); - if ( ret == 0 ) { + if ( ret > 0 ) { + if ( len <= 4 && ret != len ) + log(_logLevel) << "MessagingPort recv() got " << ret << " bytes wanted len=" << len << endl; + assert( ret <= len ); + len -= ret; + buf += ret; + } + else if ( ret == 0 ) { log(3) << "MessagingPort recv() conn closed? " << farEnd.toString() << endl; throw SocketException( SocketException::CLOSED ); } - if ( ret < 0 ) { + else { /* ret < 0 */ int e = errno; + #if defined(EINTR) && !defined(_WIN32) if( e == EINTR ) { if( ++retries == 1 ) { @@ -642,29 +650,18 @@ again: } } #endif - if ( e != EAGAIN || _timeout == 0 ) { - SocketException::Type t = SocketException::RECV_ERROR; -#if defined(_WINDOWS) - if( e == WSAETIMEDOUT ) t = SocketException::RECV_TIMEOUT; -#else - /* todo: what is the error code on an SO_RCVTIMEO on linux? EGAIN? EWOULDBLOCK? */ + if ( ( e == EAGAIN +#ifdef _WINDOWS + || e == WSAETIMEDOUT #endif - log(_logLevel) << "MessagingPort recv() " << errnoWithDescription(e) << " " << farEnd.toString() <<endl; - throw SocketException(t); - } - else { - if ( !serverAlive( farEnd.toString() ) ) { - log(_logLevel) << "MessagingPort recv() remote dead " << farEnd.toString() << endl; - throw SocketException( SocketException::RECV_ERROR ); - } + ) && _timeout > 0 ) { + // this is a timeout + log(_logLevel) << "MessagingPort recv() timeout " << farEnd.toString() <<endl; + throw SocketException(SocketException::RECV_TIMEOUT); } - } - else { - if ( len <= 4 && ret != len ) - log(_logLevel) << "MessagingPort recv() got " << ret << " bytes wanted len=" << len << endl; - assert( ret <= len ); - len -= ret; - buf += ret; + + log(_logLevel) << "MessagingPort recv() " << errnoWithDescription(e) << " " << farEnd.toString() <<endl; + throw SocketException(SocketException::RECV_ERROR); } } } |