This source file includes following definitions.
- connection_failed
- thr
- to_string
- process
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 namespace isimud { namespace exchanges { namespace FIX { namespace common {
22
23 template<class LogonT> inline
24 connectivity_policy<LogonT>::connectivity_policy(gateways_t const &gws) noexcept(true)
25 : gateways(gws) {}
26
27 template<class LogonT>
28 template<class ConnectFn> inline void
29 connectivity_policy<LogonT>::operator()(ConnectFn const &cnx) const {
30 std::exception_ptr cnx_failed(connection_failed(cnx, gateways.primary_gateway));
31 if (cnx_failed) {
32 std::rethrow_exception(cnx_failed);
33 }
34 }
35
36 template<class LogonT>
37 template<class ConnectFn> inline std::exception_ptr
38 connectivity_policy<LogonT>::connection_failed(ConnectFn const &cnx, endpoint_t const &endpoint) {
39 std::exception_ptr cnx_failed;
40 unsigned i=0;
41 for (; i<max_attempts; ++i) {
42 try {
43 cnx(boost::asio::ip::tcp::endpoint(endpoint.first, endpoint.second));
44 break;
45 } catch (std::exception const &e) {
46 cnx_failed=std::make_exception_ptr(e);
47 std::this_thread::sleep_for(min_timeout);
48 }
49 }
50 return (i>=max_attempts) ? cnx_failed : std::exception_ptr();
51 }
52
53 template<class LogonT>
54 constexpr std::chrono::seconds connectivity_policy<LogonT>::min_timeout;
55
56 template<class MsgT>
57 constexpr std::chrono::seconds server_hb_t<MsgT>::heartbeat_interval;
58
59 template<class MsgT>
60 template<class ClientCxn>
61 inline
62 server_hb_t<MsgT>::server_hb_t(ClientCxn &cxn)
63 : exit_(false), thr(&server_hb_t::template process<ClientCxn>, this, std::ref(cxn)) {
64 }
65
66 template<class MsgT>
67 inline
68 server_hb_t<MsgT>::~server_hb_t() noexcept(true) {
69 exit_=true;
70 if (thr.joinable()) {
71 thr.join();
72 }
73 }
74
75 template<class MsgT>
76 inline std::string
77 server_hb_t<MsgT>::to_string() const noexcept(false) {
78 std::ostringstream os;
79 os
80 <<"max missed heartbeats="<<max_missed_heartbeats
81 <<", heartbeat interval="<<heartbeat_interval.count()<<" sec"
82 <<", client processing-error: '"<<ex<<"'";
83 return os.str();
84 }
85
86 template<class MsgT>
87 template<class ClientCxn>
88 inline void
89 server_hb_t<MsgT>::process(ClientCxn &cxn) noexcept(true) {
90 try {
91 const hb_t hb{};
92 while (LIKELY(!static_cast<bool>(exit_))) {
93 std::this_thread::sleep_for(heartbeat_interval);
94 cxn.write(hb);
95 }
96 } catch (std::exception const &e) {
97 ex=std::make_exception_ptr(e);
98 }
99 }
100
101 } } } }