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