X-Git-Url: http://developer.intra2net.com/git/?p=libt2n;a=blobdiff_plain;f=src%2Fsocket_wrapper.cpp;h=ac88144433c32930c08be2a92b3e89f3f0602406;hp=d153716a59536afced0c96d55904a790a4f671b3;hb=fb3345ada7ea94225b78994fd50e3de693a2a3d5;hpb=4c3662a0b083759056b93c21e747e5551a8ddfcc diff --git a/src/socket_wrapper.cpp b/src/socket_wrapper.cpp index d153716..ac88144 100644 --- a/src/socket_wrapper.cpp +++ b/src/socket_wrapper.cpp @@ -40,7 +40,7 @@ client_connection* BasicSocketWrapper::get_connection(void) return c.get(); } -void ReconnectSocketWrapper::handle(command_client* stubBase, boost::function< void() > f) +bool ReconnectSocketWrapper::handle(command_client* stubBase, boost::function< void() > f) { int tries=0; @@ -55,7 +55,7 @@ void ReconnectSocketWrapper::handle(command_client* stubBase, boost::function< v f(); // we were successful - return; + return true; } catch(t2n_connect_error &e) { @@ -78,44 +78,58 @@ void ReconnectSocketWrapper::handle(command_client* stubBase, boost::function< v tries++; } + + return false; } client_connection* ReconnectIgnoreFailureSocketWrapper::get_connection(void) { - client_connection* tmp; + client_connection* tmp=BasicSocketWrapper::get_connection(); - try - { - tmp=BasicSocketWrapper::get_connection(); - } - catch(t2n_connect_error &e) + if (tmp->is_closed()) { - // TODO: return some kind of dummy connection - } - catch(...) - { - throw; + // throw away the closed connection... + c.reset(); + // ...return the dummy one instead + tmp=&dc; } return tmp; } -void ReconnectIgnoreFailureSocketWrapper::handle(command_client* stubBase, boost::function< void() > f) +bool ReconnectIgnoreFailureSocketWrapper::handle(command_client* stubBase, boost::function< void() > f) { - // TODO: check for dummy connection and try to establish a real one - - try + if (!connection_established()) { - ReconnectSocketWrapper::handle(stubBase,f); - } - catch(t2n_communication_error &e) - { - // ignore + // dummy connection is in place: try to establish a real one + client_connection* tmp=get_connection(); + + if (tmp != &dc) + { + // success! we've got a real connection + stubBase->replace_connection(tmp); + } } - catch(...) + + // only try to handle the call if we've got a real connection + if (connection_established()) { - throw; + try + { + ReconnectSocketWrapper::handle(stubBase,f); + return true; + } + catch(t2n_communication_error &e) + { + // ignore + } + catch(...) + { + throw; + } } + + return false; } }