OnixS C++ FIX Engine  4.10.1
API Documentation
TcpDirectStack.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 #pragma once
20 
24 
25 #include <cassert>
26 
27 namespace OnixS {
28 namespace FIX {
29 class ReactorOperator;
30 namespace TCPDirect {
31 
32 /**
33  * A high-level wrapper over the TCPDirect stack.
34  */
36 {
37 public:
38  /** Allocates a stack with the supplied attributes.
39  *
40  * \param attr A set of properties to apply to the stack.
41  *
42  * A stack binds to a single network interface, specified by the `interface` attribute in @p attr. *
43  *
44  * Relevant attributes to set in @p attr are those in the `zf_stack`,
45  * `zf_pool` and `zf_vi` categories described in the attributes documentation.
46  *
47  * \throws The std::bad_alloc is thrown in case of out of memory. N.B. Huge pages are required.
48  * \throws The std::runtime_error is thrown if the TCPDirect library reported an error.
49  * \throws The std::exception is thrown if a system call reported an error.
50  */
51  explicit Stack(const Attributes & attr);
52 
53 #ifdef ONIXS_FIXENGINE_CXX11
54  Stack(const Stack &) = delete;
55  Stack(Stack &&) = delete;
56 
57  Stack & operator=(const Stack &) = delete;
58  Stack & operator=(Stack &&) = delete;
59 #endif
60 
61  ~Stack();
62 
63  /**
64  * Processes events on a stack and performs the necessary handling.
65  *
66  * These events include transmit and receive events raised by the hardware,
67  * and also software events such as TCP and FIX protocol timers.
68  *
69  * Please see the "Stack polling" section in the TCPDirect User Guide for further information.
70  *
71  * \warning The event dispatching should be performed from the same thread that created the stack.
72  */
73  void dispatchEvents() ONIXS_FIXENGINE_OVERRIDE {
74  // The TCPDirect middleware is NOT thread-safe.
75  // Therefore, the event dispatching should be performed from the same thread that created the stack.
76 
77  assert(threadId() == Threading::ThisThread::id() && "should be performed from the same thread that created the stack");
78 
79  dispatchEventsImpl();
80  }
81 
82  /**
83  * \return a boolean value indicating whether a stack is quiescent.
84  *
85  * This can be used to ensure that all connections have been closed gracefully before the destroying of a stack
86  * (or exiting the application). The destroying of a stack while it is not quiescent is permitted by the API,
87  * but when doing so there is no guarantee that sent data has been acknowledged by the peer or even transmitted,
88  * and there is the possibility that peers' connections will be reset.
89  */
90  bool isQuiescent() const ONIXS_FIXENGINE_OVERRIDE {
91  assert(threadId() == Threading::ThisThread::id() && "should be performed from the same thread that created the stack");
92 
93  return isQuiescentImpl();
94  }
95 
96  /**
97  * Returns the ID of the thread that created the stack.
98  *
99  * \return the ID of the thread that created the stack.
100  */
101  Threading::ThreadId threadId() const ONIXS_FIXENGINE_OVERRIDE {
102  return threadId_;
103  }
104 
105  ReactorType::Enum type() const ONIXS_FIXENGINE_OVERRIDE {
106  return ReactorType::TcpDirect;
107  }
108 
109 private:
110  void dispatchEventsImpl();
111 
112  bool isQuiescentImpl() const;
113 
114  class Impl;
115  Impl * const impl_;
116 
117  Threading::ThreadId const threadId_;
118 
119 #ifndef ONIXS_FIXENGINE_CXX11
120  Stack(const Stack &);
121  Stack & operator=(const Stack &);
122 #endif
123 
124  friend class FIX::ReactorOperator;
125 };
126 
127 }}}
#define ONIXS_FIXENGINE_API
Definition: ABI.h:45
Threading::ThreadId threadId() const ONIXS_FIXENGINE_OVERRIDE
Returns the ID of the thread that created the stack.
pthread_t ThreadId
Type alias for thread identifier.
Definition: Definitions.h:51
static ThreadId id()
Gets the platform identifier for the current thread.
TCPDirect attributes to pass configuration details (a wrapper around the zf_Attributes struct)...
Definition: TcpDirectAttr.h:40
A high-level wrapper over the TCPDirect stack.
bool isQuiescent() const ONIXS_FIXENGINE_OVERRIDE
void dispatchEvents() ONIXS_FIXENGINE_OVERRIDE
Processes events on a stack and performs the necessary handling.
The Solarflare TCPDirect reactor.
The session&#39;s network stack reactor interface.
ReactorType::Enum type() const ONIXS_FIXENGINE_OVERRIDE