128 lines
4.5 KiB
C++
128 lines
4.5 KiB
C++
/*
|
|
* Copyright Onix Solutions Limited [OnixS]. All rights reserved.
|
|
*
|
|
* This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
|
|
* and international copyright treaties.
|
|
*
|
|
* Access to and use of the software is governed by the terms of the applicable OnixS Software
|
|
* Services Agreement (the Agreement) and Customer end user license agreements granting
|
|
* a non-assignable, non-transferable and non-exclusive license to use the software
|
|
* for it's own data processing purposes under the terms defined in the Agreement.
|
|
*
|
|
* Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
|
|
* of this source code or associated reference material to any other location for further reproduction
|
|
* or redistribution, and any amendments to this copyright notice, are expressly prohibited.
|
|
*
|
|
* Any reproduction or redistribution for sale or hiring of the Software not in accordance with
|
|
* the terms of the Agreement is a violation of copyright law.
|
|
*/
|
|
#pragma once
|
|
|
|
#include <OnixS/FIXEngine/FIX/ISessionReactor.h>
|
|
#include <OnixS/FIXEngine/FIX/TcpDirectAttr.h>
|
|
#include <OnixS/FIXEngine/Threading/Thread.h>
|
|
|
|
#include <cassert>
|
|
|
|
namespace OnixS {
|
|
namespace FIX {
|
|
class ReactorOperator;
|
|
namespace TCPDirect {
|
|
|
|
/**
|
|
* A high-level wrapper over the TCPDirect stack.
|
|
*/
|
|
class ONIXS_FIXENGINE_API Stack : public ISessionReactor
|
|
{
|
|
public:
|
|
/** Allocates a stack with the supplied attributes.
|
|
*
|
|
* \param attr A set of properties to apply to the stack.
|
|
*
|
|
* A stack binds to a single network interface, specified by the `interface` attribute in @p attr. *
|
|
*
|
|
* Relevant attributes to set in @p attr are those in the `zf_stack`,
|
|
* `zf_pool` and `zf_vi` categories described in the attributes documentation.
|
|
*
|
|
* \throws The std::bad_alloc is thrown in case of out of memory. N.B. Huge pages are required.
|
|
* \throws The std::runtime_error is thrown if the TCPDirect library reported an error.
|
|
* \throws The std::exception is thrown if a system call reported an error.
|
|
*/
|
|
explicit Stack(const Attributes & attr);
|
|
|
|
#ifdef ONIXS_FIXENGINE_CXX11
|
|
Stack(const Stack &) = delete;
|
|
Stack(Stack &&) = delete;
|
|
|
|
Stack & operator=(const Stack &) = delete;
|
|
Stack & operator=(Stack &&) = delete;
|
|
#endif
|
|
|
|
~Stack();
|
|
|
|
/**
|
|
* Processes events on a stack and performs the necessary handling.
|
|
*
|
|
* These events include transmit and receive events raised by the hardware,
|
|
* and also software events such as TCP and FIX protocol timers.
|
|
*
|
|
* Please see the "Stack polling" section in the TCPDirect User Guide for further information.
|
|
*
|
|
* \warning The event dispatching should be performed from the same thread that created the stack.
|
|
*/
|
|
void dispatchEvents() ONIXS_FIXENGINE_OVERRIDE {
|
|
// The TCPDirect middleware is NOT thread-safe.
|
|
// Therefore, the event dispatching should be performed from the same thread that created the stack.
|
|
|
|
assert(threadId() == Threading::ThisThread::id() && "should be performed from the same thread that created the stack");
|
|
|
|
dispatchEventsImpl();
|
|
}
|
|
|
|
/**
|
|
* \return a boolean value indicating whether a stack is quiescent.
|
|
*
|
|
* This can be used to ensure that all connections have been closed gracefully before the destroying of a stack
|
|
* (or exiting the application). The destroying of a stack while it is not quiescent is permitted by the API,
|
|
* but when doing so there is no guarantee that sent data has been acknowledged by the peer or even transmitted,
|
|
* and there is the possibility that peers' connections will be reset.
|
|
*/
|
|
bool isQuiescent() const ONIXS_FIXENGINE_OVERRIDE {
|
|
assert(threadId() == Threading::ThisThread::id() && "should be performed from the same thread that created the stack");
|
|
|
|
return isQuiescentImpl();
|
|
}
|
|
|
|
/**
|
|
* Returns the ID of the thread that created the stack.
|
|
*
|
|
* \return the ID of the thread that created the stack.
|
|
*/
|
|
Threading::ThreadId threadId() const ONIXS_FIXENGINE_OVERRIDE {
|
|
return threadId_;
|
|
}
|
|
|
|
ReactorType::Enum type() const ONIXS_FIXENGINE_OVERRIDE {
|
|
return ReactorType::TcpDirect;
|
|
}
|
|
|
|
private:
|
|
void dispatchEventsImpl();
|
|
|
|
bool isQuiescentImpl() const;
|
|
|
|
class Impl;
|
|
Impl * const impl_;
|
|
|
|
Threading::ThreadId const threadId_;
|
|
|
|
#ifndef ONIXS_FIXENGINE_CXX11
|
|
Stack(const Stack &);
|
|
Stack & operator=(const Stack &);
|
|
#endif
|
|
|
|
friend class FIX::ReactorOperator;
|
|
};
|
|
|
|
}}}
|