libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
connectivity_policy_impl.hpp
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright © 2015 by J.M.McGuiness, isimud@hussar.me.uk
3 **
4 ** This library is free software; you can redistribute it and/or
5 ** modify it under the terms of the GNU Lesser General Public
6 ** License as published by the Free Software Foundation; either
7 ** version 2.1 of the License, or (at your option) any later version.
8 **
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 GNU
12 ** Lesser General Public License for more details.
13 **
14 ** You should have received a copy of the GNU Lesser General Public
15 ** License along with this library; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 
19 namespace isimud { namespace ISIMUD_VER_NAMESPACE { namespace exchanges { namespace MIT { namespace common {
20 
21 template<class LogonT> inline
22 connectivity_policy<LogonT>::connectivity_policy(gateways_t const &gws, logon_args_t const &logon, logoff_args_t const &logoff) noexcept(true)
23 : gateways(gws), logon_args(logon), logoff_args(logoff) {
24 }
25 
26 template<class LogonT>
27 template<class ConnectFn> inline void
28 connectivity_policy<LogonT>::operator()(ConnectFn const &cnx) const noexcept(false) {
29  if (connection_failed(cnx, gateways.primary_gateway)) {
30  boost::exception_ptr cnx_failed(connection_failed(cnx, gateways.secondary_gateway));
31  if (cnx_failed) {
32  boost::rethrow_exception(cnx_failed);
33  }
34  }
35 }
36 
37 template<class LogonT>
38 template<class ConnectFn> inline boost::exception_ptr
39 connectivity_policy<LogonT>::connection_failed(ConnectFn const &cnx, endpoint_t const &endpoint) noexcept(true) {
40  boost::exception_ptr cnx_failed{};
41  for (unsigned i=0; i<max_attempts; ++i) {
42  try {
43  cnx(boost::asio::ip::tcp::endpoint(endpoint.first, endpoint.second));
44  break;
45  } catch (...) {
46  cnx_failed=boost::current_exception();
47  std::this_thread::sleep_for(min_timeout);
48  }
49  }
50  return cnx_failed;
51 }
52 
53 template<class MsgT>
54 template<class ClientCxn>
55 inline
56 server_hb_t<MsgT>::server_hb_t(ClientCxn &cxn)
57 : base_t(cxn, []() {return typename base_t::hb_t{};}) {
58 }
59 
60 } } } } }