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 BATSBOE { namespace common {
20 
21 template<class LogonT>
22 inline
23 connectivity_policy<LogonT>::connectivity_policy(gateways_t const &gws, logon_args_t const &logon, logoff_args_t const &logoff) noexcept(true)
24 : gateways(gws), logon_args(logon), logoff_args(logoff) {}
25 
26 template<class LogonT>
27 template<class ConnectFn> inline void
28 connectivity_policy<LogonT>::operator()(ConnectFn const &cnx) const noexcept(false) {
29  boost::exception_ptr cnx_failed(connection_failed(cnx, gateways.primary_gateway));
30  if (cnx_failed) {
31  boost::rethrow_exception(cnx_failed);
32  }
33 }
34 
35 template<class LogonT>
36 template<class ConnectFn> inline boost::exception_ptr
37 connectivity_policy<LogonT>::connection_failed(ConnectFn const &cnx, endpoint_t const &endpoint) noexcept(true) {
38  boost::exception_ptr cnx_failed{};
39  for (unsigned i=0; i<max_attempts; ++i) {
40  try {
41  cnx(boost::asio::ip::tcp::endpoint(endpoint.first, endpoint.second));
42  break;
43  } catch (...) {
44  cnx_failed=boost::current_exception();
45  std::this_thread::sleep_for(min_timeout);
46  }
47  }
48  return cnx_failed;
49 }
50 
51 template<class MsgT>
52 template<class ClientCxn>
53 inline
54 server_hb_t<MsgT>::server_hb_t(ClientCxn &cxn)
55 : base_t(cxn, []() {return typename base_t::hb_t{base_t::hb_t::seq_num};}) {
56 }
57 
58 } } } } }