OnixS C++ FIX Engine  4.3.0
API Documentation
Asynchronous Logon/Logout

In addition to synchronous OnixS::FIX::Session::logonAsInitiator / OnixS::FIX::Session::logout methods, there are corresponding asynchronous OnixS::FIX::Session::logonAsInitiatorAsync / OnixS::FIX::Session::logoutAsync methods. These asynchronous methods can be used when you need to avoid blocking the current thread by the long synchronous operation. For example, it is required when Logon/Logout method is called from an inbound callback. These methods return immediately without waiting for the acknowledgment Logon/Logout message. They return the OnixS::Threading::SharedFuture object that can be used to wait for the result of the asynchronous Logon/Logout methods by the OnixS::Threading::SharedFuture::get() method. If the result is not ready, the method will block. When it completes, it either returns or throws an exception, in case there were issues during waiting for the Logon/Logout response:

Session initiator("SenderCompId", "TargetCompId", ProtocolVersion::FIX_42, &listener);
const std::string Host = "localhost";
const int Port = Engine::instance()->listenPort();
const int Hbi = 30;
// Let's assume that in this place we need to avoid blocking the current thread.
// Sends the Logon message and returns immediately without waiting the acknowledgment Logon message.
OnixS::Threading::SharedFuture logonResult = initiator.logonAsInitiatorAsync(Host, Port, Hbi, ONIXS_FIXENGINE_NULLPTR, false);
// Continue to perform some important work in the current thread.
// Let's assume that in this place we can wait for the result of asynchronous Logon.
try
{
// It either returns or throws an exception, in case there were issues during waiting for the Logon response.
logonResult.get();
}
catch (const FirstMessageNotLogonException & ex)
{
std::clog << "FirstMessageNotLogonException: " << ex.what() << std::endl;
}
catch (const LinkErrorException & ex)
{
std::clog << "LinkErrorException: " << ex.what() << std::endl;
}
catch (const TimeoutException & ex)
{
std::clog << "TimeoutException: " << ex.what() << std::endl;
}
catch (const UnexpectedSequenceNumberException & ex)
{
std::clog << "UnexpectedSequenceNumberException: " << ex.what() << std::endl;
}
catch (const ConfirmationLogonMessageErrorException & ex)
{
std::clog << "ConfirmationLogonMessageErrorException: " << ex.what() << std::endl;
}
catch (const std::exception & ex)
{
std::clog << "Some other exception: " << ex.what() << std::endl;
}
std::clog << "Logon is performed successfully." << std::endl;
// Let's assume that in this place we need to avoid blocking the current thread.
// Sends the Logout message and returns immediately without waiting the acknowledgment Logout message.
OnixS::Threading::SharedFuture logoutResult = initiator.logoutAsync("Asynchronous Logout");
// Continue to perform some important work in the current thread.
// Let's assume that in this place we can wait for the result of asynchronous Logout.
try
{
// It either returns or throws an exception, in case there were issues during waiting for the Logout response.
logoutResult.get();
}
catch (const LinkErrorException & ex)
{
std::clog << "LinkErrorException: " << ex.what() << std::endl;
}
catch (const TimeoutException & ex)
{
std::clog << "TimeoutException: " << ex.what() << std::endl;
}
catch (const std::exception & ex)
{
std::clog << "Some other exception: " << ex.what() << std::endl;
}
std::clog << "Logout is performed successfully." << std::endl;