From d654aa6788245d7b69c678206a1add7bd0ab850a Mon Sep 17 00:00:00 2001 From: Dwight Date: Tue, 24 Feb 2009 13:14:08 -0500 Subject: [PATCH] fix bug with auto reconnect in the client --- client/dbclient.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/client/dbclient.cpp b/client/dbclient.cpp index 906b034ae43..ad9c9c8c399 100644 --- a/client/dbclient.cpp +++ b/client/dbclient.cpp @@ -384,7 +384,6 @@ namespace mongo { int port; size_t idx = serverAddress.find( ":" ); if ( idx != string::npos ) { - //out() << "port string:" << ip.substr( idx ) << endl; port = strtol( serverAddress.substr( idx + 1 ).c_str(), 0, 10 ); ip = serverAddress.substr( 0 , idx ); ip = hostbyname(ip.c_str()); @@ -590,11 +589,21 @@ namespace mongo { } bool DBClientConnection::call( Message &toSend, Message &response, bool assertOk ) { - if ( !port().call(toSend, response) ) { + /* todo: this is very ugly messagingport::call returns an error code AND can throw + an exception. we should make it return void and just throw an exception anytime + it fails + */ + try { + if ( !port().call(toSend, response) ) { + failed = true; + if ( assertOk ) + massert("dbclient error communicating with server", false); + return false; + } + } + catch( SocketException & ) { failed = true; - if ( assertOk ) - massert("dbclient error communicating with server", false); - return false; + throw; } return true; }