1 #ifndef libjmmcg_isimud_exchanges_FIX_common_connectivity_policy_hpp
2 #define libjmmcg_isimud_exchanges_FIX_common_connectivity_policy_hpp
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 #include <boost/asio/ip/address.hpp>
25 #include <boost/asio/ip/tcp.hpp>
26
27 #include <atomic>
28 #include <chrono>
29 #include <thread>
30
31 namespace isimud { namespace exchanges { namespace FIX { namespace common {
32
33
34 template<class LogonT>
35 class connectivity_policy {
36 public:
37 using logon_args_t=LogonT;
38 using endpoint_t=std::pair<boost::asio::ip::address, unsigned short>;
39 struct gateways_t {
40 const endpoint_t primary_gateway;
41
42 explicit gateways_t(endpoint_t const &primary) noexcept(true)
43 : primary_gateway(primary) {
44 }
45 gateways_t(gateways_t const &gws) noexcept(true)
46 : primary_gateway(gws.primary_gateway) {
47 }
48 };
49 enum : unsigned {
50 max_attempts=1
51 };
52 static constexpr std::chrono::seconds min_timeout{5};
53 const gateways_t gateways;
54 const logon_args_t logon_args{};
55 const logoff_args_t logoff_args{};
56
57 explicit connectivity_policy(gateways_t const &gws) noexcept(true);
58
59 template<class ConnectFn>
60 void operator()(ConnectFn const &cnx) const;
61
62 private:
63 template<class ConnectFn> static
64 std::exception_ptr connection_failed(ConnectFn const &cnx, endpoint_t const &endpoint);
65 };
66
67
68
69
70
71 template<class MsgT>
72 class server_hb_t {
73 public:
74
75 using hb_t=MsgT;
76
77 enum : unsigned {
78 max_missed_heartbeats=5
79 };
80 static constexpr std::chrono::seconds heartbeat_interval{1};
81
82 template<class ClientCxn>
83 explicit server_hb_t(ClientCxn &cxn);
84 ~server_hb_t() noexcept(true);
85
86 std::string to_string() const noexcept(false);
87
88 friend std::ostream &operator<<(std::ostream &os, server_hb_t const &s) noexcept(false) {
89 os<<s.to_string();
90 return os;
91 }
92
93 private:
94 std::atomic<bool> exit_;
95
96
97
98 std::exception_ptr ex=nullptr;
99
100
101
102 std::thread thr;
103
104 template<class ClientCxn>
105 void process(ClientCxn &cxn) noexcept(true);
106 };
107
108 } } } }
109
110 #include "connectivity_policy_impl.hpp"
111
112 #endif