fix8  version 1.4.0
Open Source C++ FIX Framework
sessionwrapper.hpp
Go to the documentation of this file.
1 //-------------------------------------------------------------------------------------------------
2 /*
3 
4 Fix8 is released under the GNU LESSER GENERAL PUBLIC LICENSE Version 3.
5 
6 Fix8 Open Source FIX Engine.
7 Copyright (C) 2010-16 David L. Dight <fix@fix8.org>
8 
9 Fix8 is free software: you can redistribute it and / or modify it under the terms of the
10 GNU Lesser General Public License as published by the Free Software Foundation, either
11 version 3 of the License, or (at your option) any later version.
12 
13 Fix8 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
14 even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 
16 You should have received a copy of the GNU Lesser General Public License along with Fix8.
17 If not, see <http://www.gnu.org/licenses/>.
18 
19 BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO
20 THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE
21 COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY
22 KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO
24 THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE,
25 YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
26 
27 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT
28 HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED
29 ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
30 CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT
31 NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR
32 THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH
33 HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
34 
35 */
36 //-------------------------------------------------------------------------------------------------
37 #ifndef FIX8_SESSIONWRAPPER_HPP_
38 #define FIX8_SESSIONWRAPPER_HPP_
39 
40 #include <Poco/Net/ServerSocket.h>
41 #ifdef FIX8_HAVE_OPENSSL
42 #include <Poco/Net/SecureStreamSocket.h>
43 #include <Poco/Net/SecureServerSocket.h>
44 #include <Poco/SharedPtr.h>
45 #include <Poco/Net/PrivateKeyPassphraseHandler.h>
46 #include <Poco/Net/InvalidCertificateHandler.h>
47 #include <Poco/Net/SSLManager.h>
48 #endif
49 
50 //-------------------------------------------------------------------------------------------------
51 namespace FIX8 {
52 
53 //-------------------------------------------------------------------------------------------------
54 #ifdef FIX8_HAVE_OPENSSL
55 
58 class Fix8CertificateHandler: public Poco::Net::InvalidCertificateHandler
59 {
60 public:
62  Fix8CertificateHandler(bool handleErrorsOnServerSide) : Poco::Net::InvalidCertificateHandler(handleErrorsOnServerSide) {}
63 
65  virtual ~Fix8CertificateHandler() {}
66 
69  F8API void onInvalidCertificate(const void* pSender, Poco::Net::VerificationErrorArgs& errorCert);
70 };
71 
75 class Fix8PassPhraseHandler : public Poco::Net::PrivateKeyPassphraseHandler
76 {
77 public:
79  Fix8PassPhraseHandler(bool server) : Poco::Net::PrivateKeyPassphraseHandler(server) {}
80 
82  ~Fix8PassPhraseHandler() {}
83 
84  F8API void onPrivateKeyRequested(const void* pSender, std::string& privateKey);
85 };
86 
87 //-------------------------------------------------------------------------------------------------
88 struct PocoSslContext
89 {
90  PocoSslContext(const SslContext& ctx, bool client)
91  {
92  if (ctx._valid)
93  {
94  Poco::SharedPtr<Poco::Net::PrivateKeyPassphraseHandler> phrase_handler(new Fix8PassPhraseHandler(!client));
95  Poco::SharedPtr<Poco::Net::InvalidCertificateHandler> cert_handler(new Fix8CertificateHandler(!client));
96 #if POCO_VERSION >= 0x01040000
97  Poco::Net::initializeSSL();
98 #endif
99  _context = new Poco::Net::Context(
100  client ? Poco::Net::Context::CLIENT_USE : Poco::Net::Context::SERVER_USE,
101  ctx._private_key_file, ctx._certificate_file, ctx._ca_location,
102  static_cast<Poco::Net::Context::VerificationMode>(ctx._verification_mode), ctx._verification_depth,
103  ctx._load_default_cas, ctx._cipher_list);
104  if (client)
105  Poco::Net::SSLManager::instance().initializeClient(phrase_handler, cert_handler, _context);
106  else
107  Poco::Net::SSLManager::instance().initializeServer(phrase_handler, cert_handler, _context);
108  }
109  }
110 
111  ~PocoSslContext()
112  {
113 #if POCO_VERSION >= 0x01040000
114  if (_context)
115  Poco::Net::uninitializeSSL();
116 #endif
117  }
118 
119  Poco::Net::Context::Ptr _context;
120  bool is_secure() const { return _context.get() != 0; }
121 };
122 #endif
123 
124 //-------------------------------------------------------------------------------------------------
127 {
128  const F8MetaCntx& _ctx;
129  const XmlElement *_ses;
131  const std::string _session_name;
132 
134  SessionConfig (const F8MetaCntx& ctx, const std::string& conf_file, const std::string& session_name) :
135  Configuration(conf_file, true), _ctx(ctx), _ses(find_group(g_sessions, session_name)), _session_name(session_name)
136  {
137  if (!_ses)
138  throw InvalidConfiguration(session_name);
139 
140  _loginParameters =
141  {
142  get_retry_interval(_ses), get_retry_count(_ses),
146  get_no_chksum_flag(_ses), get_permissive_mode_flag(_ses), false,
148  get_tcp_recvbuf_sz(_ses),
151  };
152 
153  const unsigned ts(get_tabsize(_ses));
154  if (ts != defaults::tabsize) // only set if not default
156  }
157 
159  virtual ~SessionConfig () {}
160 
163  const XmlElement *get_session_element() const { return _ses; }
164 };
165 
166 //-------------------------------------------------------------------------------------------------
169 {
170 public:
171  ClientSessionBase(const F8MetaCntx& ctx, const std::string& conf_file, const std::string& session_name)
172  : SessionConfig(ctx, conf_file, session_name) {}
173  // using SessionConfig::SessionConfig;
174 
177  virtual bool has_given_up() const { return false; }
178 
180  virtual ~ClientSessionBase () {}
181 
184  virtual Session *session_ptr() = 0;
185 
191  virtual void start(bool wait, unsigned send_seqnum=0, unsigned recv_seqnum=0, const f8String davi=f8String()) = 0;
192 };
193 
194 //-------------------------------------------------------------------------------------------------
196 
197 template<typename T>
199 {
200 protected:
203  const SessionID _id;
207  Poco::Net::StreamSocket *_sock = nullptr;
208  Poco::Net::SocketAddress _addr;
209  ClientConnection *_cc = nullptr;
210 #ifdef FIX8_HAVE_OPENSSL
211  PocoSslContext _ssl;
212 #endif
213 
214 public:
216  ClientSession (const F8MetaCntx& ctx, const std::string& conf_file,
217  const std::string& session_name, bool init_con_later=false) :
218  ClientSessionBase(ctx, conf_file, session_name),
220  _id(_ctx._beginStr, _sci, _tci),
221  _log(create_logger(_ses, session_log, &_id)),
222  _plog(create_logger(_ses, protocol_log, &_id)),
223  _persist(create_persister(_ses, nullptr, this->_loginParameters._reset_sequence_numbers)),
224  _session(new T(_ctx, _id, _persist, _log, _plog)),
225  _addr(get_address(_ses))
226 #ifdef FIX8_HAVE_OPENSSL
227  ,_ssl(get_ssl_context(_ses), true)
228 #endif
229  {
230  if (!init_con_later)
231  {
232 #ifdef FIX8_HAVE_OPENSSL
233  bool secured(_ssl.is_secure());
234  _sock = secured
235  ? new Poco::Net::SecureStreamSocket(_ssl._context)
236  : new Poco::Net::StreamSocket;
237 #else
238  bool secured(false);
239  _sock = new Poco::Net::StreamSocket;
240 #endif
241  _cc = new ClientConnection(_sock, _addr, *_session, this->_loginParameters._hb_int, get_process_model(_ses), true, secured);
242  }
243 
244  _session->set_login_parameters(this->_loginParameters);
245  _session->set_session_config(this);
246  }
247 
249  virtual ~ClientSession ()
250  {
251  delete _persist;
252  _persist = nullptr;
253  delete _session;
254  _session = nullptr;
255  delete _log;
256  _log = nullptr;
257  delete _plog;
258  _plog = nullptr;
259  }
260 
263  T *session_ptr() { return _session; }
264 
270  virtual void start(bool wait, unsigned send_seqnum=0, unsigned recv_seqnum=0, const f8String davi=f8String())
271  { _session->start(_cc, wait, send_seqnum, recv_seqnum, davi); }
272 
274  using ClientSession_ptr = std::unique_ptr<ClientSession<T>>;
275 
276  using session_type = T;
277 };
278 
279 //-------------------------------------------------------------------------------------------------
281 
282 template<typename T>
284 {
286  unsigned _send_seqnum = 0, _recv_seqnum = 0, _current = 0, _attempts = 0;
288  std::vector<Server> _servers;
289  const size_t _failover_cnt;
291 
292 public:
294  ReliableClientSession (const F8MetaCntx& ctx, const std::string& conf_file, const std::string& session_name)
295  : ClientSession<T>(ctx, conf_file, session_name, true), _thread(std::ref(*this)),
296  _failover_cnt(this->get_addresses(this->_ses, _servers))
297  {
298  _giving_up = false;
299  this->_loginParameters._reliable = true;
300  }
301 
302  enum { no_servers_configured=0xffff };
303 
306  bool has_given_up() const { return _giving_up; }
307 
310  {
311  _thread.request_stop();
312  _thread.join();
313  }
314 
320  virtual void start(bool wait, unsigned send_seqnum=0, unsigned recv_seqnum=0, const f8String davi=f8String())
321  {
322  _send_seqnum = send_seqnum;
323  _recv_seqnum = recv_seqnum;
324  if (!wait)
325  _thread.start();
326  else
327  (*this)();
328  }
329 
332  size_t get_attempts_cnt() const { return _attempts; }
333 
336  size_t get_server_cnt() const { return _failover_cnt; }
337 
341  const Server *get_server(unsigned idx=no_servers_configured) const
342  {
343  return idx == no_servers_configured && _failover_cnt ? &_servers[_current]
344  : idx < _failover_cnt ? &_servers[idx] : nullptr;
345  }
346 
350  {
351  while(!_cancellation_token)
352  {
353  ++_attempts;
354 
355  bool excepted(_failover_cnt == 0);
356  try
357  {
358  if (_failover_cnt)
359  {
360  std::ostringstream ostr;
361  ostr << "Trying " << _servers[_current]._hostname << '(' << (1 + _servers[_current]._retries) << "), "
362  << _attempts << " attempts so far";
363  this->_session->log(ostr.str(), Logger::Warn);
364  this->_loginParameters._reset_sequence_numbers = _servers[_current]._reset_sequence_numbers; // permit override
365  }
366 
367  //std::cout << "operator()():try" << std::endl;
368 #ifdef FIX8_HAVE_OPENSSL
369  bool secured(this->_ssl.is_secure());
370  this->_sock = secured
371  ? new Poco::Net::SecureStreamSocket(this->_ssl._context)
372  : new Poco::Net::StreamSocket;
373 #else
374  bool secured(false);
375  this->_sock = new Poco::Net::StreamSocket;
376 #endif
377  this->_cc = new ClientConnection(this->_sock, _failover_cnt ? this->_addr = _servers[_current]._addr : this->_addr,
378  *this->_session, this->_loginParameters._hb_int, this->get_process_model(this->_ses), true, secured);
379  this->_session->set_login_parameters(this->_loginParameters);
380  this->_session->set_session_config(this);
381  this->_session->start(this->_cc, true, _send_seqnum, _recv_seqnum, this->_loginParameters._davi());
382  _send_seqnum = _recv_seqnum = 0; // only set seqnums for the first time round
383  }
384  catch (Poco::TimeoutException& e)
385  {
386  this->_session->log(e.what(), Logger::Error);
387  excepted = true;
388  }
389  catch (f8Exception& e)
390  {
391  // std::cerr << e.what() << std::endl;
392  this->_session->log(e.what(), Logger::Error);
393  excepted = true;
394  }
395  catch (Poco::Net::InvalidAddressException& e)
396  {
397  this->_session->log(e.what(), Logger::Error);
398  excepted = true;
399  }
400 #if POCO_VERSION >= 0x01040000
401  catch (Poco::Net::InvalidSocketException& e)
402  {
403  this->_session->log(e.what(), Logger::Error);
404  excepted = true;
405  }
406 #endif
407  catch (Poco::Net::ServiceNotFoundException& e)
408  {
409  //std::cerr << e.what() << std::endl;
410  this->_session->log(e.what(), Logger::Error);
411  excepted = true;
412  }
413  catch (Poco::Net::ConnectionRefusedException& e)
414  {
415  this->_session->log(e.what(), Logger::Error);
416  excepted = true;
417  }
418  catch (Poco::Net::DNSException& e)
419  {
420  this->_session->log(e.what(), Logger::Error);
421  excepted = true;
422  }
423  catch (Poco::Net::InterfaceNotFoundException& e)
424  {
425  this->_session->log(e.what(), Logger::Error);
426  excepted = true;
427  }
428  catch (Poco::Net::NetException& e) // catch all other NetExceptions
429  {
430  this->_session->log(e.what(), Logger::Error);
431  excepted = true;
432  }
433  catch (std::exception& e)
434  {
435  //std::cout << "process:: std::exception" << endl;
436  this->_session->log(e.what(), Logger::Error);
437  excepted = true;
438  }
439 
440  //std::cout << "operator()():out of try" << std::endl;
441  try
442  {
443  this->_session->stop();
444  }
445  catch (f8Exception& e)
446  {
447  this->_session->log(e.what(), Logger::Error);
448  }
449  catch (Poco::Net::NetException& e)
450  {
451  this->_session->log(e.what(), Logger::Error);
452  }
453  catch (std::exception& e)
454  {
455  this->_session->log(e.what(), Logger::Error);
456  }
457 
458  delete this->_cc;
459  this->_cc = nullptr;
460  delete this->_sock;
461  this->_sock = nullptr;
462 
463  if (!excepted || (_failover_cnt == 0
464  && this->_loginParameters._login_retries > 0 && _attempts > this->_loginParameters._login_retries))
465  break;
466 
467  if (_failover_cnt)
468  {
469  ++_servers[_current]._retries;
470 
471  while (!_cancellation_token) // FIXME possible endless loop condition
472  {
473  if (_servers[_current]._max_retries && _servers[_current]._retries < _servers[_current]._max_retries)
474  break;
475  _servers[_current]._retries = 0; // reset for next time
476  ++_current %= _failover_cnt;
477  }
478  }
479 
481  }
482 
483  _giving_up = true;
484 
485  return 0;
486  }
487 
489 
491  using ReliableClientSession_ptr = std::unique_ptr<ReliableClientSession<T>>;
492 };
493 
494 //-------------------------------------------------------------------------------------------------
495 class SessionInstanceBase;
496 template<typename T> class SessionInstance;
497 
500 {
501 protected:
502  Poco::Net::ServerSocket *_server_sock = nullptr;
503 
504 public:
506  ServerSessionBase(const F8MetaCntx& ctx, const std::string& conf_file, const std::string& session_name)
507  : SessionConfig(ctx, conf_file, session_name) {}
508  //using SessionConfig::SessionConfig; // not supported in all C++11 compilers
509 
512  {
513  delete _server_sock;
514  _server_sock = nullptr;
515  }
516 
520 
524  bool poll(const Poco::Timespan& span=Poco::Timespan(250000)) const
525  { return _server_sock->poll(span, Poco::Net::Socket::SELECT_READ); }
526 
530  Poco::Net::StreamSocket accept(Poco::Net::SocketAddress& claddr)
531  { return _server_sock->acceptConnection(claddr); }
532 
535  virtual bool is_secure() const { return false; }
536 
537  friend class ServerManager;
538 };
539 
540 //-------------------------------------------------------------------------------------------------
541 // Server wrapper.
543 template<typename T>
545 {
546  Poco::Net::SocketAddress _addr;
547 #ifdef FIX8_HAVE_OPENSSL
548  PocoSslContext _ssl;
549 #endif
550 
551 public:
553  ServerSession (const F8MetaCntx& ctx, const std::string& conf_file, const std::string& session_name) :
554  ServerSessionBase(ctx, conf_file, session_name),
555  _addr(get_address(_ses))
556 #ifdef FIX8_HAVE_OPENSSL
557  ,_ssl(get_ssl_context(_ses), false)
558 #endif
559  {
560  _server_sock =
561 #ifdef FIX8_HAVE_OPENSSL
562  _ssl.is_secure() ? new Poco::Net::SecureServerSocket(_addr, 64, _ssl._context) :
563 #endif
564  new Poco::Net::ServerSocket(_addr);
565 
570  }
571 
573  virtual ~ServerSession () {}
574 
578 
580  using ServerSession_ptr = std::unique_ptr<ServerSession<T>>;
581 
582  virtual bool is_secure() const
583 #ifdef FIX8_HAVE_OPENSSL
584  { return _ssl.is_secure(); }
585 #else
586  { return false; }
587 #endif
588 };
589 
590 //-------------------------------------------------------------------------------------------------
593 {
594 public:
596  SessionInstanceBase () = default;
597 
599  virtual ~SessionInstanceBase () {}
600 
603  virtual Session *session_ptr() = 0;
604 
609  virtual void start(bool wait, unsigned send_seqnum=0, unsigned recv_seqnum=0) {}
610 
612  virtual void stop() {}
613 };
614 
615 //-------------------------------------------------------------------------------------------------
617 
618 template<typename T>
619 class SessionInstance : public SessionInstanceBase
620 {
622  Poco::Net::SocketAddress _claddr;
623  Poco::Net::StreamSocket *_sock;
626 
627 public:
630  _sf(sf),
631  _sock(new Poco::Net::StreamSocket(_sf.accept(_claddr))),
632  _session(new T(_sf._ctx, _sf.get_sender_comp_id(_sf._ses))),
633  _psc(new ServerConnection(_sock, _claddr, *_session, _sf.get_heartbeat_interval(_sf._ses), _sf.get_process_model(_sf._ses),
634  _sf.get_tcp_nodelay(_sf._ses), _sf.get_tcp_reuseaddr(_sf._ses), _sf.get_tcp_linger(_sf._ses),
635  _sf.get_tcp_keepalive(_sf._ses),
636 #ifdef FIX8_HAVE_OPENSSL
637  _sf.is_secure()
638 #else
639  false
640 #endif
641  ))
642  {
643  _session->set_login_parameters(_sf._loginParameters);
644  _session->set_session_config(&_sf);
645  }
646 
648  virtual ~SessionInstance ()
649  {
650  try
651  {
652  if (_psc != nullptr)
653  {
654  _psc->stop();
655  delete _psc;
656  _psc = nullptr;
657  }
658  }
659  catch (f8Exception& e)
660  {
661  this->_session->log(e.what(), Logger::Error);
662  }
663  catch (Poco::Exception& e)
664  {
665  this->_session->log(e.what(), Logger::Error);
666  }
667  catch (std::exception& e)
668  {
669  this->_session->log(e.what(), Logger::Error);
670  }
671 
672  try
673  {
674  delete _session;
675  _session = nullptr;
676  }
677  catch (f8Exception& e)
678  {
679  this->_session->log(e.what(), Logger::Error);
680  }
681  catch (Poco::Exception& e)
682  {
683  this->_session->log(e.what(), Logger::Error);
684  }
685  catch (std::exception& e)
686  {
687  this->_session->log(e.what(), Logger::Error);
688  }
689 
690  try
691  {
692  delete _sock;
693  _sock = nullptr;
694  }
695  catch (f8Exception& e)
696  {
697  this->_session->log(e.what(), Logger::Error);
698  }
699  catch (Poco::Exception& e)
700  {
701  this->_session->log(e.what(), Logger::Error);
702  }
703  catch (std::exception& e)
704  {
705  this->_session->log(e.what(), Logger::Error);
706  }
707  }
708 
711  virtual T *session_ptr() override { return _session; }
712 
717  virtual void start(bool wait, unsigned send_seqnum=0, unsigned recv_seqnum=0) override
718  { _session->start(_psc, wait, send_seqnum, recv_seqnum); }
719 
721  virtual void stop() override { _session->stop(); }
722 
724  using SessionInstance_ptr = std::unique_ptr<SessionInstance<T>>;
725 };
726 
727 template<typename T>
729 
730 } // FIX8
731 
732 #endif // FIX8_SESSIONWRAPPER_HPP_
std::vector< Server > _servers
Client (initiator) specialisation of Connection.
Definition: connection.hpp:693
bool get_permissive_mode_flag(const XmlElement *from, const bool def=false) const
LoginParameters _loginParameters
ServerSession< T > & _sf
const SessionID _id
virtual bool is_secure() const
ServerSessionBase(const F8MetaCntx &ctx, const std::string &conf_file, const std::string &session_name)
Ctor. Prepares session for receiving inbbound connections (acceptor).
f8_thread delegated async logging class
Definition: logger.hpp:153
bool get_reset_sequence_number_flag(const XmlElement *from, const bool def=false) const
unsigned get_tcp_sendbuf_sz(const XmlElement *from, const unsigned def=0) const
Multi Server Manager.
virtual ~ClientSessionBase()
Dtor.
virtual bool is_secure() const
std::unique_ptr< SessionInstance< T >> SessionInstance_ptr
Convenient scoped pointer for your session instance.
Fix8 Base Session. User sessions are derived from this class.
Definition: session.hpp:394
Base Server session instance.
static void set_recv_buf_sz(const unsigned sz, Poco::Net::Socket *sock)
Definition: connection.hpp:633
Server session instance.
const Server * get_server(unsigned idx=no_servers_configured) const
unsigned _login_retry_interval
Definition: session.hpp:353
bool get_silent_disconnect(const XmlElement *from, const bool def=false) const
virtual void stop()
Stop the session. Cleanup.
Base (ABC) Persister class.
Definition: persist.hpp:55
virtual void start(bool wait, unsigned send_seqnum=0, unsigned recv_seqnum=0)
default_appl_ver_id _davi
Definition: session.hpp:357
F8API void stop()
Stop the reader and writer threads.
Definition: connection.cpp:322
Class to hold server settings for failoverable sessions.
bool poll(const Poco::Timespan &span=Poco::Timespan(250000)) const
f8_thread_cancellation_token _cancellation_token
f8_thread_cancellation_token & cancellation_token()
F8API Poco::Net::SocketAddress get_address(const XmlElement *from) const
Server (acceptor) specialisation of Connection.
Definition: connection.hpp:722
unsigned get_tcp_recvbuf_sz(const XmlElement *from, const unsigned def=0) const
unsigned get_retry_interval(const XmlElement *from, const unsigned def=defaults::retry_interval) const
Client wrapper.
Poco::Net::ServerSocket * _server_sock
virtual ~SessionConfig()
Dtor.
Thread wrapper. Ctor provides T instance and specifies ptr to member to call or defaults to operator(...
Definition: thread.hpp:245
Quickfix style sessionid.
Definition: session.hpp:46
virtual ~SessionInstance()
Dtor.
ServerConnection * _psc
SessionInstance(ServerSession< T > &sf)
Ctor. Prepares session instance with inbound connection.
Thread cancellation token.
Definition: thread.hpp:206
virtual Session * session_ptr()=0
F8API Persister * create_persister(const XmlElement *from, const SessionID *sid=nullptr, bool flag=false) const
F8API size_t get_addresses(const XmlElement *from, std::vector< Server > &target) const
virtual SessionInstanceBase * create_server_instance()
Base Client wrapper.
ClientSession(const F8MetaCntx &ctx, const std::string &conf_file, const std::string &session_name, bool init_con_later=false)
Ctor. Prepares session for connection as an initiator.
Poco::Net::StreamSocket * _sock
static void set_send_buf_sz(const unsigned sz, Poco::Net::Socket *sock)
Definition: connection.hpp:644
Poco::Net::StreamSocket * _sock
virtual ~ReliableClientSession()
Dtor.
const F8MetaCntx & ctx()
Compiler generated metadata object, accessed through this function.
virtual int join(int timeoutInMs=0)
Definition: thread.hpp:126
Base exception class.
Definition: f8exception.hpp:49
A simple xml parser with Xpath style lookup.
Definition: xml.hpp:48
default_appl_ver_id get_default_appl_ver_id(const XmlElement *from) const
#define F8API
Definition: f8dll.h:60
unsigned get_heartbeat_interval(const XmlElement *from, const unsigned def=defaults::hb_interval) const
SessionConfig(const F8MetaCntx &ctx, const std::string &conf_file, const std::string &session_name)
Ctor. Loads configuration, obtains session details, sets up logfile flags.
int hypersleep< h_milliseconds >(unsigned amt)
Definition: hypersleep.hpp:105
unsigned get_connect_timeout(const XmlElement *from, const unsigned def=defaults::connect_timeout) const
F8API void start()
Start the reader and writer threads.
Definition: connection.cpp:315
unsigned get_tabsize(const XmlElement *from, const unsigned def=defaults::tabsize) const
virtual void start(bool wait, unsigned send_seqnum=0, unsigned recv_seqnum=0) override
std::unique_ptr< ServerSession< T >> ServerSession_ptr
Convenient scoped pointer for your session.
Base Server Session.
virtual T * session_ptr() override
virtual void stop() override
Stop the session. Cleanup.
virtual void start(bool wait, unsigned send_seqnum=0, unsigned recv_seqnum=0, const f8String davi=f8String())=0
virtual ~ServerSessionBase()
Dtor.
Base session wrapper.
void request_stop()
Definition: thread.hpp:293
std::atomic< T > f8_atomic
Definition: thread.hpp:55
Class to encapsulate a Fix8 configuration.
Poco::Net::StreamSocket accept(Poco::Net::SocketAddress &claddr)
ClientConnection * _cc
static void set_tabsize(unsigned tabsize)
Definition: message.hpp:990
const F8MetaCntx & _ctx
virtual ~SessionInstanceBase()
Dtor.
unsigned _login_retries
Definition: session.hpp:353
const XmlElement * get_session_element() const
An invalid configuration parameter was passed.
const std::string _session_name
unsigned get_retry_count(const XmlElement *from, const int def=defaults::login_retries) const
sender_comp_id get_sender_comp_id(const XmlElement *from) const
virtual bool has_given_up() const
ClientSessionBase(const F8MetaCntx &ctx, const std::string &conf_file, const std::string &session_name)
ServerSession(const F8MetaCntx &ctx, const std::string &conf_file, const std::string &session_name)
Ctor. Prepares session for receiving inbbound connections (acceptor).
const XmlElement * _ses
virtual SessionInstanceBase * create_server_instance()=0
virtual void start(bool wait, unsigned send_seqnum=0, unsigned recv_seqnum=0, const f8String davi=f8String())
F8API Schedule create_login_schedule(const XmlElement *from) const
bool get_enforce_compids_flag(const XmlElement *from, const bool def=true) const
f8_thread< ReliableClientSession< T > > _thread
ReliableClientSession(const F8MetaCntx &ctx, const std::string &conf_file, const std::string &session_name)
Ctor. Prepares session for connection as an initiator.
F8API Clients create_clients(const XmlElement *from) const
Poco::Net::SocketAddress _addr
const char * what() const
Definition: f8exception.hpp:85
std::unique_ptr< ReliableClientSession< T >> ReliableClientSession_ptr
Convenient scoped pointer for your session.
virtual ~ServerSession()
Dtor.
F8API Logger * create_logger(const XmlElement *from, const Logtype ltype, const SessionID *sid=nullptr) const
Poco::Net::SocketAddress _addr
target_comp_id get_target_comp_id(const XmlElement *from) const
virtual ~ClientSession()
Dtor.
Static metadata context class - one per FIX xml schema.
Definition: message.hpp:210
Poco::Net::SocketAddress _claddr
F8API ProcessModel get_process_model(const XmlElement *from) const
bool get_always_seqnum_assign(const XmlElement *from, const bool def=false) const
std::unique_ptr< ClientSession< T >> ClientSession_ptr
Convenient scoped pointer for your session.
std::string f8String
Definition: f8types.hpp:47
SessionInstanceBase()=default
Ctor. Prepares session instance with inbound connection.
Reliable Client wrapper. This client attempts to recover from disconnects and login rejects...
bool get_no_chksum_flag(const XmlElement *from, const bool def=false) const
virtual Session * session_ptr()=0
virtual void start(bool wait, unsigned send_seqnum=0, unsigned recv_seqnum=0, const f8String davi=f8String())
const XmlElement * find_group(group_types type, const std::string &tag) const