1 /***************************************************************************
2 * Copyright (C) 2008 by Gerd v. Egidy *
5 * This library is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU Lesser General Public License version *
7 * 2.1 as published by the Free Software Foundation. *
9 * This library is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU Lesser General Public License for more details. *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18 ***************************************************************************/
23 #include <socket_wrapper.hxx>
28 client_connection* BasicSocketWrapper::get_connection(void)
32 if (socket_type == tcp_s)
33 c=std::auto_ptr<socket_client_connection>
34 (new socket_client_connection(port,server,connect_timeout_usec,max_retries,logstream,log_level));
35 else if (socket_type == unix_s)
36 c=std::auto_ptr<socket_client_connection>
37 (new socket_client_connection(path,connect_timeout_usec,max_retries,logstream,log_level));
43 void ReconnectSocketWrapper::handle(command_client* stubBase, boost::function< void() > f)
51 // we always reconnect if something went wrong before:
52 // makes sure the buffers are clean of half-sent packets etc.
60 catch(t2n_connect_error &e)
62 // reconnect already tries max_tries times to reconnect: we are done if that failed
65 catch(t2n_communication_error &e)
67 // aborts the loop with an exception after max_retries iterations
68 // retries means that the first try doesn't count: use >
69 if (tries > max_retries)
72 // otherwise ignore the exception and reconnect in the next iteration
83 client_connection* ReconnectIgnoreFailureSocketWrapper::get_connection(void)
85 client_connection* tmp;
89 tmp=BasicSocketWrapper::get_connection();
91 catch(t2n_connect_error &e)
93 // TODO: return some kind of dummy connection
103 void ReconnectIgnoreFailureSocketWrapper::handle(command_client* stubBase, boost::function< void() > f)
105 // TODO: check for dummy connection and try to establish a real one
109 ReconnectSocketWrapper::handle(stubBase,f);
111 catch(t2n_communication_error &e)