OnixS C++ FIX Engine  4.8.0
API Documentation
ExternalThread Mode

Sometimes, it is more effective to perform the event dispatching in a loop in the main application thread. For this purpose, one can use the OnixS::FIX::ThreadingModel::ExternalThread mode.

Stack

Before an externally-managed session is created, the application must create an OnixS::FIX::ISessionReactor instance. There are two reactor classes, which can be used:

TCPStandard::Stack stack;

The pointer to the stack is provided in Session's constructor, for example:

SessionListener listener;
Session session(&stack, SenderCompId, TargetCompId, FixProtocolVersion, &listener);

Asynchronous Logon and Logout

Applications must call asynchronous Session's methods to logon (OnixS::FIX::Session::logonAsInitiatorAsync) and logout (OnixS::FIX::Session::logoutAsync).

session.logonAsInitiatorAsync(counterpartyHost, counterpartyPort, heartBtInt, ONIXS_FIXENGINE_NULLPTR, true);
// Dispatching events..
session.logoutAsync("End of connection");

Dispatching Network Events

Applications must call OnixS::FIX::TCPStandard::Stack::dispatchEvents frequently for each stack that is in use.

bool finished = false;
while (!finished)
stack.dispatchEvents();

Shutdown

The TCPStandard stack requires finishing all outstanding work and handling all outstanding events. Before destroying the OnixS::FIX::TCPStandard::Stack instance, the following code should be executed:

while (!stack.isQuiescent())
stack.dispatchEvents();

Method OnixS::FIX::TCPStandard::Stack::isQuiescent returns a boolean value indicating whether a stack is quiescent.

This can be used to ensure that all connections have been closed gracefully before destroying a stack (or exiting the application). Destroying 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.

ExternalThread Mode for Acceptor Sessions

There is an ability to use the ExternalThread mode for acceptor sessions too. However, to dispatch listening events and accept incoming TCP connections, one must pass the pointer to the stack to the OnixS::FIX::Engine::init() method. The pointer to the same stack should also be passed to the acceptor session's constructor. In this case, the FIX Engine does not create an additional thread to listen for incoming connections and uses the corresponding stack to dispatch these events:

TCPStandard::Stack stack;
EngineSettings engineSettings;
// Invoke the Engine::init with the given stack class instance.
Engine::init(engineSettings, &stack);
SessionListener listener;
Session acceptor(&stack, SenderCompId, TargetCompId, FixProtocolVersion, &listener);
acceptor.logonAsAcceptor();
bool finished = false;
// Dispatching events..
while (!finished)
stack.dispatchEvents();
acceptor.shutdown();
Engine::shutdown();
while(!stack.isQuiescent())
stack.dispatchEvents();

See Also