fix8  version 1.4.0
Open Source C++ FIX Framework
session.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_SESSION_HPP_
38 #define FIX8_SESSION_HPP_
39 
40 #include <Poco/Net/StreamSocket.h>
41 //-------------------------------------------------------------------------------------------------
42 namespace FIX8 {
43 
44 //-------------------------------------------------------------------------------------------------
46 class SessionID
47 {
48  static RegExp _sid;
49 
53 
55 
56 public:
61  SessionID(const f8String& beginString, const f8String& senderCompID, const f8String& targetCompID)
62  : _beginString(beginString), _senderCompID(senderCompID), _targetCompID(targetCompID) { make_id(); }
63 
68  SessionID(const begin_string& beginString, const sender_comp_id& senderCompID, const target_comp_id& targetCompID)
69  : _beginString(beginString), _senderCompID(senderCompID), _targetCompID(targetCompID) { make_id(); }
70 
73  SessionID(const f8String& from) { from_string(from); }
74 
77  SessionID(const SessionID& from) : _beginString(from._beginString), _senderCompID(from._senderCompID),
78  _targetCompID(from._targetCompID), _id(from._id) {}
79 
80  SessionID() {}
81 
83  virtual ~SessionID() {}
84 
86  F8API void make_id();
87 
91 
93  F8API void from_string(const f8String& from);
94 
97  const begin_string& get_beginString() const { return _beginString; }
98 
101  const sender_comp_id& get_senderCompID() const { return _senderCompID; }
102 
105  const target_comp_id& get_targetCompID() const { return _targetCompID; }
106 
109  const f8String& get_id() const { return _id; }
110 
114  bool same_sender_comp_id(const target_comp_id& targetCompID) const { return targetCompID() == _senderCompID(); }
115 
119  bool same_target_comp_id(const sender_comp_id& senderCompID) const { return senderCompID() == _targetCompID(); }
120 
124  bool same_side_target_comp_id(const target_comp_id& targetCompID) const { return targetCompID() == _targetCompID(); }
125 
129  bool same_side_sender_comp_id(const sender_comp_id& senderCompID) const { return senderCompID() == _senderCompID(); }
130 
134  bool operator==(const SessionID& that)
135  {
136  return this != &that ? that._senderCompID() == _senderCompID() && that._targetCompID() == _targetCompID() : true;
137  }
138 
142  bool operator!=(const SessionID& that)
143  {
144  return this != &that ? that._senderCompID() != _senderCompID() && that._targetCompID() != _targetCompID() : false;
145  }
146 
151  friend std::ostream& operator<<(std::ostream& os, const SessionID& what) { return os << what._id; }
152 };
153 
154 //-------------------------------------------------------------------------------------------------
156 namespace States
157 {
159  {
164  };
165 
169  static inline bool is_live(SessionStates ss)
170  { return ss != st_none && ss != st_session_terminated; }
171 
175  static inline bool is_established(SessionStates ss)
176  { return ss != st_wait_for_logon && ss != st_not_logged_in && ss != st_logon_sent && is_live(ss); }
177 }
178 
179 //-------------------------------------------------------------------------------------------------
181 using Client = std::tuple<f8String, Poco::Net::IPAddress>; // name, ip
182 using Clients = std::unordered_map<f8String, Client>; // tci : name, ip
183 
184 //-------------------------------------------------------------------------------------------------
185 namespace defaults
186 {
187  enum
188  {
196  };
197 }
198 
199 //-------------------------------------------------------------------------------------------------
200 struct Schedule
201 {
205 
206  Schedule() : _start(Tickval::errorticks()), _end(Tickval::errorticks()), _utc_offset(),
207  _start_day(-1), _end_day(-1) {}
208 
209  Schedule(Tickval start, Tickval end, Tickval duration=Tickval(), int utc_offset=0,
210  int start_day=-1, int end_day=-1) :
211  _start(start), _end(end), _duration(duration),
212  _utc_offset(utc_offset), _start_day(start_day), _end_day(end_day),
213  _toffset(static_cast<Tickval::ticks>(_utc_offset) * Tickval::minute)
214  {
215  }
216 
217  Schedule(const Schedule& from) :
218  _start(from._start), _end(from._end), _duration(from._duration),
219  _utc_offset(from._utc_offset), _start_day(from._start_day), _end_day(from._end_day),
220  _toffset(from._toffset)
221  {
222  }
223 
225  {
226  if (this != &that)
227  {
228  _start = that._start;
229  _end = that._end;
230  _duration = that._duration;
231  _utc_offset = that._utc_offset;
232  _start_day = that._start_day;
233  _end_day = that._end_day;
234  _toffset = that._toffset;
235  }
236 
237  return *this;
238  }
239 
242  bool is_valid() const { return !_start.is_errorval(); }
243 
247  bool test(bool prev=false) const
248  {
249  Tickval now(true);
250  now.adjust(_toffset); // adjust for local utc offset
251  const Tickval today(now.get_ticks() - (now.get_ticks() % Tickval::day));
252  bool active(prev);
253 
254  if (_start_day < 0) // start/end day not specified; daily only
255  {
256  //cout >> now << ' ' >> (today + _start) << ' ' >> (today + _end) << endl;
257 
258  if (now.in_range(today + _start, today + _end))
259  {
260  if (!prev)
261  active = true;
262  }
263  else if (prev)
264  active = false;
265  }
266  else
267  {
268  const tm result(now.get_tm());
269 
270  //cout >> now << ' ' >> (today + _start) << ' ' >> (today + _end) << ' ' << result.tm_wday << endl;
271 
272  if (!prev)
273  {
274  if ( ((_start_day > _end_day && (result.tm_wday >= _start_day || result.tm_wday <= _end_day))
275  || (_start_day < _end_day && result.tm_wday >= _start_day && result.tm_wday <= _end_day))
276  && now.in_range(today + _start, today + _end))
277  active = true;
278  }
279  else if ( ((_start_day > _end_day && (result.tm_wday < _start_day && result.tm_wday > _end_day))
280  || (_start_day < _end_day && result.tm_wday >= _end_day))
281  && now > today + _end)
282  active = false;
283  }
284 
285  return active;
286  }
287 
292  friend std::ostream& operator<<(std::ostream& os, const Schedule& what)
293  {
294  os << "start:" >> what._start << " end:" >> what._end << " duration:" << what._duration
295  << " utc_offset:" << what._utc_offset << " start day:" << what._start_day << " end day:" << what._end_day;
296  return os;
297  }
298 };
299 
300 //-------------------------------------------------------------------------------------------------
302 {
303  LoginParameters() = default;
304 
305  LoginParameters(unsigned login_retry_interval, unsigned login_retries,
306  const default_appl_ver_id& davi, unsigned connect_timeout, bool reset_seqnum=false,
307  bool always_seqnum_assign=false, bool silent_disconnect=false, bool no_chksum_flag=false,
308  bool permissive_mode_flag=false, bool reliable=false, bool enforce_compids=true,
309  unsigned recv_buf_sz=0, unsigned send_buf_sz=0, unsigned hb_int=defaults::hb_interval,
310  const Schedule& sch=Schedule(), const Clients& clients=Clients(), const f8String& pem_path=f8String()) :
311  _login_retry_interval(login_retry_interval), _login_retries(login_retries), _connect_timeout(connect_timeout),
312  _reset_sequence_numbers(reset_seqnum), _always_seqnum_assign(always_seqnum_assign),
313  _silent_disconnect(silent_disconnect), _no_chksum_flag(no_chksum_flag),
314  _permissive_mode_flag(permissive_mode_flag), _reliable(reliable), _enforce_compids(enforce_compids),
315  _davi(davi), _recv_buf_sz(recv_buf_sz), _send_buf_sz(send_buf_sz), _hb_int(hb_int),
316  _login_schedule(sch), _clients(clients), _pem_path(pem_path) {}
317 
326  {}
327 
329  {
330  if (this != &that)
331  {
340  _reliable = that._reliable;
342  _davi = that._davi;
343  _recv_buf_sz = that._recv_buf_sz;
344  _send_buf_sz = that._send_buf_sz;
345  _hb_int = that._hb_int;
347  _clients = that._clients;
348  _pem_path = that._pem_path;
349  }
350  return *this;
351  }
352 
362 };
363 
364 //-------------------------------------------------------------------------------------------------
366 {
369  const std::string _reject_text;
370 
371  Session_Schedule(Schedule& sch, int reject_reason=0, const std::string& reject_text="Business messages are not accepted now.") :
372  _sch(sch), _reject_reason(reject_reason), _reject_text(reject_text)
373  {
374  }
375 
380  friend std::ostream& operator<<(std::ostream& os, const Session_Schedule& what)
381  {
382  os << what._sch << " reject_reason:" << what._reject_reason << " reject_text:" << what._reject_text;
383  return os;
384  }
385 };
386 
387 //-------------------------------------------------------------------------------------------------
388 class Persister;
389 class Logger;
390 class Connection;
391 
392 //-------------------------------------------------------------------------------------------------
394 class Session
395 {
399 
400 public:
402 
404 
405 protected:
411  const F8MetaCntx& _ctx;
412  sender_comp_id _sci; // used by acceptor
417 
419 
423 
426  std::string _batchmsgs_buffer;
428 
430  F8API static const std::vector<f8String> _state_names;
431 
433  F8API bool heartbeat_service();
434 
436  F8API bool activation_service();
437 
442  F8API virtual bool handle_logon(const unsigned seqnum, const Message *msg);
443 
448  F8API virtual Message *generate_logon(const unsigned heartbeat_interval, const f8String davi=f8String());
449 
454  F8API virtual bool handle_logout(const unsigned seqnum, const Message *msg);
455 
460  F8API virtual bool handle_heartbeat(const unsigned seqnum, const Message *msg);
461 
466  F8API virtual bool handle_resend_request(const unsigned seqnum, const Message *msg);
467 
472  F8API virtual bool handle_sequence_reset(const unsigned seqnum, const Message *msg);
473 
478  F8API virtual bool handle_test_request(const unsigned seqnum, const Message *msg);
479 
484  virtual bool handle_reject(const unsigned seqnum, const Message *msg) { return false; }
485 
490  virtual bool handle_admin(const unsigned seqnum, const Message *msg) { return true; }
491 
497  F8API virtual bool handle_outbound_reject(const unsigned seqnum, const Message *msg, const char *errstr);
498 
505  virtual bool handle_application(const unsigned seqnum, const Message *&msg) = 0;
506 
510  virtual void state_change(const States::SessionStates before, const States::SessionStates after) {}
511 
514  virtual void modify_outbound(Message *msg) {}
515 
520  virtual bool authenticate(SessionID& id, const Message *msg) { return true; }
521 
523  F8API virtual void recover_seqnums();
524 
529  {
530  const BaseMsgEntry *bme(_ctx._bme.find_ptr(msg_type.c_str()));
531  if (!bme)
533  return bme->_create._do(true);
534  }
535 
536 #if (FIX8_THREAD_SYSTEM == FIX8_THREAD_PTHREAD) && !defined _MSC_VER && defined _GNU_SOURCE && defined __linux__
537 
541  static f8String get_thread_policy_string(thread_id_t id);
542 #endif
543 
546  void set_scheduler(int priority);
547 
550  void set_affinity(int core_id);
551 
552 public:
559  F8API Session(const F8MetaCntx& ctx, const SessionID& sid, Persister *persist=nullptr,
560  Logger *logger=nullptr, Logger *plogger=nullptr);
561 
568  F8API Session(const F8MetaCntx& ctx, const sender_comp_id& sci=sender_comp_id(), Persister *persist=nullptr,
569  Logger *logger=nullptr, Logger *plogger=nullptr);
570 
572  F8API virtual ~Session();
573 
581  F8API int start(Connection *connection, bool wait=true, const unsigned send_seqnum=0,
582  const unsigned recv_seqnum=0, const f8String davi=f8String());
583 
586  void clear_connection(const Connection *connection)
587  {
588  if (connection == _connection)
589  _connection = nullptr;
590  }
591 
595  F8API virtual bool process(const f8String& from);
596 
599  {
600  const unsigned _begin, _end, _interrupted_seqnum;
601  unsigned _last;
603 
604  RetransmissionContext(const unsigned begin, const unsigned end, const unsigned interrupted_seqnum)
605  : _begin(begin), _end(end), _interrupted_seqnum(interrupted_seqnum), _last(), _no_more_records() {}
606 
607  friend std::ostream& operator<<(std::ostream& os, const RetransmissionContext& what)
608  {
609  os << "end:" << what._end << " last:" << what._last << " interrupted seqnum:"
610  << what._interrupted_seqnum << " no_more_records:" << std::boolalpha << what._no_more_records;
611  return os;
612  }
613  };
614 
615  using SequencePair = std::pair<const unsigned, const f8String>;
616 
621  F8API virtual bool retrans_callback(const SequencePair& with, RetransmissionContext& rctx);
622 
629  F8API virtual bool send(Message *msg, bool destroy=true, const unsigned custom_seqnum=0, const bool no_increment=false);
630 
638  F8API virtual bool send(Message& msg, const unsigned custom_seqnum=0, const bool no_increment=false);
639 
645  F8API virtual size_t send_batch(const std::vector<Message *>& msgs, bool destroy=true);
646 
650  F8API bool send_process(Message *msg);
651 
655  F8API virtual int modify_header(MessageBase *msg);
656 
659 
661  F8API void stop();
662 
666 
670 
673  const F8MetaCntx& get_ctx() const { return _ctx; }
674 
678  bool is_loggable(Logger::Level level) const { return _logger ? _logger->is_loggable(level) : false; }
679 
686  bool enqueue(const std::string& what, Logger::Level lev, const char *fl=nullptr, unsigned value=0) const
687  { return _logger ? _logger->enqueue(what, lev, fl, value) : false; }
688 
695  bool log(const std::string& what, Logger::Level lev, const char *fl=nullptr, unsigned value=0) const
696  { return _logger ? _logger->send(what, lev, fl, value) : false; }
697 
703  bool plog(const std::string& what, Logger::Level lev, const unsigned direction=0) const
704  { return _plogger ? _plogger->send(what, lev, nullptr, direction) : false; }
705 
708  const Tickval& get_last_received() const { return _last_received; }
709 
712  const Tickval& get_last_sent() const { return _last_sent; }
713 
715  void update_sent() { _last_sent.now(); }
716 
718  void update_received() { _last_received.now(); }
719 
724  F8API void compid_check(const unsigned seqnum, const Message *msg, const SessionID& id) const;
725 
730  F8API bool sequence_check(const unsigned seqnum, const Message *msg);
731 
736  virtual bool activation_check(const unsigned seqnum, const Message *msg) { return _active; }
737 
742  F8API bool enforce(const unsigned seqnum, const Message *msg);
743 
746  const SessionID& get_sid() const { return _sid; }
747 
750  unsigned get_next_send_seq() const { return _next_send_seq; }
751 
754  void set_login_parameters(const LoginParameters& loginParamaters) { _loginParameters = loginParamaters; }
755 
758  void get_login_parameters(LoginParameters& loginParamaters) const { loginParamaters = _loginParameters; }
759 
763 
766  void set_reset_sequence_numbers_flag(bool flag) { _loginParameters._reset_sequence_numbers = flag; }
767 
770  void set_persister(Persister *pst) { _persist = pst; }
771 
774  Control& control() { return _control; }
775 
778  bool is_shutdown() { return _control.has(shutdown) || _state == States::st_session_terminated; }
779 
780  /* ! Set the SessionConfig object - only for server sessions
781  \param sf pointer to SessionConfig object */
782  void set_session_config(struct SessionConfig *sf) { _sf = sf; }
783 
786  F8API virtual Message *generate_logout(const char *msgstr=nullptr);
787 
791  F8API virtual Message *generate_heartbeat(const f8String& testReqID);
792 
797  F8API virtual Message *generate_resend_request(const unsigned begin, const unsigned end=0);
798 
803  F8API virtual Message *generate_sequence_reset(const unsigned newseqnum, const bool gapfillflag=false);
804 
808  F8API virtual Message *generate_test_request(const f8String& testReqID);
809 
815  F8API virtual Message *generate_reject(const unsigned seqnum, const char *what, const char *msgtype=nullptr);
816 
823  F8API virtual Message *generate_business_reject(const unsigned seqnum, const Message *msg, const int reason, const char *what);
824 
828  {
829  const States::SessionStates old_state(_state.exchange(new_state));
830  if (old_state != new_state)
831  state_change(old_state, new_state);
832  }
833 
837 
843  static const Message *detach(const Message *&msg)
844  {
845  const Message *tmp(msg);
846  msg = 0;
847  return tmp;
848  }
849 
854  {
855  static const f8String unknown("Unknown");
856  return state < _state_names.size() ? _state_names[state] : unknown;
857  }
858 
861  F8API static const f8String copyright_string();
862 };
863 
864 //-------------------------------------------------------------------------------------------------
865 // our buffered RAII ostream log target, ostream Session log target for specified Session ptr
866 #define ssout_info(x) if (!x->is_loggable(FIX8::Logger::Info)); \
867  else FIX8::log_stream(FIX8::logger_function(std::bind(&FIX8::Session::enqueue, x, std::placeholders::_1, FIX8::Logger::Info, FILE_LINE, std::placeholders::_2)))
868 #define ssout_warn(x) if (!x->is_loggable(FIX8::Logger::Warn)); \
869  else FIX8::log_stream(FIX8::logger_function(std::bind(&FIX8::Session::enqueue, x, std::placeholders::_1, FIX8::Logger::Warn, FILE_LINE, std::placeholders::_2)))
870 #define ssout_error(x) if (!x->is_loggable(FIX8::Logger::Error)); \
871  else FIX8::log_stream(FIX8::logger_function(std::bind(&FIX8::Session::enqueue, x, std::placeholders::_1, FIX8::Logger::Error, FILE_LINE, std::placeholders::_2)))
872 #define ssout_fatal(x) if (!x->is_loggable(FIX8::Logger::Fatal)); \
873  else FIX8::log_stream(FIX8::logger_function(std::bind(&FIX8::Session::enqueue, x, std::placeholders::_1, FIX8::Logger::Fatal, FILE_LINE, std::placeholders::_2)))
874 #if defined FIX8_DEBUG
875 #define ssout_debug(x) if (!x->is_loggable(Logger::Debug)); \
876  else FIX8::log_stream(FIX8::logger_function(std::bind(&FIX8::Session::enqueue, x, std::placeholders::_1, FIX8::Logger::Debug, FILE_LINE, std::placeholders::_2)))
877 #else
878 #define ssout_debug(x) true ? null_insert() : null_insert()
879 #endif
880 
881 #define ssout(x) ssout_info(x)
882 #define slout ssout(this)
883 #define slout_info ssout_info(this)
884 #define slout_warn ssout_warn(this)
885 #define slout_error ssout_error(this)
886 #define slout_fatal ssout_fatal(this)
887 #define slout_debug ssout_debug(this)
888 
889 //-------------------------------------------------------------------------------------------------
890 
891 } // FIX8
892 
893 #endif // FIX8_SESSION_HPP_
Logger * _logger
Definition: session.hpp:422
const MsgTable & _bme
Framework generated lookup table to generate Fix messages.
Definition: message.hpp:216
unsigned _req_next_send_seq
Definition: session.hpp:414
Connection * get_connection()
Definition: session.hpp:665
F8API void update_persist_seqnums()
Force persister to sync next send/receive seqnums.
Definition: session.cpp:266
target_comp_id _targetCompID
Definition: session.hpp:52
bool is_valid() const
Definition: session.hpp:242
Indicates a static metadata lookup failed. With the exception of user defined fields there should nev...
virtual bool activation_check(const unsigned seqnum, const Message *msg)
Definition: session.hpp:736
bool plog(const std::string &what, Logger::Level lev, const unsigned direction=0) const
Definition: session.hpp:703
f8_thread delegated async logging class
Definition: logger.hpp:153
friend std::ostream & operator<<(std::ostream &os, const SessionID &what)
Definition: session.hpp:151
F8API bool sequence_check(const unsigned seqnum, const Message *msg)
Definition: session.cpp:427
Logger * _plogger
Definition: session.hpp:422
bool send(const std::string &what, Level lev=Logger::Info, const char *fl=nullptr, const unsigned val=0)
Definition: logger.hpp:306
POSIX regex wrapper class.
Definition: f8utils.hpp:370
F8API void compid_check(const unsigned seqnum, const Message *msg, const SessionID &id) const
Definition: session.cpp:415
Fix8 Base Session. User sessions are derived from this class.
Definition: session.hpp:394
virtual F8API bool handle_logon(const unsigned seqnum, const Message *msg)
Definition: session.cpp:470
void set_session_config(struct SessionConfig *sf)
Definition: session.hpp:782
SessionID(const f8String &from)
Definition: session.hpp:73
unsigned _login_retry_interval
Definition: session.hpp:353
virtual void state_change(const States::SessionStates before, const States::SessionStates after)
Definition: session.hpp:510
std::pair< const unsigned, const f8String > SequencePair
Definition: session.hpp:615
friend std::ostream & operator<<(std::ostream &os, const Session_Schedule &what)
Definition: session.hpp:380
TimerEvent< Session > _hb_processor
Definition: session.hpp:425
SessionID(const begin_string &beginString, const sender_comp_id &senderCompID, const target_comp_id &targetCompID)
Definition: session.hpp:68
Message instantiation table entry.
Definition: message.hpp:192
Base (ABC) Persister class.
Definition: persist.hpp:55
void set_persister(Persister *pst)
Definition: session.hpp:770
default_appl_ver_id _davi
Definition: session.hpp:357
std::tuple< f8String, Poco::Net::IPAddress > Client
Class to hold client info settings for server sessions.
Definition: session.hpp:181
F8API SessionID make_reverse_id() const
Definition: session.cpp:81
States::SessionStates get_session_state() const
Definition: session.hpp:836
friend std::ostream & operator<<(std::ostream &os, const Schedule &what)
Definition: session.hpp:292
Provides context to your retrans handler.
Definition: session.hpp:598
virtual F8API bool process(const f8String &from)
Definition: session.cpp:277
virtual void modify_outbound(Message *msg)
Definition: session.hpp:514
const Tickval & get_last_received() const
Definition: session.hpp:708
bool same_sender_comp_id(const target_comp_id &targetCompID) const
Definition: session.hpp:114
Schedule & operator=(const Schedule &that)
Definition: session.hpp:224
Tickval _last_received
Definition: session.hpp:410
void set_reset_sequence_numbers_flag(bool flag)
Definition: session.hpp:766
Field< f8String, Common_MsgType > msg_type
Definition: field.hpp:2147
Persister * _persist
Definition: session.hpp:421
f8_atomic< States::SessionStates > _state
Definition: session.hpp:408
bool same_side_target_comp_id(const target_comp_id &targetCompID) const
Definition: session.hpp:124
LoginParameters & operator=(const LoginParameters &that)
Definition: session.hpp:328
const SessionID & get_sid() const
Definition: session.hpp:746
TimerEvent< Session > _session_scheduler
Definition: session.hpp:425
SessionID _sid
Definition: session.hpp:415
void do_state_change(const States::SessionStates new_state)
Definition: session.hpp:827
Tickval _duration
Definition: session.hpp:202
const sender_comp_id & get_senderCompID() const
Definition: session.hpp:101
const LoginParameters & get_login_parameters() const
Definition: session.hpp:762
High resolution timer.
Definition: timer.hpp:55
std::function< Message *(bool)> _do
Definition: message.hpp:176
Session_Schedule * _schedule
Definition: session.hpp:427
F8API bool activation_service()
Session start/stop service thread method.
Definition: session.cpp:788
Quickfix style sessionid.
Definition: session.hpp:46
virtual bool handle_admin(const unsigned seqnum, const Message *msg)
Definition: session.hpp:490
const F8MetaCntx & get_ctx() const
Definition: session.hpp:673
virtual F8API bool handle_resend_request(const unsigned seqnum, const Message *msg)
Definition: session.cpp:663
Complete Fix connection (reader and writer).
Definition: connection.hpp:508
bool test(bool prev=false) const
Definition: session.hpp:247
std::unordered_map< f8String, Client > Clients
Definition: session.hpp:182
static F8API const f8String copyright_string()
Definition: session.cpp:1207
std::string _batchmsgs_buffer
Definition: session.hpp:426
LoginParameters _loginParameters
Definition: session.hpp:418
virtual F8API Message * generate_logout(const char *msgstr=nullptr)
Definition: session.cpp:947
friend std::ostream & operator<<(std::ostream &os, const RetransmissionContext &what)
Definition: session.hpp:607
virtual F8API bool handle_sequence_reset(const unsigned seqnum, const Message *msg)
Definition: session.cpp:642
static const ticks day
Definition: tickval.hpp:81
Schedule _login_schedule
Definition: session.hpp:359
unsigned get_next_send_seq() const
Definition: session.hpp:750
virtual F8API bool handle_logout(const unsigned seqnum, const Message *msg)
Definition: session.cpp:630
sender_comp_id _sci
Definition: session.hpp:412
Schedule(Tickval start, Tickval end, Tickval duration=Tickval(), int utc_offset=0, int start_day=-1, int end_day=-1)
Definition: session.hpp:209
static F8API const std::vector< f8String > _state_names
string representation of Sessionstates
Definition: session.hpp:430
f8_atomic< unsigned > _next_receive_seq
Definition: session.hpp:407
virtual F8API bool send(Message *msg, bool destroy=true, const unsigned custom_seqnum=0, const bool no_increment=false)
Definition: session.cpp:978
f8_atomic< bool > _active
Definition: session.hpp:409
virtual bool handle_reject(const unsigned seqnum, const Message *msg)
Definition: session.hpp:484
Connection * _connection
Definition: session.hpp:413
void clear_connection(const Connection *connection)
Definition: session.hpp:586
bool same_target_comp_id(const sender_comp_id &senderCompID) const
Definition: session.hpp:119
bool operator!=(const SessionID &that)
Definition: session.hpp:142
static const Message * detach(const Message *&msg)
Definition: session.hpp:843
const F8MetaCntx & ctx()
Compiler generated metadata object, accessed through this function.
LoginParameters(unsigned login_retry_interval, unsigned login_retries, const default_appl_ver_id &davi, unsigned connect_timeout, bool reset_seqnum=false, bool always_seqnum_assign=false, bool silent_disconnect=false, bool no_chksum_flag=false, bool permissive_mode_flag=false, bool reliable=false, bool enforce_compids=true, unsigned recv_buf_sz=0, unsigned send_buf_sz=0, unsigned hb_int=defaults::hb_interval, const Schedule &sch=Schedule(), const Clients &clients=Clients(), const f8String &pem_path=f8String())
Definition: session.hpp:305
Tickval _last_sent
Definition: session.hpp:410
void set_login_parameters(const LoginParameters &loginParamaters)
Definition: session.hpp:754
unsigned _connect_timeout
Definition: session.hpp:354
#define F8API
Definition: f8dll.h:60
LoginParameters(const LoginParameters &from)
Definition: session.hpp:318
Control _control
Definition: session.hpp:406
F8API void stop()
stop the session.
Definition: session.cpp:230
Field< f8String, Common_SenderCompID > sender_comp_id
Definition: field.hpp:2145
virtual F8API Message * generate_logon(const unsigned heartbeat_interval, const f8String davi=f8String())
Definition: session.cpp:933
bool enqueue(const std::string &what, Logger::Level lev, const char *fl=nullptr, unsigned value=0) const
Definition: session.hpp:686
struct SessionConfig * _sf
Definition: session.hpp:416
struct tm get_tm() const
Definition: tickval.hpp:213
virtual bool handle_application(const unsigned seqnum, const Message *&msg)=0
sender_comp_id _senderCompID
Definition: session.hpp:51
virtual F8API int modify_header(MessageBase *msg)
Definition: session.cpp:1003
SessionID(const f8String &beginString, const f8String &senderCompID, const f8String &targetCompID)
Definition: session.hpp:61
integral_type has(const T sbit) const
Definition: f8utils.hpp:975
Tickval & now()
Definition: tickval.hpp:133
f8_spin_lock _per_spl
Definition: session.hpp:420
void set_scheduler(int priority)
Definition: session.cpp:1194
bool is_errorval() const
Definition: tickval.hpp:173
Base session wrapper.
const Tickval & get_last_sent() const
Definition: session.hpp:712
virtual F8API bool handle_test_request(const unsigned seqnum, const Message *msg)
Definition: session.cpp:771
decltype(f8_time_point::min().time_since_epoch().count()) ticks
Definition: tickval.hpp:66
const target_comp_id & get_targetCompID() const
Definition: session.hpp:105
virtual F8API ~Session()
Dtor.
Definition: session.cpp:152
bool log(const std::string &what, Logger::Level lev, const char *fl=nullptr, unsigned value=0) const
Definition: session.hpp:695
unsigned _req_next_receive_seq
Definition: session.hpp:414
virtual F8API bool handle_heartbeat(const unsigned seqnum, const Message *msg)
Definition: session.cpp:868
A complete Fix message with header, body and trailer.
Definition: message.hpp:1058
std::atomic< T > f8_atomic
Definition: thread.hpp:55
generic spin_lock wrapper
Definition: thread.hpp:364
F8API bool send_process(Message *msg)
Definition: session.cpp:1009
F8API Session(const F8MetaCntx &ctx, const SessionID &sid, Persister *persist=nullptr, Logger *logger=nullptr, Logger *plogger=nullptr)
Definition: session.cpp:105
Timer event object to provide callback context with Timer.
Definition: timer.hpp:60
bool enqueue(const std::string &what, Level lev=Logger::Info, const char *fl=nullptr, const unsigned val=0)
Definition: logger.hpp:294
virtual F8API Message * generate_reject(const unsigned seqnum, const char *what, const char *msgtype=nullptr)
Definition: session.cpp:888
Timer< Session > & get_timer()
Definition: session.hpp:669
f8String _rid
Definition: session.hpp:54
Schedule(const Schedule &from)
Definition: session.hpp:217
F8API void make_id()
Definition: session.cpp:73
void update_sent()
Update the last sent time.
Definition: session.hpp:715
Message * create_msg(const f8String &msg_type) const
Definition: session.hpp:528
bool same_side_sender_comp_id(const sender_comp_id &senderCompID) const
Definition: session.hpp:129
virtual bool authenticate(SessionID &id, const Message *msg)
Definition: session.hpp:520
Session_Schedule(Schedule &sch, int reject_reason=0, const std::string &reject_text="Business messages are not accepted now.")
Definition: session.hpp:371
f8String _id
Definition: session.hpp:54
F8API bool heartbeat_service()
Heartbeat generation service thread method.
Definition: session.cpp:808
static const f8String & get_session_state_string(const States::SessionStates state)
Definition: session.hpp:853
unsigned _login_retries
Definition: session.hpp:353
const f8String & get_id() const
Definition: session.hpp:109
const std::string _reject_text
Definition: session.hpp:369
begin_string _beginString
Definition: session.hpp:50
bool operator==(const SessionID &that)
Definition: session.hpp:134
const F8MetaCntx & _ctx
Definition: session.hpp:411
virtual F8API Message * generate_business_reject(const unsigned seqnum, const Message *msg, const int reason, const char *what)
Definition: session.cpp:901
virtual F8API Message * generate_test_request(const f8String &testReqID)
Definition: session.cpp:924
bool is_loggable(Logger::Level level) const
Definition: session.hpp:678
void set_affinity(int core_id)
Definition: session.cpp:1200
Tickval::ticks _toffset
Definition: session.hpp:204
bool in_range(const Tickval &a, const Tickval &b) const
Definition: tickval.hpp:179
F8API bool enforce(const unsigned seqnum, const Message *msg)
Definition: session.cpp:252
Tickval _start
Definition: session.hpp:202
F8API void from_string(const f8String &from)
Create a sessionid string.
Definition: session.cpp:87
RetransmissionContext(const unsigned begin, const unsigned end, const unsigned interrupted_seqnum)
Definition: session.hpp:604
Tickval & adjust(ticks by)
Definition: tickval.hpp:187
std::thread::id thread_id_t
Definition: thread.hpp:58
virtual F8API Message * generate_heartbeat(const f8String &testReqID)
Definition: session.cpp:878
Tickval _end
Definition: session.hpp:202
bool is_loggable(Level level) const
Definition: logger.hpp:262
Timer< Session > _timer
Definition: session.hpp:424
const begin_string & get_beginString() const
Definition: session.hpp:97
static RegExp _sid
Definition: session.hpp:48
static bool is_live(SessionStates ss)
Definition: session.hpp:169
virtual ~SessionID()
Dtor.
Definition: session.hpp:83
virtual F8API size_t send_batch(const std::vector< Message * > &msgs, bool destroy=true)
Definition: session.cpp:997
Base class for all fix messages.
Definition: message.hpp:381
virtual F8API Message * generate_resend_request(const unsigned begin, const unsigned end=0)
Definition: session.cpp:957
const Minst _create
Definition: message.hpp:194
const Val * find_ptr(const Key &key) const
Definition: f8types.hpp:154
ticks get_ticks() const
Definition: tickval.hpp:129
f8_atomic< unsigned > _next_send_seq
Definition: session.hpp:407
virtual F8API Message * generate_sequence_reset(const unsigned newseqnum, const bool gapfillflag=false)
Definition: session.cpp:966
Static metadata context class - one per FIX xml schema.
Definition: message.hpp:210
F8API int start(Connection *connection, bool wait=true, const unsigned send_seqnum=0, const unsigned recv_seqnum=0, const f8String davi=f8String())
Definition: session.cpp:167
virtual F8API bool handle_outbound_reject(const unsigned seqnum, const Message *msg, const char *errstr)
Definition: session.cpp:782
void update_received()
Update the last received time.
Definition: session.hpp:718
bool is_shutdown()
Definition: session.hpp:778
virtual F8API void recover_seqnums()
Recover next expected and next to send sequence numbers from persitence layer.
Definition: session.cpp:1124
std::string f8String
Definition: f8types.hpp:47
void atomic_init(States::SessionStates st)
Definition: session.cpp:144
Control & control()
Definition: session.hpp:774
static bool is_established(SessionStates ss)
Definition: session.hpp:175
SessionID(const SessionID &from)
Definition: session.hpp:77
void get_login_parameters(LoginParameters &loginParamaters) const
Definition: session.hpp:758
virtual F8API bool retrans_callback(const SequencePair &with, RetransmissionContext &rctx)
Definition: session.cpp:707