OnixS C++ CME iLink 3 Binary Order Entry Handler  1.18.11
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 <limits.h>
23 
24 #include <OnixS/CME/iLink3/ABI.h>
33 
34 namespace OnixS
35 {
36 namespace CME
37 {
38 namespace iLink3
39 {
40 // Forward declarations
41 class TcpDirectStack;
42 namespace AdHoc { struct SessionHelper; };
43 
44 /**
45 * An iLink 3 Session.
46 */
48 {
49 public:
50  static const UInt64 UndefinedUuid = 0;
51 
52  /**
53  * Constructor.
54  *
55  * \param settings Session settings.
56  * \param marketSegmentId Market segment ID.
57  * \param listener Session listener.
58  * \param storageType Session storage type.
59  * \param storage Session storage.
60  * \param uuid Universally Unique Identifier (UUID).
61  * \param customKey Custom key that could be used to distinguish sessions with the same UUID, Session ID, FirmId, and Market Segment ID values.
62  */
63  Session(const SessionSettings &settings, int marketSegmentId,
65  SessionStorage *storage = ONIXS_ILINK3_NULLPTR, UInt64 uuid = UndefinedUuid, const std::string &customKey = "");
66 
67  Session(SessionReactor & stack, const SessionSettings & settings, int marketSegmentId,
69  SessionStorage * storage = ONIXS_ILINK3_NULLPTR, UInt64 uuid = UndefinedUuid, const std::string &customKey = "");
70 
71  ~Session();
72 
73  /// \return the Universally Unique Identifier (UUID).
74  UInt64 uuid() const ONIXS_ILINK3_NOTHROW;
75 
76  /// \return Session ID (assigned by the exchange).
77  std::string id() const;
78 
79  /// \return Market Segment ID.
80  int marketSegmentId() const ONIXS_ILINK3_NOTHROW;
81 
82  /// \return Custom key that could be used to distinguish sessions with the same UUID, Session ID, FirmId, and Market Segment ID values.
83  std::string customKey() const;
84 
85  /// \return `true` if the session is negotiated (the Negotiation Response message has been received in reply to the Negotiation message); otherwise - `false`.
86  bool negotiated() const;
87 
88  /// Sets the "negotiated" status.
89  ///
90  /// The session is negotiated when the Negotiation Response message has been received in reply to the Negotiation message.
91  Session& negotiated(bool negotiated);
92 
93  /// \return the Fault Tolerance Indicator (whether the connection is the primary or backup).
94  Messaging::FTI::Enum faultToleranceIndicator() const;
95 
96  /// Sets the Fault Tolerance Indicator (whether the connection is the primary or backup).
97  Session& faultToleranceIndicator(Messaging::FTI::Enum value);
98 
99  /**
100  * Establishes the connection.
101  *
102  * \param host Market Segment Gateway host.
103  * \param port Market Segment Gateway port.
104  *
105  * \return This session.
106  */
107  Session& connect(const std::string &host, Port port);
108 
109  /**
110  * Establishes the connection asynchronously.
111  *
112  * \param host Market Segment Gateway host.
113  * \param port Market Segment Gateway port.
114  */
115  Threading::SharedFuture<void> connectAsync(const std::string & host, Port port);
116 
117  /**
118  * Terminates the connection.
119  *
120  * \param reason Terminate reason details.
121  *
122  * \note Method blocks until the Terminate message is received in reply, or the timeout is elapsed.
123  *
124  * \return This session.
125  */
126  Session& disconnect(const std::string &reason = "");
127 
128  /**
129  * Terminates the connection asynchronously.
130  *
131  * \param reason Terminate reason details.
132  */
133  Threading::SharedFuture<void> disconnectAsync(const std::string & reason = "");
134 
135  /**
136  * Breaks the connection non-gracefully.
137  * \return This session.
138  */
139  Session& breakConnection();
140 
141  /**
142  * Breaks the connection non-gracefully asynchronously.
143  */
144  Threading::SharedFuture<void> breakConnectionAsync();
145 
146  /**
147  * Sends the message.
148  *
149  * \param sendingTime The time value to be used for a `sendingTimeEpoch` field of the message(s) being sent.
150  * \param msg The message to be sent.
151  *
152  * \note This call is thread-safe, except for the TCPDirect mode.
153  *
154  * \return This session.
155  */
156  template <typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
157  Session& send(
158  Messaging::MessageHolder<SbeMessageType, MaxMessageSize, MessageInitializer> &msg,
159  Messaging::Timestamp sendingTime = UtcWatch::now());
160 
161 #if defined (ONIXS_ILINK3_CXX11)
162 
163  /**
164  * Sends the message.
165  * \param sendingTime The time value to be used for a `sendingTimeEpoch` field of the message(s) being sent.
166  * \param msg The message to be sent.
167  *
168  * \note This call is thread-safe, except for the TCPDirect mode.
169  *
170  * \return This session.
171  */
172  template <typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
173  Session& send(
175  Messaging::Timestamp sendingTime = UtcWatch::now());
176 
177 #endif
178 
179  /// CME states: Packet size maximum behavior based on MTU (Maximum Transmission Unit) - 1420 bytes, as defined on our network.
180  static const size_t CmeMaxPacketSize = 1420;
181 
182 #if defined (ONIXS_ILINK3_CXX11)
183 
184  /**
185  * Sends messages.
186  *
187  * \note This call is thread-safe.
188  *
189  * \param msgs Message batch to send.
190  * \param maxPacketSize The maximum number of bytes written to the socket's send buffer together.
191  * This parameter could be used to reduce the probability that the operating system will fragment the message across multiple TCP packets.
192  * \param sendingTime The time value to be used for a `sendingTimeEpoch` field of the message(s) being sent.
193  *
194  * \note The maxPacketSize parameter should not be less than any message size in the batch.
195  * Otherwise, the method call can produce an error, and the session can close the connection.
196  *
197  * \return This session.
198  */
199  template <typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
200  Session& send(
202  Messaging::Timestamp sendingTime = UtcWatch::now(),
203  size_t maxPacketSize = CmeMaxPacketSize);
204 
205  /**
206  * Sends messages.
207  *
208  * \note This call is thread-safe.
209  *
210  * \param msgs Message batch combiner to send.
211  * \param maxPacketSize The maximum number of bytes written to the socket's send buffer together.
212  * This parameter could be used to reduce the probability that the operating system will fragment the message across multiple TCP packets.
213  * \param sendingTime The time value to be used for a `sendingTimeEpoch` field of the message(s) being sent.
214  *
215  * \note The maxPacketSize parameter should not be less than any message size in the batch.
216  * Otherwise, the method call can produce an error, and the session can close the connection.
217  *
218  * \return This session.
219  */
220  Session& send(
221  MessageBatchCombiner & msgs,
222  Messaging::Timestamp sendingTime = UtcWatch::now(),
223  size_t maxPacketSize = CmeMaxPacketSize);
224 
225 #endif
226 
227  /**
228  * Sends messages.
229  *
230  * \note This call is thread-safe.
231  *
232  * \param begin Message range begin.
233  * \param end Message range end.
234  * \param maxPacketSize The maximum number of bytes written to the socket's send buffer together.
235  * This parameter could be used to reduce the probability that the operating system will fragment the message across multiple TCP packets.
236  * \param sendingTime The time value to be used for a `sendingTimeEpoch` field of the message(s) being sent.
237  *
238  * \note The maxPacketSize parameter should not be less than any message size in the batch.
239  * Otherwise, the method call can produce an error, and the session can close the connection.
240  * \return This session.
241  */
242  Session& send(
243  NetworkMessage* begin, NetworkMessage* end,
244  Messaging::Timestamp sendingTime = UtcWatch::now(),
245  size_t maxPacketSize = CmeMaxPacketSize) ONIXS_ILINK3_NONULL;
246 
247  /**
248  * Sends messages.
249  *
250  * \note This call is thread-safe.
251  *
252  * \param range Message range to send.
253  * \param maxPacketSize The maximum number of bytes written to the socket's send buffer together.
254  * This parameter could be used to reduce the probability that the operating system will fragment the message across multiple TCP packets.
255  * \param sendingTime The time value to be used for a `sendingTimeEpoch` field of the message(s) being sent.
256  *
257  * \note The maxPacketSize parameter should not be less than any message size in the batch.
258  * Otherwise, the method call can produce an error, and the session can close the connection.
259  *
260  * \return This session.
261  */
262  Session& send(
263  NetMessagesRange range,
264  Messaging::Timestamp sendingTime = UtcWatch::now(),
265  size_t maxPacketSize = CmeMaxPacketSize);
266 
267  /**
268  * Send the Sequence message.
269  *
270  * \note The session sends Sequence messages automatically per the CME iLink protocol.
271  * This method should be used only if an ad hoc Sequence message is required
272  * and the connection is established.
273  *
274  * \param keepAliveLapsed Indicates whether one Keep Alive interval has lapsed without any message received.
275  *
276  * \return This session.
277  */
278  Session& sendSequenceMessage(Messaging::KeepAliveLapsed::Enum keepAliveLapsed = Messaging::KeepAliveLapsed::Lapsed);
279 
280  /**
281  * Warms up the sending path.
282  *
283  * \param msg SBE message to warm up the sending path.
284  * \param warmupFlags Specific flags which can be used to turn on the warmup feature for a specific NIC.
285  * \param sendingTime The time value to be used for a `sendingTimeEpoch` field of the message(s) being sent.
286  *
287  * \note This call is thread-safe, except for the TCPDirect mode.
288  *
289  * \return This session.
290  */
291  template <typename SbeMessageType, size_t MaxMessageSize>
292  Session& warmUp(
293  Messaging::MessageHolder<SbeMessageType, MaxMessageSize> &msg,
294  Messaging::Timestamp sendingTime = UtcWatch::now(),
295  int warmupFlags = 0);
296 
297 
298 #if defined (ONIXS_ILINK3_CXX11)
299 
300  /**
301  * Warms up the sending path.
302  *
303  * \note This call is thread-safe.
304  *
305  * \param msgs Message batch to send.
306  * \param maxPacketSize The maximum number of bytes written to the socket's send buffer together during the subsequent `send` call.
307  * \param sendingTime The time value to be used for a `sendingTimeEpoch` field of the message(s) being sent.
308  * \param warmupFlags Specific flags which can be used to turn on the warmup feature for a specific NIC.
309  *
310  * \note The maxPacketSize parameter should not be less than any message size in the batch.
311  * Otherwise, the method call can produce an error, and the session can close the connection.
312  *
313  * \return This session.
314  */
315  template <typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
316  Session& warmUp(
318  Messaging::Timestamp sendingTime = UtcWatch::now(),
319  size_t maxPacketSize = CmeMaxPacketSize,
320  int warmupFlags = 0);
321 
322  /**
323  * Warms up the sending path.
324  *
325  * \note This call is thread-safe.
326  *
327  * \param msgs Message batch combiner to send.
328  * \param maxPacketSize The maximum number of bytes written to the socket's send buffer together during the subsequent `send` call.
329  * \param sendingTime The time value to be used for a `sendingTimeEpoch` field of the message(s) being sent.
330  * \param warmupFlags Specific flags which can be used to turn on the warmup feature for a specific NIC.
331  *
332  * \note The maxPacketSize parameter should not be less than any message size in the batch.
333  * Otherwise, the method call can produce an error, and the session can close the connection.
334  *
335  * \return This session.
336  */
337  Session& warmUp(
339  size_t maxPacketSize = CmeMaxPacketSize, int warmupFlags = 0);
340 #endif
341 
342  /**
343  * Warms up the sending path.
344  *
345  * \note This call is thread-safe.
346  *
347  * \param begin Message range begin.
348  * \param end Message range end.
349  * \param maxPacketSize The maximum number of bytes written to the socket's send buffer together during the subsequent `send` call.
350  * \param sendingTime The time value to be used for a `sendingTimeEpoch` field of the message(s) being sent.
351  * \param warmupFlags Specific flags which can be used to turn on the warmup feature for a specific NIC.
352  *
353  * \note The maxPacketSize parameter should not be less than any message size in the batch.
354  * Otherwise, the method call can produce an error, and the session can close the connection.
355  *
356  * \return This session.
357  */
358  Session& warmUp(
359  NetworkMessage* begin, NetworkMessage* end, Messaging::Timestamp sendingTime = UtcWatch::now(),
360  size_t maxPacketSize = CmeMaxPacketSize, int warmupFlags = 0) ONIXS_ILINK3_NONULL;
361 
362  /**
363  * Warms up the sending path.
364  *
365  * \note This call is thread-safe.
366  *
367  * \param range Message range.
368  * \param maxPacketSize The maximum number of bytes written to the socket's send buffer together during the subsequent `send` call.
369  * \param sendingTime The time value to be used for a `sendingTimeEpoch` field of the message(s) being sent.
370  * \param warmupFlags Specific flags which can be used to turn on the warmup feature for a specific NIC.
371  *
372  * \note The maxPacketSize parameter should not be less than any message size in the batch.
373  * Otherwise, the method call can produce an error, and the session can close the connection.
374  *
375  * \return This session.
376  */
377  Session& warmUp(
378  NetMessagesRange range, Messaging::Timestamp sendingTime = UtcWatch::now(),
379  size_t maxPacketSize = CmeMaxPacketSize, int warmupFlags = 0);
380 
381 
382  /**
383  * Performs the throttling of a session that must be called before each send function call.
384  * If the count of messages per time unit exceeds the throttling limit, the function will be blocked until the given time interval is passed.
385  *
386  * \note This call is thread-safe.
387  */
388  Session& throttle();
389 
390  /**
391  * Checks the throttling of a session that must be called before each send function call.
392  * 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.
393  *
394  * \note This call is thread-safe.
395  */
396  size_t tryThrottle();
397 
398  /**
399  * Sets throttling limit parameters.
400  *
401  * \param messagesCount Message limit per time unit.
402  * \param intervalInMs Time interval to limit messages.
403  *
404  * \note This call is thread-safe.
405  */
406  Session & throttlingLimit(size_t messagesCount, size_t intervalInMs = 1000);
407 
408  /// \return the host name the session is connected to.
409  std::string remoteHost() const;
410 
411  /// \return the IP address the session is connected to.
412  std::string remoteIpAddress() const;
413 
414  /// \return the port number the session is connected to.
415  Port remotePort() const;
416 
417  /// \return the local port range
418  std::pair<Port, Port> localPortRange() const ONIXS_ILINK3_NOTHROW;
419 
420  /// Sets the local port range
421  Session& localPortRange(std::pair<Port, Port> portRange);
422 
423  /// \return the IP Address or name of the local network interface.
424  std::string localNetworkInterface() const;
425 
426  /// Sets the IP Address or name of the local network interface.
427  Session& localNetworkInterface(const std::string &value);
428 
429  /// \return the local network port number.
430  Port localPort() const;
431 
432  /// \return the value of the `TCP_NODELAY` option (improve latency at the expense of message throughput).
433  bool tcpNoDelayOption() const;
434 
435  /// Sets the `TCP_NODELAY` option (improve latency at the expense of message throughput).
436  Session& tcpNoDelayOption(bool value);
437 
438  /// \return Socket options.
439  const SocketOptions &socketOptions() const;
440 
441  /// Sets socket options.
442  Session& socketOptions(const SocketOptions &options);
443 
444  static const int UndefinedAffinity = -1;
445 
446  /// Sets the receiving thread CPU affinity.
447  Session& receivingThreadAffinity(CpuIndex cpuIndex);
448 
449  /// \return the receiving thread CPU affinity.
450  Session& receivingThreadAffinity(const CpuIndexes &cpuIndexes);
451 
452  /// Sets the receiving thread CPU affinity.
453  const CpuIndexes &receivingThreadAffinity() const;
454 
455  /// Sets the sending thread CPU affinity.
456  Session& sendingThreadAffinity(CpuIndex cpuIndex);
457 
458  /// Sets the sending thread CPU affinity.
459  Session& sendingThreadAffinity(const CpuIndexes &cpuIndexes);
460 
461  /// \return the auxiliary sending thread CPU affinity.
462  const CpuIndexes &sendingThreadAffinity() const;
463 
464  /// \return the scheduling priority of the receiving thread.
465  int receivingThreadPriority() const;
466 
467  /// Sets the scheduling priority of the receiving thread.
468  Session& receivingThreadPriority(int priority);
469 
470  /// \return the scheduling priority of the sending thread.
471  int sendingThreadPriority() const;
472 
473  /// \return the scheduling priority of the sending thread.
474  Session& sendingThreadPriority(int priority);
475 
476  /// \return the receiving thread policy.
477  int receivingThreadPolicy() const;
478 
479  /// Sets the receiving thread policy.
480  Session& receivingThreadPolicy(int policy);
481 
482  /// Sets the sending thread policy.
483  int sendingThreadPolicy() const;
484 
485  /// \return the sending thread policy.
486  Session& sendingThreadPolicy(int policy);
487 
488  /// \return the receive spinning timeout value (in microseconds).
489  unsigned receiveSpinningTimeout() const ONIXS_ILINK3_NOTHROW;
490 
491  /// Sets the receive spinning timeout value (in microseconds).
492  Session& receiveSpinningTimeout(unsigned timeoutInUs);
493 
494  /// \return the send spinning timeout value (in microseconds).
495  unsigned sendSpinningTimeout() const ONIXS_ILINK3_NOTHROW;
496 
497  /// Sets the send spinning timeout value (in microseconds).
498  Session& sendSpinningTimeout(unsigned timeoutInUs);
499 
500  /// \return `true` if new messages are reported even when the message gap is detected,
501  /// and the reply on the [Retransmit Request](https://www.cmegroup.com/confluence/display/EPICSANDBOX/Retransmit+Request)
502  /// message is expected; otherwise - `false`.
503  bool reportNewMessagesWhileWaitingForMissedMessages() const;
504 
505  /// Sets the option to report new messages even when the message gap is detected,
506  /// and the reply on the [Retransmit Request](https://www.cmegroup.com/confluence/display/EPICSANDBOX/Retransmit+Request)
507  /// message is expected.
508  Session& reportNewMessagesWhileWaitingForMissedMessages(bool value);
509 
510  /// \return the number of messages to be sent together.
511  unsigned messageGrouping() const ONIXS_ILINK3_NOTHROW;
512 
513  /**
514  * Sets the number of messages to be sent together.
515  *
516  * \param numberOfMessagesToGroup If the parameter is zero (by default) or one, the Handler tries to send
517  * an outgoing application-level message in the context of the thread that calls the OnixS::CME::iLink3::Session::send method.
518  * If the message cannot be sent immediately, it is stored in the queue for the subsequent sending by the sending thread.
519  * If this parameter is larger than one, the Handler stores outgoing SBE messages in the queue for the subsequent sending by the sending thread.
520  *
521  * \return This session.
522  */
523  Session& messageGrouping(unsigned numberOfMessagesToGroup);
524 
525  /// \return Session storage type.
526  SessionStorageType::Enum storageType() const ONIXS_ILINK3_NOTHROW;
527 
528  /// \return Session storage ID.
529  const std::string &storageId() const ONIXS_ILINK3_NOTHROW;
530 
531  /// \return the sequence number of the next outgoing message.
532  SeqNumber outSeqNum() const ONIXS_ILINK3_NOTHROW;
533 
534  /// Sets the sequence number of the next outgoing message.
535  Session& outSeqNum(SeqNumber nextOutSeqNum);
536 
537  /// \return the expected sequence number of the next inbound message.
538  SeqNumber inSeqNum() const;
539 
540  /// Sets the expected sequence number of the next inbound message.
541  Session& inSeqNum(SeqNumber nextExpectedInSeqNum);
542 
543  /**
544  * \return the sequence number of the last business message published by CME with the PreviousUUID.
545  *
546  * If no business message was published, the value is zero.
547  */
548  SeqNumber previousSeqNo() const ONIXS_ILINK3_NOTHROW;
549 
550  /// Sets the sequence number of the last business message published by CME with the PreviousUUID.
551  Session& previousSeqNo(SeqNumber value);
552 
553  /**
554  * \return The UUID from the previously established session.
555  *
556  * - This can be the CME-assigned default UUID=0 for messages published by CME before the first Negotiation of the customer at the beginning of the week.
557  * - This can be the last UUID used by the customer from the previously established session.
558  */
559  Messaging::UInt64 previousUuid() const ONIXS_ILINK3_NOTHROW;
560 
561  /// Sets the UUID from the previously Established session.
562  Session& previousUuid(Messaging::UInt64 value);
563 
564  /**
565  * Backups the current log files, resets the sequence numbers to 1 and generates a new UUID.
566  *
567  * \warning Can be called only when the session is disconnected.
568  *
569  * \param startOfWeek if `true` then the PreviousUUID and PreviousSeqNum are reset to 0.
570  *
571  * \return This session.
572  */
573  Session& reset(bool startOfWeek = false);
574 
575  /// \return Session's current state.
576  SessionStateId::Enum state() const;
577 
578  /// \return the time when the session was created or the last reset operation was performed.
579  Messaging::Timestamp creationTime() const ONIXS_ILINK3_NOTHROW;
580 
581  /// Flushes all internal buffers of the session storage.
582  void flushSessionStorage();
583 
584  /// \return the maximum number of tries to restore the telecommunications link.
585  unsigned reconnectAttempts() const;
586 
587  /// Sets the maximum number of tries to restore the telecommunications link.
588  Session& reconnectAttempts(unsigned reconnectAttempts);
589 
590  /// \return the time interval between retries to restore the telecommunications link (seconds).
591  unsigned reconnectInterval() const;
592 
593  /// Sets the time interval between retries to restore the telecommunications link (seconds).
594  Session& reconnectInterval(unsigned seconds);
595 
596  /// \return the usage of local time in Handler events and logs files.
597  bool localTimeUsage() const;
598 
599  /// Specifies the usage of local time in Handler events and logs files.
600  Session& localTimeUsage(bool useLocalTime);
601 
602  /// \return The session storage directory.
603  const std::string &storageDirectory() const;
604 
605  /// \return `true` if logging of an outgoing message to the session storage is performed before sending it to the wire; otherwise - `false`.
606  bool logBeforeSending() const;
607 
608  /// Sets the option to log an outgoing message to the session storage before sending it to the wire.
609  Session& logBeforeSending(bool value);
610 
611  /// \return the maximum size of the message queue used during message gap recovery.
612  size_t incomingMessageGapQueueMaximumSize() const;
613 
614  /// Sets the maximum size of the message queue used during message gap recovery.
615  Session& incomingMessageGapQueueMaximumSize(size_t value);
616 
617  /// Write the given user's message to the Handler's log file using the session formatted Id.
618  const Session& log(const std::string &message) const;
619 
620  /// \return the human-friendly description.
621  std::string toString() const;
622 
623  /// \return the license expiration date.
624  Messaging::Timestamp licenseExpirationDate() const;
625 
626  /// \return the version of the message schema.
627  Messaging::SchemaVersion messagingVersion() const ONIXS_ILINK3_NOTHROW;
628 
629  /// \return the value of the option to detect the message gap for the previous UUID.
630  bool detectMessageGapForPreviousUuid() const;
631 
632  /// Sets the value of the option to detect the message gap for the previous UUID.
633  Session& detectMessageGapForPreviousUuid(bool detectGap);
634 
635  /// Represents invalid value of socket handle.
636  static const Handle InvalidSocketHandle;
637 
638  /// Returns the socket handle which the session uses to transmit data.
639  ///
640  /// \note The TCPDirect mode does not support this method, so it always returns the `InvalidSocketHandle` value.
641  Handle socketHandle();
642 
643  /// Returns the total number of bytes in the outbound queue.
644  size_t outboundQueueBytes();
645 
646  /// Gets information about the underlying TCP connection.
647  ///
648  /// \return `true` when success; otherwise - `false`.
649  /// \note Available on Linux only.
650  /// \note Not available for the TcpDirect mode.
651  bool getTcpInfo(TcpInfo&);
652 
653  /// \return the version of the library.
654  static const std::string& version() ONIXS_ILINK3_NOTHROW;
655 
656 private:
657  Session(const Session& );
658  Session& operator=(const Session& );
659 
660  void send(NetworkMessage msg, Messaging::Timestamp ts);
661  void send(NetworkMessage* begin, NetworkMessage* end, size_t maxPacketSize, Messaging::Timestamp ts);
662  void warmUp(NetworkMessage msg, int warmupFlags, Messaging::Timestamp ts);
663  void warmUp(NetworkMessage* begin, NetworkMessage* end, size_t maxPacketSize, int warmupFlags, Messaging::Timestamp ts);
664 
665  template <typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
666  void validate(const Messaging::MessageHolder<SbeMessageType, MaxMessageSize, MessageInitializer> &msg) const;
667 
668  void validateVersion(Messaging::SchemaVersion version) const;
669 
670  Session& sendRetransmitRequest(UInt64 uuid, SeqNumber from, SeqNumber to);
671 
672  struct Impl;
673  Impl *const impl_;
674 
675 friend struct AdHoc::SessionHelper;
676 };
677 
678 /**
679 * An iLink 3 Session for CME Convenience Gateways (CGW).
680 */
681 class ONIXS_ILINK3_EXPORTED CgwSession : public Session
682 {
683 public:
684  /**
685  * Constructor.
686  *
687  * \param settings Session settings.
688  * \param listener Session listener.
689  * \param storageType Session storage type.
690  * \param storage Session storage.
691  * \param uuid Universally Unique Identifier (UUID).
692  * \param customKey Custom key that could be used to distinguish sessions with the same UUID, Session ID and FirmId values.
693  */
694  CgwSession(const SessionSettings &settings,
696  SessionStorage *storage = ONIXS_ILINK3_NULLPTR, UInt64 uuid = UndefinedUuid, const std::string &customKey = "");
697 
698  /**
699  * Constructor.
700  *
701  * \param stack Externally provided reactor.
702  * \param settings Session settings.
703  * \param listener Session listener.
704  * \param storageType Session storage type.
705  * \param storage Session storage.
706  * \param uuid Universally Unique Identifier (UUID).
707  * \param customKey Custom key that could be used to distinguish sessions with the same UUID, Session ID and FirmId values.
708  */
709  CgwSession(SessionReactor & stack, const SessionSettings & settings,
711  SessionStorage * storage = ONIXS_ILINK3_NULLPTR, UInt64 uuid = UndefinedUuid, const std::string &customKey = "");
712 
713 private:
714  int marketSegmentId() const ONIXS_ILINK3_NOTHROW;
715  static const int marketSegmentId_ = INT_MAX;
716 };
717 
718 template <typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
721 {
722  assert(ts != Messaging::Timestamp());
723 
724 #ifndef NDEBUG
725  validate(msg);
726 #endif
727 
728  send(msg.toNetworkMessage(), ts);
729 
730  return *this;
731 }
732 
733 template <typename SbeMessageType, size_t MaxMessageSize>
737  Messaging::Timestamp sendingTime,
738  int warmupFlags)
739 {
740  warmUp(msg.toNetworkMessage(), warmupFlags, sendingTime);
741  return *this;
742 }
743 
744 #if defined (ONIXS_ILINK3_CXX11)
745 
746 template <typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
749 {
750  assert(ts != Messaging::Timestamp());
751 
752  send(msg, ts);
753  return *this;
754 }
755 
756 #endif
757 
758 #if defined (ONIXS_ILINK3_CXX11)
759 
760 template <typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
765  size_t maxPacketSize)
766 {
767  assert(ts != Messaging::Timestamp());
768 
769  if ONIXS_ILINK3_UNLIKELY(msgs.netMsgs_.empty())
770  return *this;
771 
772  NetworkMessage* const begin = &*msgs.netMsgs_.begin();
773  NetworkMessage* const end = begin + msgs.netMsgs_.size();
774 
775  send(begin, end, maxPacketSize, ts);
776  return *this;
777 }
778 
779 template <typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
783  Messaging::Timestamp ts, size_t maxPacketSize, int flags)
784 {
785  assert(ts != Messaging::Timestamp());
786 
787  if ONIXS_ILINK3_UNLIKELY(msgs.netMsgs_.empty())
788  return *this;
789 
790  NetworkMessage* const begin = &*msgs.netMsgs_.begin();
791  NetworkMessage* const end = begin + msgs.netMsgs_.size();
792 
793  warmUp(begin, end, maxPacketSize, flags, ts);
794  return *this;
795 }
796 
797 #endif
798 
799 template <typename SbeMessageType, size_t MaxMessageSize, typename MessageInitializer>
801 {
802  Messaging::validate(holder);
803  validateVersion(holder->version());
804 }
805 
806 }
807 }
808 }
#define ONIXS_ILINK3_NULLPTR
Definition: Compiler.h:183
An iLink 3 Session.
Definition: Session.h:47
Contains the SimpleOpenFramingHeader, the SBE message, and the data buffer.
Session&#39;s network stack reactor interface.
std::pair< NetworkMessage *, NetworkMessage * > NetMessagesRange
Definition: MessageBatch.h:43
Session & send(Messaging::MessageHolder< SbeMessageType, MaxMessageSize, MessageInitializer > &msg, Messaging::Timestamp sendingTime=UtcWatch::now())
Sends the message.
Definition: Session.h:720
Messaging::UInt32 SeqNumber
Definition: Messaging.h:60
void validate(const Message &)
Definition: Validation.h:32
TCP state information.
Definition: TcpInfo.h:31
unsigned short Port
Definition: Defines.h:44
MessageHeader::Version SchemaVersion
SBE-encoded data version type.
Definition: SchemaTraits.h:30
STL namespace.
std::set< CpuIndex > CpuIndexes
Definition: Defines.h:73
Definition: Defines.h:40
An iLink 3 Session for CME Convenience Gateways (CGW).
Definition: Session.h:681
size_t CpuIndex
Definition: Defines.h:72
int Handle
Type alias for socket handle.
Definition: Defines.h:56
#define ONIXS_ILINK3_EXPORTED
Definition: Compiler.h:176
Session & warmUp(Messaging::MessageHolder< SbeMessageType, MaxMessageSize > &msg, Messaging::Timestamp sendingTime=UtcWatch::now(), int warmupFlags=0)
Warms up the sending path.
Definition: Session.h:735
UInt64 UInt64
uInt64.
Definition: Fields.h:308
The class can be used to combine messages with different types to the batch for sending.
Definition: MessageBatch.h:140
std::vector< SocketOption > SocketOptions
Socket options.
Definition: Defines.h:77
#define ONIXS_ILINK3_HOTPATH
Definition: Compiler.h:188
The time point without the time-zone information.
Definition: Time.h:467
#define ONIXS_ILINK3_NOTHROW
Definition: Compiler.h:177
NetworkMessage toNetworkMessage() noexcept