OnixS C++ FIX Engine  4.6.0
API Documentation
Session.h
Go to the documentation of this file.
1 /*
2 * Copyright Onix Solutions Limited [OnixS]. All rights reserved.
3 *
4 * This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
5 * and international copyright treaties.
6 *
7 * Access to and use of the software is governed by the terms of the applicable OnixS Software
8 * Services Agreement (the Agreement) and Customer end user license agreements granting
9 * a non-assignable, non-transferable and non-exclusive license to use the software
10 * for it's own data processing purposes under the terms defined in the Agreement.
11 *
12 * Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
13 * of this source code or associated reference material to any other location for further reproduction
14 * or redistribution, and any amendments to this copyright notice, are expressly prohibited.
15 *
16 * Any reproduction or redistribution for sale or hiring of the Software not in accordance with
17 * the terms of the Agreement is a violation of copyright law.
18 */
19 
20 #pragma once
21 
22 #include <string>
23 #include <set>
24 #include <vector>
25 #include <utility>
26 #include <iosfwd>
27 #include <limits>
28 
31 
33 
42 
44 
46 
49 
50 
51 namespace OnixS {
52 namespace FIX {
53 ONIXS_FIXENGINE_API_DECL(class, Message);
54 ONIXS_FIXENGINE_API_DECL(class, Dictionary);
55 ONIXS_FIXENGINE_API_DECL(class, Engine);
56 ONIXS_FIXENGINE_API_DECL(class, ISessionListener);
57 ONIXS_FIXENGINE_API_DECL(class, ISessionStorage);
58 
59 /// Session message mode.
60 struct MessageMode {
61  enum Enum {
62  /// The default mode. The `Message` class is used in inbound callbacks.
63  Message = 1,
64 
65  /// The `FlatMessage` class is used in inbound callbacks.
67  };
68 };
69 
70 namespace Core {
71 namespace Messaging {
72 class Message;
73 }
74 }
75 
76 template<typename MsgType>
78 {
80  typedef std::vector<FlatMessage*> MsgBatchType;
81  typedef std::vector<OnixS::FIX::Core::Messaging::Extras::FlatMessage*> CoreMsgBatchType;
82 };
83 
84 template<>
86 {
88  typedef std::vector<Message*> MsgBatchType;
89  typedef std::vector<OnixS::FIX::Core::Messaging::Message*> CoreMsgBatchType;
90 };
91 
92 namespace TCPDirect {
93  class Stack;
94 }
95 
96 /**
97 * FIX Session - a bi-directional stream of ordered messages between two parties within a continuous sequence number series.
98 */
100 {
101 public:
102  /**
103  * Creates the FIX Session.
104  *
105  * @param senderCompId Assigned value used to identify firm sending message (SenderCompID (tag=49) field value in outgoing messages).
106  * @param targetCompId Assigned value used to identify receiving firm (TargetCompID (tag=56) field value in outgoing messages).
107  * @param dictionary FIX dictionary to be used by the session.
108  * @param listener Instance of ISessionListener interface which will receive and handle miscellaneous Session events.
109  * @param storageType Session storage type.
110  * @param storage Pluggable Session storage.
111  */
112  Session(
113  const std::string & senderCompId,
114  const std::string & targetCompId,
115  const Dictionary & dictionary,
116  ISessionListener * listener,
118  ISessionStorage * storage = ONIXS_FIXENGINE_NULLPTR);
119 
120  /**
121  * Creates the FIX Session.
122  *
123  * @param reactor An instance of externally managed reactor.
124  * @param senderCompId Assigned value used to identify firm sending message (SenderCompID (tag=49) field value in outgoing messages).
125  * @param targetCompId Assigned value used to identify receiving firm (TargetCompID (tag=56) field value in outgoing messages).
126  * @param dictionary FIX dictionary to be used by the session.
127  * @param listener Instance of ISessionListener interface which will receive and handle miscellaneous Session events.
128  * @param storageType Session storage type.
129  * @param storage Pluggable Session storage.
130  */
131  Session(
132  ISessionReactor * reactor,
133  const std::string & senderCompId,
134  const std::string & targetCompId,
135  const Dictionary & dictionary,
136  ISessionListener * listener,
138  ISessionStorage * storage = ONIXS_FIXENGINE_NULLPTR);
139 
140  /**
141  * Creates the FIX Session.
142  *
143  * @param senderCompId Assigned value used to identify firm sending message (SenderCompID (tag=49) field value in outgoing messages).
144  * @param targetCompId Assigned value used to identify receiving firm (TargetCompID (tag=56) field value in outgoing messages).
145  * @param dictionary FIX dictionary to be used by the session.
146  * @param keepSequenceNumbersAfterLogout Option to keep sequence numbers after the exchange of Logout (MsgType=5) messages.
147  * @param listener Instance of ISessionListener interface which will receive and handle miscellaneous Session events.
148  * @param storageType Session storage type.
149  * @param storage Pluggable Session storage.
150  */
151  Session(
152  const std::string & senderCompId,
153  const std::string & targetCompId,
154  const Dictionary & dictionary,
155  bool keepSequenceNumbersAfterLogout,
156  OnixS::FIX::ISessionListener * listener,
158  ISessionStorage * storage = ONIXS_FIXENGINE_NULLPTR);
159 
160 
161  /**
162  * Creates the FIX Session.
163  *
164  * @param reactor An instance of externally managed reactor.
165  * @param senderCompId Assigned value used to identify firm sending message (SenderCompID (tag=49) field value in outgoing messages).
166  * @param targetCompId Assigned value used to identify receiving firm (TargetCompID (tag=56) field value in outgoing messages).
167  * @param dictionary FIX dictionary to be used by the session.
168  * @param keepSequenceNumbersAfterLogout Option to keep sequence numbers after the exchange of Logout (MsgType=5) messages.
169  * @param listener Instance of ISessionListener interface which will receive and handle miscellaneous Session events.
170  * @param storageType Session storage type.
171  * @param storage Pluggable Session storage.
172  */
173  Session(
174  ISessionReactor * reactor,
175  const std::string & senderCompId,
176  const std::string & targetCompId,
177  const Dictionary & dictionary,
178  bool keepSequenceNumbersAfterLogout,
179  OnixS::FIX::ISessionListener * listener,
181  ISessionStorage * storage = ONIXS_FIXENGINE_NULLPTR);
182 
183  /**
184  * Creates the FIX Session.
185  *
186  * @param senderCompId Assigned value used to identify firm sending message (SenderCompID (tag=49) field value in outgoing messages).
187  * @param targetCompId Assigned value used to identify receiving firm (TargetCompID (tag=56) field value in outgoing messages).
188  * @param dictionary FIX dictionary to be used by the session.
189  * @param keepSequenceNumbersAfterLogout Option to keep sequence numbers after the exchange of Logout (MsgType=5) messages.
190  * @param listener Instance of ISessionListener interface which will receive and handle miscellaneous Session events.
191  * @param customSessionKey Custom key that can be used to distinguish sessions with the same values of the SenderCompID, TargetCompID and the FIX Protocol version.
192  * @param storageType Session storage type.
193  * @param storage Pluggable Session storage.
194  */
195  Session(
196  const std::string & senderCompId,
197  const std::string & targetCompId,
198  const Dictionary & dictionary,
199  bool keepSequenceNumbersAfterLogout,
200  OnixS::FIX::ISessionListener * listener,
201  const std::string & customSessionKey,
203  ISessionStorage * storage = ONIXS_FIXENGINE_NULLPTR);
204 
205  /**
206  * Creates the FIX Session.
207  *
208  * @param reactor An instance of externally managed reactor.
209  * @param senderCompId Assigned value used to identify firm sending message (SenderCompID (tag=49) field value in outgoing messages).
210  * @param targetCompId Assigned value used to identify receiving firm (TargetCompID (tag=56) field value in outgoing messages).
211  * @param dictionary FIX dictionary to be used by the session.
212  * @param keepSequenceNumbersAfterLogout Option to keep sequence numbers after the exchange of Logout (MsgType=5) messages.
213  * @param listener Instance of ISessionListener interface which will receive and handle miscellaneous Session events.
214  * @param customSessionKey Custom key that can be used to distinguish sessions with the same values of the SenderCompID, TargetCompID and the FIX Protocol version.
215  * @param storageType Session storage type.
216  * @param storage Pluggable Session storage.
217  */
218  Session(
219  ISessionReactor * reactor,
220  const std::string & senderCompId,
221  const std::string & targetCompId,
222  const Dictionary & dictionary,
223  bool keepSequenceNumbersAfterLogout,
224  OnixS::FIX::ISessionListener * listener,
225  const std::string & customSessionKey,
227  ISessionStorage * storage = ONIXS_FIXENGINE_NULLPTR);
228 
229  /**
230  * Destructor.
231  */
232  ~Session();
233 
234  /**
235  * Removes all messages from the outbound queue.
236  *
237  * @param removeFragmentedPacket - specifies whether to remove last packet which is partly sent.
238  *
239  * @note This call is thread-safe.
240  */
241  Session & clearOutboundQueue(bool removeFragmentedPacket = false);
242 
243  /**
244  * Returns Session's state.
245  *
246  * @note This call is thread-safe.
247  */
248  SessionState::Enum state() const;
249 
250  /**
251  * Returns the current encryption method.
252  *
253  * @note This call is thread-safe.
254  */
255  EncryptionMethod::Enum encryptionMethod() const;
256 
257  /**
258  * Sets the encryption method.
259  *
260  * @note This call is thread-safe.
261  */
262  Session & encryptionMethod(EncryptionMethod::Enum newEncryptionMethod);
263 
264  /**
265  * Returns the port to listen on for incoming FIX Connections in Acceptor mode.
266  *
267  * @note This call is thread-safe.
268  */
269  int listenPort() const;
270 
271  /**
272  * Sets the port to listen on for incoming FIX Connections in Acceptor mode.
273  *
274  * @note This call is thread-safe.
275  */
276  Session & listenPort(int listenPort);
277 
278  /**
279  * Returns the local network interface from which you intend to send and receive data.
280  *
281  * @note This call is thread-safe.
282  */
283  std::string localNetworkInterface() const;
284 
285  /**
286  * Sets the local network interface from which you intend to send and receive data.
287  *
288  * @note This call is thread-safe.
289  */
290  Session & localNetworkInterface(const std::string & localNetworkInterface);
291 
292  /**
293  * Returns the local port from which you intend to send and receive data.
294  *
295  * @note This call is thread-safe.
296  */
297  unsigned short localPort() const;
298  /**
299  * Local port range type.
300  */
301  typedef std::pair<unsigned short, unsigned short> LocalPortRange;
302 
303  /**
304  * Returns the local port range, the first available port from this range will be used to send and receive data.
305  *
306  * @note This call is thread-safe.
307  */
308  LocalPortRange localPortRange() const;
309 
310  /**
311  * Sets the local port range, the first available port from this range will be used to send and receive data.
312  *
313  * @note This call is thread-safe.
314  */
315  Session & localPortRange(LocalPortRange portRange);
316 
317  /**
318  * Returns option to improve latency at the expense of message throughput (TCP_NODELAY socket option).
319  * When it is not set, the corresponding Engine setting's value is used ('true' by default).
320  */
321  bool tcpNoDelayOption() const;
322 
323  /**
324  * Sets value of option to improve latency at the expense of message throughput (TCP_NODELAY socket option).
325  */
326  Session & tcpNoDelayOption(bool improveLatency = true);
327 
328  /**
329  * Returns the option that controls whether to send the logout message before
330  * dropping the telecommunication link, in case of exception.
331  * When it is not set, the corresponding Engine setting's value is used ('false' by default).
332  */
333  bool sendLogoutOnException() const;
334 
335  /**
336  * Sets value of the option that controls whether to send the logout message before
337  * dropping the telecommunication link, in case of exception.
338  */
339  Session & sendLogoutOnException(bool sendLogoutOnException);
340 
341  /**
342  * Returns option to validate the presence of unknown FIX messages.
343  * When it is not set, the corresponding Engine setting's value is used ('false' by default).
344  */
345  bool validateUnknownMessages() const;
346 
347  /**
348  * Sets option to validate the presence of unknown FIX messages.
349  */
350  Session & validateUnknownMessages(bool);
351 
352  /**
353  * Returns option to validate the presence of unknown fields.
354  * When it is not set, the corresponding Engine setting's value is used ('false' by default).
355  */
356  bool validateUnknownFields() const;
357 
358  /**
359  * Sets option to validate the presence of unknown fields.
360  */
361  Session & validateUnknownFields(bool);
362 
363  /**
364  * Returns option to validate the presence of required fields in inbound and outbound messages.
365  * When it is not set, the corresponding Engine setting's value is used ('false' by default).
366  */
367  bool validateRequiredFields() const;
368 
369  /**
370  * Sets option to validate the presence of required fields in inbound and outbound messages.
371  */
372  Session & validateRequiredFields(bool);
373 
374  /**
375  * Returns option to validate the field values of FIX messages in accordance with the FIX protocol or its FIX Dictionary.
376  * When it is not set, the corresponding Engine setting's value is used ('false' by default).
377  */
378  bool validateFieldValues() const;
379 
380  /**
381  * Sets option to validate the field values of FIX messages in accordance with the FIX protocol or its FIX Dictionary.
382  */
383  Session & validateFieldValues(bool);
384 
385  /**
386  * Returns option to validate the empty field values of FIX messages in accordance with the FIX protocol or its FIX Dictionary.
387  * When it is not set, the corresponding Engine setting's value is used ('false' by default).
388  */
389  bool validateEmptyFieldValues() const;
390 
391  /**
392  * Sets option to validate the empty field values of FIX messages in accordance with the FIX protocol or its FIX Dictionary.
393  */
394  Session & validateEmptyFieldValues(bool);
395 
396  /**
397  * Returns the option that controls repeating group entry count validation.
398  * When it is not set, the corresponding Engine setting's value is used ('true' by default).
399  */
400  bool validateRepeatingGroupEntryCount() const;
401 
402  /**
403  * Sets value of the option that controls repeating group entry count validation.
404  */
405  Session & validateRepeatingGroupEntryCount(bool);
406 
407  /**
408  * Returns the option that controls repeating group leading tag validation.
409  * When it is not set, the corresponding Engine setting's value is used ('false' by default).
410  */
411  bool validateRepeatingGroupLeadingTag() const;
412 
413  /**
414  * Sets value of the option that controls repeating group leading tag validation.
415  */
416  Session & validateRepeatingGroupLeadingTag(bool);
417 
418  /**
419  * Returns the option that controls duplicated field validation.
420  * When it is not set, the corresponding Engine setting's value is used ('false' by default).
421  */
422  bool validateDuplicatedField() const;
423 
424  /**
425  * Sets value of the option that controls duplicated field validation.
426  */
427  Session & validateDuplicatedField(bool);
428 
429  /**
430  * Returns the option that controls the validation of the checksum of the incoming message.
431  * When it is not set, the corresponding Engine setting's value is used ('false' by default).
432  */
433  bool validateChecksum() const;
434 
435  /**
436  * Sets the validation of the checksum of the incoming message.
437  */
438  Session & validateChecksum(bool);
439 
440  /**
441  * Returns the number of messages that should be written to the outgoing TCP buffer together.
442  * When it is not set, the corresponding Engine setting's value is used (0 by default).
443  */
444  unsigned messageGrouping() const;
445 
446  /**
447  * Sets the number of messages that should be written to the outgoing TCP buffer together.
448  */
449  Session & messageGrouping(unsigned numberOfMessagesToGroup);
450 
451  /**
452  * Returns the connection mode.
453  */
454  ThreadingModel::Enum threadingModel() const;
455 
456  /**
457  * Sets the connection mode.
458  */
459  Session & threadingModel(ThreadingModel::Enum value);
460 
461  /**
462  * Returns the reasonable transmission time as % from heartbeatIntervalSec value.
463  * When it is not set, the corresponding Engine setting's value is used (20% by default).
464  */
465  int reasonableTransmissionTime() const;
466 
467  /**
468  * Sets the reasonable transmission time as % from heartbeatIntervalSec value.
469  *
470  * When either end of the connection has not received any data for (heartbeatIntervalSec() * (100 + reasonableTransmissionTime())/100) seconds,
471  * it will transmit a Test Request message.
472  *
473  * If there is still no Heartbeat message received after (heartbeatIntervalSec * (100 + reasonableTransmissionTime())/100) seconds
474  * then the connection should be considered lost and corrective action be initiated.
475  */
476  Session & reasonableTransmissionTime(int value);
477 
478  /**
479  * Sets the number of attempts to restore the telecommunication link.
480  */
481  Session & reconnectAttempts(int value);
482 
483  /**
484  * Returns the number of attempts to restore the telecommunication link.
485  * When it is not set, the corresponding Engine setting's value is used (3 by default).
486  */
487  int reconnectAttempts() const;
488 
489  /**
490  * Sets the time interval between the attempts to restore the telecommunication link (in seconds).
491  */
492  Session & reconnectInterval(int value);
493 
494  /**
495  * Returns the time interval between the attempts to restore the telecommunication link (in seconds).
496  * When it is not set, the corresponding Engine setting's value is used (180 by default).
497  */
498  int reconnectInterval() const;
499 
500  /**
501  * Sets the non-blocking receive spinning timeout (in microseconds) before the receiving thread enters into the blocking wait mode.
502  *
503  * @note Should not be greater than 1 sec (minimal heartbeatIntervalSec()).
504  */
505  Session & receiveSpinningTimeoutUsec(int usec);
506 
507  /**
508  * Returns the current receive spinning timeout value (in microseconds).
509  * By default, the value is zero and receive spinning is not used.
510  */
511  int receiveSpinningTimeout() const;
512 
513  /**
514  * Sets the send spinning timeout (in microseconds) of the Session::send(..) method to wait for the socket sending buffer availability
515  * in the spin loop mode before placing the message to the outgoing queue (to be sent later by the sending thread).
516  *
517  * @note Should not be greater than 1 sec (minimal heartbeatIntervalSec()).
518  */
519  Session & sendSpinningTimeoutUsec(int usec);
520 
521  /**
522  * Returns the current send spinning timeout value (in microseconds).
523  * By default, the value is zero and send spinning is not used.
524  */
525  int sendSpinningTimeout() const;
526 
527  /**
528  * Sets NextExpectedMsgSeqNum field (tag 789) support in Logon messages.
529  */
530  Session & supportNextExpectedMsgSeqNum(bool support);
531 
532  /**
533  * Returns 'true' if NextExpectedMsgSeqNum field (tag 789) is supported in Logon messages, otherwise - 'false'.
534  * By default, the option value is false.
535  */
536  bool supportNextExpectedMsgSeqNum() const;
537 
538  /**
539  * Returns the SSL certificate file.
540  *
541  * @note This call is thread-safe.
542  */
543  std::string sslCertificateFile() const;
544 
545  /**
546  * Sets the SSL certificate file.
547  *
548  * @note Only the (Privacy Enhanced Mail) Base 64 Encoded (.pem) SSL certificates are supported.
549  *
550  * @note This call is thread-safe.
551  */
552  Session & sslCertificateFile(const std::string & file);
553 
554  /**
555  * Returns the SSL private key file.
556  *
557  * @note This call is thread-safe.
558  */
559  std::string sslPrivateKeyFile() const;
560 
561  /**
562  * Sets the SSL private key file.
563  *
564  * @note Only the (Privacy Enhanced Mail) Base 64 Encoded (.pem) SSL certificates are supported.
565  *
566  * @note This call is thread-safe.
567  */
568  Session & sslPrivateKeyFile(const std::string & file);
569 
570  /**
571  * Returns the SSL private key file password.
572  *
573  * @note This call is thread-safe.
574  */
575  std::string sslPrivateKeyPassword() const;
576 
577  /**
578  * Sets the SSL private key file password.
579  *
580  * @note This call is thread-safe.
581  */
582  Session & sslPrivateKeyPassword(const std::string & password);
583 
584  /**
585  * Set option to request peer certificates and perform the certificate verification.
586  *
587  * @note This call is thread-safe.
588  */
589  Session & sslVerifyPeer(bool verify);
590 
591  /**
592  * Returns option to request peer certificates and perform the certificate verification.
593  * When it is not set, the corresponding Engine setting's value is used ('false' by default).
594  *
595  * @note This call is thread-safe.
596  */
597  bool sslVerifyPeer() const;
598 
599  /**
600  * Sets the path to the trusted certification authority certificate file in (Privacy Enhanced Mail) Base64 encoded (.pem) format.
601  *
602  * @note This call is thread-safe.
603  */
604  Session & sslCaFile(const std::string & value);
605 
606  /**
607  * Returns the path to trusted certification authority certificate file in (Privacy Enhanced Mail) Base64 encoded (.pem) format.
608  *
609  * @note This call is thread-safe.
610  */
611  std::string sslCaFile() const;
612 
613  /**
614  * Establishes the FIX Connection as Acceptor.
615  *
616  * Acceptor is the receiving party of the FIX session. It listens for the incoming connection on the pre-defined port.
617  * The acceptor has responsibility to perform first level authentication and formally declare
618  * the connection request "accepted" through transmission of an acknowledgment Logon message.
619  *
620  * @note This call is thread-safe.
621  */
622  Session & logonAsAcceptor();
623 
624  /**
625  * Establishes FIX Connection as Initiator using the ResetSeqNumFlag (tag 141) field.
626  *
627  * Initiator establishes the telecommunications link and initiates the session via transmission
628  * of the initial Logon message.
629  * The method is blocked until the acknowledgment Logon message is received or the timeout expired.
630  * The timeout value is equal to the triple heartbeat interval.
631  *
632  * @note This call is thread-safe.
633  */
634  Session & logonAsInitiator(const std::string & host, int port, bool setResetSeqNumFlag);
635 
636  /**
637  * Establishes FIX Connection as Initiator.
638  *
639  * Initiator establishes the telecommunications link and initiates the session via transmission
640  * of the initial Logon message.
641  * The method is blocked until the acknowledgment Logon message is received or the timeout expired.
642  * The timeout value is equal to the triple heartbeat interval.
643  *
644  * @note This call is thread-safe.
645  */
646  Session & logonAsInitiator(const std::string & host, int port);
647 
648  /**
649  * Establishes FIX Connection as Initiator using the given Heartbeat interval (seconds).
650  * The method is blocked until the acknowledgment Logon message is received or the timeout expired.
651  * The timeout value is equal to the triple heartbeat interval.
652  *
653  * @note This call is thread-safe.
654  */
655  Session & logonAsInitiator(const std::string & host, int port, int heartbeatIntervalSec);
656 
657  /**
658  * Establishes FIX Connection as Initiator using the given Heartbeat interval (seconds) and the ResetSeqNumFlag(141) field.
659  * The method is blocked until the acknowledgment Logon message is received or the timeout expired.
660  * The timeout value is equal to the triple heartbeat interval.
661  *
662  * @note This call is thread-safe.
663  */
664  Session & logonAsInitiator(const std::string & host, int port, int heartbeatIntervalSec, bool setResetSeqNumFlag);
665 
666  /**
667  * Establishes FIX Connection as Initiator using the custom Logon message.
668  * The method is blocked until the acknowledgment Logon message is received or the timeout expired.
669  * The timeout value is equal to the triple heartbeat interval.
670  *
671  * @note This call is thread-safe.
672  */
673  Session & logonAsInitiator(const std::string & host, int port, int heartbeatIntervalSec, Message * customLogonMsg);
674 
675  /**
676  * Establishes FIX Connection as Initiator using the custom Logon message and the ResetSeqNumFlag(141) field.
677  * The method is blocked until the acknowledgment Logon message is received or the timeout expired.
678  * The timeout value is equal to the triple heartbeat interval.
679  *
680  * @note This call is thread-safe.
681  */
682  Session & logonAsInitiator(const std::string & host, int port, int heartbeatIntervalSec, Message * customLogonMsg, bool setResetSeqNumFlag);
683 
684  /**
685  * Establishes FIX Connection asynchronously as Initiator using the custom Logon message and the ResetSeqNumFlag(141) field.
686  * The method returns immediately without waiting the acknowledgment Logon message.
687  * Returns the `SharedFuture` object that can be used to wait for the result of the asynchronous logon method.
688  *
689  * @note This call is thread-safe.
690  */
691  Threading::SharedFuture<void> logonAsInitiatorAsync(const std::string & host, int port, int heartbeatIntervalSec, Message * customLogonMsg, bool setResetSeqNumFlag);
692 
693  /**
694  * Terminates the FIX Connection.
695  *
696  * The initial Logout message is sent to the counterparty and the method is blocked until the acknowledgment
697  * Logout message is received or the timeout expired.
698  * The timeout value is equal to the triple heartbeat interval or,
699  * in case there are no incoming messages, heartbeat interval plus reasonable transmission time.
700  *
701  * @note This call is thread-safe.
702  */
703  Session & logout();
704 
705  /**
706  * Terminates the FIX Connection.
707  *
708  * The initial Logout message is sent to the counterparty and the method is blocked until the acknowledgment
709  * Logout message is received or the timeout expired.
710  * The timeout value is equal to the triple heartbeat interval or,
711  * in case there are no incoming messages, heartbeat interval plus reasonable transmission time.
712  *
713  * @param text Free format text string that is sent to the counterparty in the Text(58) field of the initial
714  * Logout message.
715  *
716  * @note This call is thread-safe.
717  */
718  Session & logout(const std::string & text);
719 
720  /**
721  * Terminates the FIX Connection.
722  *
723  * The initial Logout message is sent to the counterparty and the method returns immediately
724  * without waiting the acknowledgment Logout message.
725  * Returns the `SharedFuture` object that can be used to wait for the result of the asynchronous logout method.
726  *
727  * @param text Free format text string that is sent to the counterparty in the Text(58) field of the initial
728  * Logout message.
729  *
730  * @note This call is thread-safe.
731  */
732  Threading::SharedFuture<void> logoutAsync(const std::string & text);
733 
734  /**
735  * Terminates the FIX Connection.
736  *
737  * The initial Logout message is sent to the counterparty and the method is blocked until the acknowledgment
738  * Logout message is received or the timeout expired.
739  * The timeout value is equal to the triple heartbeat interval or,
740  * in case there are no incoming messages, heartbeat interval plus reasonable transmission time.
741  *
742  * @param customLogoutMessage Custom Logout message that is sent to the counterparty.
743  *
744  * @note This call is thread-safe.
745  */
746  Session & logout(Message * customLogoutMessage);
747  Session & logout(FlatMessage * customLogoutMessage);
748 
749  /**
750  * Terminates the FIX Connection.
751  *
752  * The initial Logout message is sent to the counterparty and the method returns immediately
753  * without waiting the acknowledgment Logout message.
754  * Returns the `SharedFuture` object that can be used to wait for the result of the asynchronous logout method.
755  *
756  * @param customLogoutMessage Custom Logout message that is sent to the counterparty.
757  *
758  * @note This call is thread-safe.
759  */
760  Threading::SharedFuture<void> logoutAsync(Message * customLogoutMessage);
761  Threading::SharedFuture<void> logoutAsync(FlatMessage * customLogoutMessage);
762 
763  /**
764  * Terminates the FIX connection in the non-graceful way (without the exchange of Logout (MsgType=5) messages).
765  *
766  * @note This call is thread-safe.
767  */
768  Session & breakConnection();
769 
770  /**
771  * Sends the message to the counterparty.
772  *
773  * As soon as a session is created, it is possible to start sending messages via the session.
774  * If the session is not established, the messages are stored in the session storage and will be sent in replay to the resend request
775  * when the connection is established with the counterparty and the sequence numbers mismatch is detected.
776  *
777  * @note This call is asynchronous.
778  *
779  * @note This call is thread-safe.
780  */
781  Session & send(Message * msg);
782  Session & send(FlatMessage * msg);
783 
784  /**
785  * Performs sending via a specific API (e.g. zero-copy send) of the message to the counterparty.
786  *
787  * As soon as a session is created, it is possible to start sending messages via the session.
788  * If the session is not established, the messages are stored in the session storage and will be sent in replay to the resend request
789  * when the connection is established with the counterparty and the sequence numbers mismatch is detected.
790  *
791  * @note This call is asynchronous.
792  *
793  * @note This call is thread-safe.
794  */
795  Session & send(FlatMessage * msg, SessionSendMode::Enum mode);
796 
797  /**
798  * Message batch types.
799  */
800  template<typename MsgType> class MsgBatch;
801 
803  {
806 
807  static void init(MBT::CoreMsgBatchType & coreBatch);
808  static void init(SBT::CoreMsgBatchType & coreBatch);
809  static void add(MBT::MsgBatchType & batch, MBT::CoreMsgBatchType & coreBatch, MBT::MessagePtr & msg);
810  static void add(SBT::MsgBatchType & batch, SBT::CoreMsgBatchType & coreBatch, SBT::MessagePtr & msg);
811  static void clear(MBT::MsgBatchType & batch);
812  static void clear(SBT::MsgBatchType & batch);
813 
814  template<typename MsgType> friend class MsgBatch;
815  };
816 
817  template<typename MsgType>
818  class MsgBatch
819  {
820  typedef MsgBatchTraits<MsgType> Traits;
821 
822  friend class Session;
823 
824  typename Traits::MsgBatchType batch_;
825  typename Traits::CoreMsgBatchType coreBatch_;
826 
827  MsgBatch(const MsgBatch&);
828  MsgBatch & operator=(const MsgBatch&);
829 
830  public:
831 
832  typedef typename Traits::MessagePtr MessagePtr;
833  typedef typename Traits::MsgBatchType::iterator iterator;
834  typedef typename Traits::MsgBatchType::const_iterator const_iterator;
835 
836  MsgBatch() { MsgBatchHelper::init(coreBatch_); }
837  ~MsgBatch() { MsgBatchHelper::clear(batch_); }
838 
839  void add(MessagePtr & msg) { MsgBatchHelper::add(batch_, coreBatch_, msg); }
840 
841  MsgType & operator[](size_t index) { return *batch_[index]; }
842  const MsgType & operator[](size_t index) const { return *batch_[index]; }
843 
844  size_t size() const { return batch_.size(); }
845 
846  const_iterator begin() const { return batch_.begin(); }
847  iterator begin() { return batch_.begin(); }
848 
849  const_iterator end() const { return batch_.end(); }
850  iterator end() { return batch_.end(); }
851  };
852 
855  typedef FlatMessageBatch SerializedMessageBatch;
856 
857  /**
858  * Sends messages in a batch to the counterparty.
859  *
860  * As soon as a session is created, it is possible to start sending messages via the session.
861  * If the session is not established, the messages are stored in the session storage and will be sent in replay to the resend request
862  * when the connection is established with the counterparty and the sequence numbers mismatch is detected.
863  *
864  *@param msgs Message batch to send.
865  *@param maxPacketSize The maximum number of bytes written to the socket's send buffer together.
866  * This parameter could be used to reduce the probability that the operating system will fragment a FIX message across multiple TCP packets.
867  *
868  * @note The message batch should not be empty and maxPacketSize parameter should not be less than any message size in the batch.
869  * Otherwise, the method call can produce an error and the session can close the connection.
870  *
871  * @note This call is asynchronous.
872  *
873  * @note This call is thread-safe.
874  */
875  Session & send(MessageBatch & msgs, size_t maxPacketSize = (std::numeric_limits<size_t>::max)());
876  Session & send(FlatMessageBatch & msgs, size_t maxPacketSize = (std::numeric_limits<size_t>::max)());
877 
878  /**
879  * Sends serialized message(s) to the counterparty without any fields updating.
880  * One can use the preFill method to prepare message(s) for sending.
881  *
882  * As soon as a session is created, it is possible to start sending messages via the session.
883  * If the session is not established, the messages are stored in the session storage and will be sent in replay to the resend request
884  * when the connection is established with the counterparty and the sequence numbers mismatch is detected.
885  *
886  * @note This call is asynchronous.
887  *
888  * @note This call is thread-safe.
889  */
890  Session & sendAsIs(FlatMessage * msg);
891 
892  /**
893  * Sends serialized message(s) to the counterparty without any fields updating.
894  * One can use the preFill method to prepare message(s) for sending.
895  *
896  * As soon as a session is created, it is possible to start sending messages via the session.
897  * If the session is not established, the messages are stored in the session storage and will be sent in replay to the resend request
898  * when the connection is established with the counterparty and the sequence numbers mismatch is detected.
899  *
900  *@param msgs Message batch to send.
901  *@param maxPacketSize The maximum number of bytes written to the socket's send buffer together.
902  * This parameter could be used to reduce the probability that the operating system will fragment a FIX message across multiple TCP packets.
903  *
904  * @note The message batch should not be empty and maxPacketSize parameter should not be less than any message size in the batch.
905  * Otherwise, the method call can produce an error and the session can close the connection.
906  *
907  * @note This call is asynchronous.
908  *
909  * @note This call is thread-safe.
910  */
911  Session & sendAsIs(FlatMessageBatch & msgs, size_t maxPacketSize = (std::numeric_limits<size_t>::max)());
912 
913  /**
914  * Performs throttling of a session that must be called before each of a send function call.
915  * If the count of messages per a time unit exceeds a throttling limit, the function will be blocked until the given time interval is passed.
916  *
917  * @note This call is thread-safe.
918  */
919  Session & throttle();
920 
921  /**
922  * Sets throttling limit parameters.
923  *
924  *@param messagesCount Message limit per a time unit.
925  *@param intervalInMs Time interval to limit messages.
926  *
927  * @note This call is thread-safe.
928  */
929  Session & throttlingLimit(size_t messagesCount, size_t intervalInMs = 1000);
930 
931  /**
932  * This method warms up the sending path.
933  *
934  *@param msg Message to warm up the assembly part of the sending path.
935  *@param warmupFlags Specific flags which can be used to turn on the warmup feature for a specific NIC.
936 
937  * @note This call is thread-safe.
938  */
939  Session & warmUp(FlatMessage* msg, int warmupFlags = 0);
940 
941  /**
942  * Returns 'true' if given flags work as expected and a real data is not sent to the wire, otherwise - 'false'.
943  *
944  *@param warmupFlags Warmup flags for checking.
945  *@param baseListenPort Base listen port to use during the checking.
946  *@param localNetworkInterface IP address to bind for listen and outgoing test sockets.
947  *
948  * @note This call is thread-safe.
949  */
950  static bool checkWarmupFlags(int warmupFlags, unsigned short baseListenPort = 5000, const std::string & localNetworkInterface = "127.0.0.1");
951 
952  /**
953  * Pre-fills session-level fields that are constant during the session's lifetime - SenderCompId, TargetCompId, SenderLocationId, TargetLocationID, SenderSubID, TargetSubID.
954  *
955  * @note This call is thread-safe.
956  */
957  void preFill(Message & msg) const;
958 
959  /**
960  * Pre-fills the following fields in the message or messages batch for sending as is:
961  * - Session-level fields that are constant during the session's lifetime - SenderCompId, TargetCompId, SenderLocationId, TargetLocationI, SenderSubID, TargetSubID.
962  * - MsgSeqNum field in accordance with the session outgoing sequence number.
963  * - SendingTime field.
964  * - BodyLength and CheckSum fields.
965  *
966  * @note This call is thread-safe.
967  */
968  void preFill(FlatMessage & msg) const;
969  void preFill(FlatMessageBatch & msgs) const;
970 
971  /**
972  * Shutdowns the session.
973  *
974  * @note This call is thread-safe.
975  */
976  Session & shutdown();
977 
978  /**
979  * Returns the text description of this session.
980  *
981  * @note This call is thread-safe.
982  */
983  operator const std::string & () const;
984 
985  /**
986  * Returns the underlying storage Id.
987  *
988  * @note This call is thread-safe.
989  */
990  const std::string & storageId() const;
991 
992  /**
993  * Flushes all internal buffers of the underlying storage.
994  *
995  * @note This call is thread-safe.
996  */
997  Session & flushSessionStorage();
998 
999  /**
1000  * Returns the counterparty host name.
1001  *
1002  * @note The method performs a DNS request for the first time.
1003  * Therefore, it can block the thread execution for a long time until the DNS request is completed.
1004  *
1005  * @note This call is thread-safe.
1006  */
1007  std::string counterpartyHost() const;
1008 
1009  /**
1010  * Returns the counterparty address.
1011  *
1012  * @note This call is thread-safe.
1013  */
1014  std::string counterpartyIpAddress() const;
1015 
1016  /**
1017  * Returns the counterparty port number.
1018  *
1019  * @note This call is thread-safe.
1020  */
1021  size_t counterpartyPort() const;
1022 
1023  /**
1024  * Returns Session's Custom Key.
1025  *
1026  * @note This call is thread-safe.
1027  */
1028  const std::string & customKey() const;
1029 
1030  /**
1031  * Returns the total number of bytes in the outbound queue.
1032  *
1033  * @note This call is thread-safe.
1034  */
1035  size_t outboundQueueBytes() const;
1036 
1037  /**
1038  * Returns the Heartbeat interval (in seconds).
1039  */
1040  int heartbeatIntervalSec() const;
1041 
1042  /**
1043  * Returns 'true' if inbound messages are logged, otherwise - 'false'.
1044  * By default, the value is 'true'.
1045  */
1046  bool logInboundMessages() const;
1047 
1048  /**
1049  * Option to log inbound messages.
1050  */
1051  Session & logInboundMessages(bool value);
1052 
1053  /**
1054  * Returns 'true' if outbound messages are logged, otherwise - 'false'.
1055  * By default, the value is 'true'.
1056  */
1057  bool logOutboundMessages() const;
1058 
1059  /**
1060  * Option to log outbound messages.
1061  */
1062  Session & logOutboundMessages(bool value);
1063 
1064  /**
1065  * Incoming message types to be filtered out from the logs.
1066  */
1067  typedef std::set<std::string> InboundMessageLogFilter;
1068 
1069  /**
1070  * Returns incoming message types to be filtered out from the logs.
1071  *
1072  * @note This call is thread-safe.
1073  */
1074  InboundMessageLogFilter inboundMessageLogFilter() const;
1075 
1076  /**
1077  * Sets incoming message types to be filtered out from the logs.
1078  *
1079  * @note This call is thread-safe.
1080  */
1081  Session & inboundMessageLogFilter(const InboundMessageLogFilter & filter);
1082 
1083  /**
1084  * Outgoing message types to be filtered out from the logs.
1085  */
1086  typedef std::set<std::string> OutboundMessageLogFilter;
1087 
1088  /**
1089  * Returns outgoing message types to be filtered out from the logs.
1090  *
1091  * @note This call is thread-safe.
1092  */
1093  OutboundMessageLogFilter outboundMessageLogFilter() const;
1094 
1095  /**
1096  * Sets outgoing message types to be filtered out from the logs.
1097  *
1098  * @note This call is thread-safe.
1099  */
1100  Session & outboundMessageLogFilter(const OutboundMessageLogFilter & filter);
1101 
1102  /**
1103  * Returns 'true' if outbound messages are logged before sending, otherwise - 'false'.
1104  * By default, the value is 'true'.
1105  *
1106  * @note This call is thread-safe.
1107  */
1108  bool logBeforeSending() const;
1109 
1110  /**
1111  * Option to switch on/off logging of outbound messages before/after sending.
1112  *
1113  * @note This call is thread-safe.
1114  */
1115  Session & logBeforeSending(bool value);
1116 
1117  /**
1118  * Returns the expected sequence number of the next incoming message.
1119  *
1120  * @note This call is thread-safe.
1121  */
1122  SequenceNumber inSeqNum() const;
1123 
1124  /**
1125  * Sets the expected sequence number of the next incoming message.
1126  *
1127  * @note This call is thread-safe.
1128  */
1129  Session & inSeqNum(SequenceNumber seqNum);
1130 
1131  /**
1132  * Returns the sequence number of the next outgoing message.
1133  *
1134  * @note This call is thread-safe.
1135  */
1136  SequenceNumber outSeqNum() const;
1137 
1138  /**
1139  * Sets the sequence number of the next outgoing message.
1140  *
1141  * @note This call is thread-safe.
1142  */
1143  Session & outSeqNum(SequenceNumber seqNum);
1144 
1145  /**
1146  * Represents unlimited number of messages to be requested in one Resend Request (MsgType=2) message.
1147  * Default value is 0.
1148  */
1149  static const unsigned int ResendRequestMaximumRangeNoLimit;
1150 
1151  /**
1152  * Sets the maximum number of messages to be requested in one Resend Request (MsgType=2) message.
1153  *
1154  * @see Session::ResendRequestMaximumRangeNoLimit.
1155  *
1156  * @param range Maximum number of messages to be requested in one Resend Request (MsgType=2) message. Cannot be negative.
1157  *
1158  * @note This call is thread-safe.
1159  */
1160  Session & resendRequestMaximumRange(int range);
1161 
1162  /**
1163  * Returns the maximum number of messages to be requested in one Resend Request (MsgType=2) message.
1164  * By default, the value is zero (no limit).
1165  *
1166  * @see Session::ResendRequestMaximumRangeNoLimit.
1167  *
1168  * @note This call is thread-safe.
1169  */
1170  int resendRequestMaximumRange() const;
1171 
1172  /**
1173  * Sets the number of sent messages that are available for resending on counterparty's Resend Request <2> message.
1174  *
1175  * @note This call is thread-safe.
1176  */
1177  Session & resendingQueueSize(int value);
1178 
1179  /**
1180  * Returns the number of sent messages that are available for resending on counterparty's Resend Request <2> message.
1181  * By default value is -1 that means that the corresponding Engine setting's value is used ('1000' by default).
1182  *
1183  * @note This call is thread-safe.
1184  */
1185  int resendingQueueSize() const;
1186 
1187  /**
1188  * Returns the session role.
1189  *
1190  * @note This call is thread-safe.
1191  */
1192  SessionRole::Enum role() const;
1193 
1194  /**
1195  * Returns the assigned value used to identify firm sending message (the SenderCompID (tag 49) field value in outgoing messages).
1196  *
1197  * @note This call is thread-safe.
1198  */
1199  const std::string & senderCompId() const;
1200 
1201  /**
1202  * Returns 'true' if the LastMsgSeqNumProcessed (tag 369) field is specified on every message sent, otherwise - 'false'.
1203  * By default, the option value is false.
1204  */
1205  bool specifyLastMsgSeqNumProcessed() const;
1206 
1207  /**
1208  * Option to specify the LastMsgSeqNumProcessed (tag 369) field on every message sent.
1209  * Useful for detecting a backlog with a counterparty.
1210  *
1211  * @note Option does not affect the FlatMessage send.
1212  */
1213  Session & specifyLastMsgSeqNumProcessed(bool specify);
1214 
1215  /**
1216  * Returns 'true' if updating of SendingTime is turn on for every message, otherwise - 'false'.
1217  * By default, the option value is true.
1218  */
1219  bool updateSendingTimeField() const;
1220 
1221  /**
1222  * Option to specify updating of SendingTime of every sent message.
1223  */
1224  Session & updateSendingTimeField(bool specify);
1225 
1226  /**
1227  * Sets the time format of SendingTime of every sent message.
1228  * By default, the YYYYMMDDHHMMSSMsec format is used.
1229  */
1230  Session & sendingTimeFormat(TimestampFormat::Enum format);
1231 
1232  /**
1233  * Returns the Assigned value used to identify receiving firm (the TargetCompID (tag 56) field value in outgoing messages).
1234  *
1235  * @note This call is thread-safe.
1236  */
1237  const std::string & targetCompId() const;
1238 
1239  /**
1240  * Instance of the FIX dictionary or standard FIX messages dictionary which is used by the session.
1241  */
1242  Dictionary dictionary() const;
1243 
1244  /**
1245  * Returns the CPU affinity of the receiving thread.
1246  */
1247  const OnixS::Threading::CpuIndexes & receivingThreadAffinity() const;
1248 
1249  /**
1250  * Sets the CPU affinity of the receiving thread.
1251  */
1252  Session & receivingThreadAffinity(const OnixS::Threading::CpuIndexes & cpuIndexes);
1253 
1254  /**
1255  * Sets the CPU affinity of the receiving thread to a CPU.
1256  */
1257  Session & receivingThreadAffinity(const OnixS::Threading::CpuIndex cpuIndex);
1258 
1259  /**
1260  * Returns the CPU affinity of the sending thread.
1261  */
1262  const OnixS::Threading::CpuIndexes & sendingThreadAffinity() const;
1263 
1264  /**
1265  * Sets the CPU affinity index of the sending thread.
1266  */
1267  Session & sendingThreadAffinity(const OnixS::Threading::CpuIndexes & cpuIndexes);
1268 
1269  /**
1270  * Sets the CPU affinity index of the sending thread a CPU.
1271  */
1272  Session & sendingThreadAffinity(const OnixS::Threading::CpuIndex cpuIndex);
1273 
1274  /**
1275  * Represents undefined value of priority and policy.
1276  */
1277  static const int UndefinedPriorityAndPolicy;
1278 
1279  /**
1280  * Returns the priority of the receiving thread.
1281  */
1282  int receivingThreadPriority() const;
1283 
1284  /**
1285  * Sets the priority of the receiving thread.
1286  */
1287  Session & receivingThreadPriority(int priority);
1288 
1289  /**
1290  * Returns the priority of the sending thread.
1291  */
1292  int sendingThreadPriority() const;
1293 
1294  /**
1295  * Sets the priority of the sending thread.
1296  */
1297  Session & sendingThreadPriority(int priority);
1298 
1299  /**
1300  * Returns the scheduling policy of the receiving thread.
1301  */
1302  int receivingThreadPolicy() const;
1303 
1304  /**
1305  * Sets the scheduling policy of the receiving thread.
1306  */
1307  Session & receivingThreadPolicy(int policy);
1308 
1309  /**
1310  * Returns the scheduling policy of the sending thread.
1311  */
1312  int sendingThreadPolicy() const;
1313 
1314  /**
1315  * Sets the scheduling policy of the sending thread.
1316  */
1317  Session & sendingThreadPolicy(int policy);
1318 
1319  /**
1320  * Returns the sent message if it can be found by the given message sequence number, otherwise - NULL.
1321  *
1322  * @note This call is thread-safe.
1323  */
1324  Message * findSentMessage(SequenceNumber messageSequenceNumber);
1325  FlatMessage * findSentFlatMessage(SequenceNumber messageSequenceNumber);
1326 
1327  /**
1328  * When the message gap is detected the "Resend Request" FIX Message is sent and Session state is changed to "AwaitReplyOnResendRequest".
1329  * By default in this state the incoming new messages (without the PossDupFlag (tag #43) flag) are ignored because we expect them to be re-sent later again with the PossDupFlag flag.
1330  *
1331  * This property allows to change this behavior and report the new messages anyway.
1332  *
1333  * @note In this mode messages could be reported out of the original order: e.g. MsgSeqNum could be: 3 (original), 4 (original), 2 (PossDupFlag='Y'), 3 (PossDupFlag='Y'), 4 (PossDupFlag='Y')
1334  * and some messages could be received two times: first time without PossDupFlag='Y' and second time - with this flag.
1335  */
1336  Session & reportNewMessagesWhileWaitingForMissedMessages(bool report);
1337 
1338  /**
1339  * Returns 'true' if the new messages are reported even when the message gap is detected and the reply on the "Resend Request" message is expected, otherwise - 'false'.
1340  */
1341  bool reportNewMessagesWhileWaitingForMissedMessages() const;
1342 
1343  /**
1344  * By default the "Resend Request" message is sent only once - when the first gap is detected.
1345  * This property allows to change this behavior and send the "Resend Request" message on each detected message sequence number gap.
1346  */
1347  Session & sendResendRequestOnEachMessageGap(bool send);
1348 
1349  /**
1350  * Returns 'true' if the "Resend Request" message is sent on each detected message sequence number gap, otherwise - 'false'.
1351  */
1352  bool sendResendRequestOnEachMessageGap() const;
1353 
1354  /**
1355  * By default the "Resend Request" message requests all messages begin from the first missed one.
1356  * This property allows to change this behavior and request only missed messages.
1357  *
1358  * @note This method can be called only when the session is disconnected.
1359  */
1360  Session & requestOnlyMissedMessages(bool request);
1361 
1362  /**
1363  * Returns 'true' if the "Resend Request" message requests only missed messages, otherwise - 'false'.
1364  */
1365  bool requestOnlyMissedMessages() const;
1366 
1367  /**
1368  * By default if the "Session Level Reject" message is received in replay to the "Resend Request" then this is considered as a serious problem and the FIX connection will be closed.
1369  * This property allows to change this behavior and consider the "Session Level Reject" on the "Resend Request" as the "Sequence Reset Gap Fill" message.
1370  */
1371  Session & considerRejectOnResendRequestAsGapFill(bool consider);
1372 
1373  /**
1374  * Returns 'true' if the "Reject" on the "Resend Request" is considered as the "Sequence Reset Gap Fill" message, otherwise - 'false'.
1375  */
1376  bool considerRejectOnResendRequestAsGapFill() const;
1377 
1378  /**
1379  * By default if the incoming message has a sequence number less than expected and the PossDupFlag is not set, it indicates
1380  * a serious error and leads to FIX connection closing.
1381  * This property allows to change this behavior and consider the sequence number of the incoming message, which less than expected, as an expected one.
1382  */
1383  Session & ignoreLessThanExpectedSequenceNumber(bool ignore);
1384 
1385  /**
1386  * Returns 'true' if the sequence number of the incoming message, which less than expected, is considered as an expected one, otherwise - 'false'.
1387  */
1388  bool ignoreLessThanExpectedSequenceNumber() const;
1389 
1390  /**
1391  * Option to automatically reset the local sequence numbers to 1 during every logon.
1392  */
1393  Session & resetLocalSequenceNumbersOnLogon(bool reset);
1394 
1395  /**
1396  * Returns 'true' if local sequence numbers are reset automatically to 1 during every logon, otherwise - 'false'.
1397  */
1398  bool resetLocalSequenceNumbersOnLogon() const;
1399 
1400  /**
1401  * If requestOnlyMissedMessages option is true and the sequence number of an incoming FIX message
1402  * greater that expected then the resend functionality is run and this incoming message is stored
1403  * in the incoming message gap queue for further processing.
1404  * This property allows to set maximum size of that queue.
1405  */
1406  Session & incomingMessageGapQueueMaximumSize(size_t maxSize);
1407 
1408  /**
1409  * Returns maximum size of the incoming message gap queue.
1410  * By default, the value equal to 1000.
1411  */
1412  size_t incomingMessageGapQueueMaximumSize() const;
1413 
1414  /**
1415  * Registers the Session listener.
1416  *
1417  * @throw Exception if the listener is already registered.
1418  */
1419  Session & registerListener(ISessionListener * listener);
1420 
1421  /**
1422  * Un-registers the Session listener.
1423  */
1424  Session & unregisterListener(ISessionListener * listener);
1425 
1426  /**
1427  * Un-registers all Session listener.
1428  */
1429  Session & unregisterAllListeners();
1430 
1431  /**
1432  * Backups the current log files and resets the local sequence numbers to 1.
1433  *
1434  * @note This method can be called only when the session is disconnected.
1435  *
1436  * @note This call is thread-safe.
1437  */
1438  Session & resetLocalSequenceNumbers();
1439 
1440  /**
1441  * Sends a Logon message with the ResetSeqNumFlag set.
1442  *
1443  * @note This call is thread-safe.
1444  */
1445  Session & resetSeqNumViaLogonExchange();
1446 
1447  /**
1448  * Returns the SenderSubID (tag 50) field values for all outgoing messages.
1449  *
1450  * @note This call is thread-safe.
1451  */
1452  std::string senderSubId() const;
1453 
1454  /**
1455  * Sets the SenderSubID (tag 50) field values for all outgoing messages.
1456  *
1457  * @note This call is thread-safe.
1458  */
1459  Session & senderSubId(const std::string & value);
1460 
1461  /**
1462  * Returns the TargetSubID (tag 57) field values for all outgoing messages.
1463  *
1464  * @note This call is thread-safe.
1465  */
1466  std::string targetSubId() const;
1467 
1468  /**
1469  * Sets the TargetSubID (tag 57) field values for all outgoing messages.
1470  *
1471  * @note This call is thread-safe.
1472  */
1473  Session & targetSubId(const std::string & value);
1474 
1475  /**
1476  * Returns the SenderLocationID (tag 142) field values for all outgoing messages.
1477  *
1478  * @note This call is thread-safe.
1479  */
1480  std::string senderLocationId() const;
1481 
1482  /**
1483  * Sets the SenderLocationID (tag 142) field values for all outgoing messages.
1484  *
1485  * @note This call is thread-safe.
1486  */
1487  Session & senderLocationId(const std::string & value);
1488 
1489  /**
1490  * Returns the TargetLocationID (tag 143) field values for all outgoing messages.
1491  *
1492  * @note This call is thread-safe.
1493  */
1494  std::string targetLocationId() const;
1495 
1496  /**
1497  * Sets the TargetLocationID (tag 143) field values for all outgoing messages.
1498  *
1499  * @note This call is thread-safe.
1500  */
1501  Session & targetLocationId(const std::string & value);
1502 
1503  /**
1504  * Options to turn on/off incoming message sequence numbers validation.
1505  */
1506  Session & validateSequenceNumbers(bool value);
1507 
1508  /**
1509  * Returns the current status of incoming message sequence numbers validation.
1510  * By default the option value is true.
1511  */
1512  bool validateSequenceNumbers() const;
1513 
1514  /**
1515  * Returns the thread name suffix for receiving (R:threadNameSuffix) and sending (S:threadNameSuffix) threads.
1516  *
1517  * @note This call is thread-safe.
1518  */
1519  std::string threadNameSuffix() const;
1520 
1521  /**
1522  * Sets the thread name suffix for receiving ("R:threadNameSuffix") and sending ("S:threadNameSuffix") threads.
1523  **
1524  * If threadNameSuffix is not specified, it is set by default to ("R:senderCompId-targetCompId")("S:senderCompId-targetCompId").
1525  **
1526  * @note This method can be called only when the session is disconnected.
1527  * @throw Exception if the session state is not Disconnected.
1528  *
1529  * @note This call is thread-safe.
1530  */
1531  Session & threadNameSuffix(const std::string & value);
1532 
1533  /**
1534  * Sends the Test Request (MsgType 1) message.
1535  *
1536  * @note This call is thread-safe.
1537  */
1538  Session & sendTestRequest(const std::string & testReqId = "");
1539 
1540  /**
1541  * Sends the Resend Request (MsgType 2) message.
1542  *
1543  * @note Normally, "Resend Request" message is sent automatically. This method allows to simulate a sequence gap by sending this message manually.
1544  * This can be needed in some venue specific cases. This method should not be used in the normal work.
1545  *
1546  * @param beginSeqNumber Begin sequence number of the first requested message in the range.
1547  *
1548  * @note This call is thread-safe.
1549  */
1550  Session & sendResendRequest(SequenceNumber beginSeqNumber);
1551 
1552  /**
1553  * Sends the Reject (MsgType 3) message.
1554  *
1555  * @param refSeqNumber MsgSeqNum of rejected message.
1556  * @param text Message to explain the reason for rejection.
1557  *
1558  * @note This call is thread-safe.
1559  */
1560  Session & sendReject(SequenceNumber refSeqNumber, const std::string & text);
1561 
1562  /**
1563  * Returns the time when logical session was created or last sequence number reset operation was performed.
1564  * Originating value is extracted from attached storage using ISessionStorage::sessionCreationTime() method.
1565  *
1566  * @note This call is thread-safe.
1567  */
1568  Timestamp creationTime() const;
1569 
1570  /**
1571  * Returns the session string presentation.
1572  *
1573  * @note This call is thread-safe.
1574  */
1575  std::string toString() const;
1576 
1577  /**
1578  * Represents invalid value of socket handle.
1579  */
1581 
1582  /**
1583  * Returns the socket handle which the session uses to transmit FIX data.
1584  *
1585  * @note This call is thread-safe.
1586  */
1587  OnixS::Sockets::Handle socketHandle();
1588 
1589  /**
1590  * Additional options, which should be set to the session socket when it is created.
1591  * For initiator sessions, options are set before socket connect(..) call.
1592  * For acceptor sessions, options are set after socket accept(..) call.
1593  */
1594  Session & socketOptions(const OnixS::Sockets::SocketOptions & options);
1595 
1596  /**
1597  * Inbound and outbound messages, session's state data are stored in this directory.
1598  *
1599  * @note This method can be called only when the session is disconnected.
1600  * @throw Exception if the session state is not Disconnected.
1601  *
1602  * @note This call is thread-safe.
1603  */
1604  Session & logDirectory(const std::string & value);
1605 
1606  /**
1607  * Inbound and outbound messages, session's state data are stored in this directory.
1608  *
1609  * @note This call is thread-safe.
1610  */
1611  const std::string & logDirectory() const;
1612 
1613  /**
1614  * Sets the timeout during which counterparty should send a reply to the "Resend Request" message.
1615  * If a counterparty does not reply during this timeout, then the ISessionListener::onWarning is called.
1616  * By default, the resend request timeout equal to zero, which means an infinite timeout.
1617  *
1618  * @note The resend timeout is checked when an incoming message is received or when the receive timeout is elapsed.
1619  * Therefore, the actual timeout can be greater than the specified one or can be rounded to the value equal to the heartbeat interval + reasonable transmission time.
1620  *
1621  * @note This call is thread-safe.
1622  */
1623  Session & resendTimeout(const TimeSpan & timeout);
1624 
1625  /**
1626  * Returns the timeout during which counterparty should send a reply to the "Resend Request" message.
1627  *
1628  * @note This call is thread-safe.
1629  */
1630  TimeSpan resendTimeout() const;
1631 
1632  /**
1633  * Option to scramble the Password (tag=554) field value in Logon(A) message, in the session storage, for the security reasons.
1634  * By default the option value is false.
1635  */
1636  Session & scramblePassword(bool scramble);
1637 
1638  /**
1639  * Returns 'true' if the Password (tag=554) field value in Logon(A) message is scrambled, otherwise - 'false'.
1640  */
1641  bool scramblePassword() const;
1642 
1643  /**
1644  * Schedule the memory usage optimization.
1645  * The session will perform the actual memory usage optimization after receiving and processing the next incoming message.
1646  */
1647  void scheduleShrinkToFit();
1648 
1649  /**
1650  * HTTP proxy settings.
1651  */
1653  {
1655  :host(), port(), username(), password()
1656  {}
1657 
1658  ProxySettings(const std::string & proxyHost, int proxyPort, const std::string & proxyUsername = std::string(), const std::string & proxyPassword = std::string())
1659  :host(proxyHost), port(proxyPort), username(proxyUsername), password(proxyPassword)
1660  {}
1661 
1662  std::string host;
1663  int port;
1664  std::string username;
1665  std::string password;
1666  };
1667 
1668  /**
1669  * Sets HTTP proxy settings.
1670  */
1671  Session & proxySettings(const ProxySettings & settings);
1672 
1673  /**
1674  * Returns HTTP proxy settings.
1675  */
1676  ProxySettings proxySettings() const;
1677 
1678  /**
1679  * Returns the session message mode.
1680  */
1681  MessageMode::Enum messageMode() const;
1682 
1683  /**
1684  * Sets the session message mode.
1685  */
1686  void messageMode(MessageMode::Enum mode);
1687 
1688  struct Impl; ///< Implementation details.
1689 
1690 private:
1691  void init(
1692  const std::string & senderCompId,
1693  const std::string & targetCompId,
1694  const Dictionary & dictionary,
1695  ISessionListener * listener,
1696  bool keepSequenceNumbersAfterLogout,
1697  SessionStorageType::Enum storageType,
1698  ISessionStorage * storage,
1699  const std::string & customSessionKey,
1700  ISessionReactor * reactor);
1701 
1702  Impl * impl_;
1703 
1704  friend class Engine::Impl;
1705 };
1706 
1707 /// Stream output.
1709 std::ostream & operator << (std::ostream & os, const Session & session);
1710 }
1711 }
FIX Session - a bi-directional stream of ordered messages between two parties within a continuous seq...
Definition: Session.h:99
File based storage. Session&#39;s state and messages are persisted to the file system.
ONIXS_FIXENGINE_API std::ostream & operator<<(std::ostream &os, const Group &group)
Stream output.
Traits::MsgBatchType::iterator iterator
Definition: Session.h:833
MsgType & operator[](size_t index)
Definition: Session.h:841
std::set< std::string > InboundMessageLogFilter
Incoming message types to be filtered out from the logs.
Definition: Session.h:1067
static const OnixS::Sockets::Handle InvalidSocketHandle
Represents invalid value of socket handle.
Definition: Session.h:1580
const_iterator begin() const
Definition: Session.h:846
size_t CpuIndex
Logical processors that a thread is allowed to run on (first logical CPU has index 0)...
Definition: Thread.h:31
int Handle
Type alias for socket handle.
Definition: Definitions.h:46
std::set< std::string > OutboundMessageLogFilter
Outgoing message types to be filtered out from the logs.
Definition: Session.h:1086
size_t size() const
Definition: Session.h:844
Session&#39;s Listener.
FlatMessageBatch SerializedMessageBatch
Definition: Session.h:855
std::vector< OnixS::FIX::Core::Messaging::Message * > CoreMsgBatchType
Definition: Session.h:89
const MsgType & operator[](size_t index) const
Definition: Session.h:842
#define ONIXS_FIXENGINE_API
Definition: ABI.h:45
HTTP proxy settings.
Definition: Session.h:1652
const_iterator end() const
Definition: Session.h:849
PtrTraits< Message >::UniquePtr MessagePtr
Definition: Session.h:87
Provides access to FIX fields from a flat (tag=value) message.
Definition: FlatMessage.h:52
Message batch types.
Definition: Session.h:800
A high-level wrapper over the TCPDirect stack.
ProxySettings(const std::string &proxyHost, int proxyPort, const std::string &proxyUsername=std::string(), const std::string &proxyPassword=std::string())
Definition: Session.h:1658
std::set< CpuIndex > CpuIndexes
Definition: Thread.h:32
MsgBatch< FlatMessage > FlatMessageBatch
Definition: Session.h:854
Identifies FIX messages dictionary.
Definition: Dictionary.h:73
std::vector< Message * > MsgBatchType
Definition: Session.h:88
static const int UndefinedPriorityAndPolicy
Represents undefined value of priority and policy.
Definition: Session.h:1277
Traits::MsgBatchType::const_iterator const_iterator
Definition: Session.h:834
Session message mode.
Definition: Session.h:60
ONIXS_FIXENGINE_API_DECL(class, IEngineListener)
std::pair< unsigned short, unsigned short > LocalPortRange
Local port range type.
Definition: Session.h:301
PtrTraits< MsgType >::UniquePtr MessagePtr
Definition: Session.h:79
Time span related functionality.
Definition: TimeSpan.h:93
std::vector< FlatMessage * > MsgBatchType
Definition: Session.h:80
MsgBatch< Message > MessageBatch
Definition: Session.h:853
Session&#39;s pluggable storage.
Session&#39;s network stack reactor interface.
unsigned int SequenceNumber
Alias for sequence mumber.
std::vector< OnixS::FIX::Core::Messaging::Extras::FlatMessage * > CoreMsgBatchType
Definition: Session.h:81
Represents a future result of an asynchronous operation - a result that will eventually appear in the...
Definition: Future.h:253
Encapsulates operations over a FIX Message.
Definition: Message.h:49
std::vector< SocketOption > SocketOptions
Storage type of socket options.
Definition: Definitions.h:63
std::auto_ptr< T > UniquePtr
Definition: Definitions.h:32
Traits::MessagePtr MessagePtr
Definition: Session.h:832
void add(MessagePtr &msg)
Definition: Session.h:839
Timestamps related functionality.
Definition: Timestamp.h:91
static const unsigned int ResendRequestMaximumRangeNoLimit
Represents unlimited number of messages to be requested in one Resend Request (MsgType=2) message...
Definition: Session.h:1149