libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
connectivity_policy.hpp
Go to the documentation of this file.
1 #ifndef ISIMUD_EXCHANGES_FIX_common_connectivity_policy_hpp
2 #define ISIMUD_EXCHANGES_FIX_common_connectivity_policy_hpp
3 
4 /******************************************************************************
5 ** Copyright © 2016 by J.M.McGuiness, isimud@hussar.me.uk
6 **
7 ** This library is free software; you can redistribute it and/or
8 ** modify it under the terms of the GNU Lesser General Public
9 ** License as published by the Free Software Foundation; either
10 ** version 2.1 of the License, or (at your option) any later version.
11 **
12 ** This library is distributed in the hope that it will be useful,
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ** Lesser General Public License for more details.
16 **
17 ** You should have received a copy of the GNU Lesser General Public
18 ** License along with this library; if not, write to the Free Software
19 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21 
22 #include "../../common/server_heartbeats.hpp"
23 
24 #include <boost/asio/ip/address.hpp>
25 #include <boost/asio/ip/tcp.hpp>
26 #include <boost/exception_ptr.hpp>
27 
28 #include <atomic>
29 #include <chrono>
30 #include <thread>
31 
32 namespace isimud { namespace ISIMUD_VER_NAMESPACE { namespace exchanges { namespace FIX { namespace common {
33 
34 /// An implementation of the connectivity policy for the FIX protocol.
35 template<class LogonT>
37 public:
38  using logon_args_t=LogonT;
39  using endpoint_t=std::pair<boost::asio::ip::address, unsigned short>;
40  struct gateways_t {
41  const endpoint_t primary_gateway;
42 
43  explicit gateways_t(endpoint_t const &primary) noexcept(true)
45  }
46  gateways_t(gateways_t const &gws) noexcept(true)
48  }
49  };
50  enum : unsigned {
51  max_attempts=1
52  };
53  static inline constexpr std::chrono::seconds min_timeout{5};
55  const logon_args_t logon_args{};
57 
58  explicit connectivity_policy(gateways_t const &gws) noexcept(true);
59 
60  template<class ConnectFn>
61  void operator()(ConnectFn const &cnx) const noexcept(false);
62 
63 private:
64  template<class ConnectFn> static
65  boost::exception_ptr connection_failed(ConnectFn const &cnx, endpoint_t const &endpoint) noexcept(true);
66 };
67 
68 /// Generate heartbeats from the containing simulator.
69 /**
70  The simulator generates heartbeats to which the client responds.
71 */
72 template<class MsgT>
73 class server_hb_t : public exchanges::common::server_hb_t<MsgT, 5, 1> {
74 public:
75  using base_t=exchanges::common::server_hb_t<MsgT, 5, 1>;
76 
77  template<class ClientCxn>
78  explicit server_hb_t(ClientCxn &cxn);
79 };
80 
81 } } } } }
82 
84 
85 #endif