44#include < quickfix/FileStore.h>
55#include < quickfix/Session.h>
66#include < quickfix/SessionSettings.h>
7- #include < quickfix/SocketInitiator .h>
7+ #include < quickfix/ThreadedSocketInitiator .h>
88
99#include < memory>
1010
@@ -20,28 +20,12 @@ Worker::Worker(std::unique_ptr<FixApp> app,
2020 std::unique_ptr<FIX::FileStoreFactory> store,
2121 FIX::SessionSettings settings,
2222 std::unique_ptr<FIX::FileLogFactory> log,
23- std::unique_ptr<FIX::SocketInitiator> initiator,
24- const std::function<void (std::stop_token)>& task)
23+ std::unique_ptr<FIX::ThreadedSocketInitiator> initiator)
2524 : app_(std::move(app)),
2625 store_ (std::move(store)),
2726 settings_(std::move(settings)),
2827 log_(std::move(log)),
29- initiator_(std::move(initiator)),
30- worker_task_(task) {
31- // default behaviour
32- if (!task) {
33- worker_task_ = {[this ]([[maybe_unused]] const std::stop_token& stoken) {
34- utils::Threading::set_thread_name (THREAD_NAME_);
35- spdlog::info (" starting FIX wrapper thread. name [{}], id [{}]" , THREAD_NAME_,
36- utils::Threading::get_os_thread_id ());
37- // NB: SocketInitiator::start() is a blocking call, so the stop_token
38- // cannot cancel the thread. NB: The `stop()` function has to forcibly
39- // stop it with `initiator_->stop()`.
40- initiator_->start ();
41- spdlog::info (" started FIX initiator" );
42- }};
43- }
44- }
28+ initiator_(std::move(initiator)) {}
4529
4630// static member function
4731Worker Worker::from_conf (Config& conf) {
@@ -51,7 +35,8 @@ Worker Worker::from_conf(Config& conf) {
5135 auto settings = FIX::SessionSettings{conf.fix_config_path };
5236 auto store = std::make_unique<FIX::FileStoreFactory>(settings);
5337 auto log = std::make_unique<FIX::FileLogFactory>(settings);
54- auto initiator = std::make_unique<FIX::SocketInitiator>(*app, *store, settings, *log);
38+ auto initiator =
39+ std::make_unique<FIX::ThreadedSocketInitiator>(*app, *store, settings, *log);
5540
5641 // hand over object ownership to the instance being created (by the static
5742 // function)
@@ -60,27 +45,13 @@ Worker Worker::from_conf(Config& conf) {
6045}
6146
6247void Worker::start () {
63- try {
64- worker_ = std::jthread{worker_task_};
65- } catch (const std::exception& e) {
66- spdlog::error (" error starting FIX. error [{}]" , e.what ());
67- } catch (...) {
68- spdlog::error (" error starting FIX. unknown error" );
69- }
48+ initiator_->start ();
49+ spdlog::info (" started FIX initiator" );
7050}
7151
7252void Worker::stop () {
73- try {
74- if (initiator_) {
75- initiator_->stop (); // TODO(mils): does this need a try/catch?
76- }
77- spdlog::info (" stopped FIX initiator" );
78- } catch (const std::exception& e) {
79- spdlog::error (" error stopping FIX initiator. error [{}]" , e.what ());
80- } catch (...) {
81- spdlog::error (" error stopping FIX initiator. unknown error" );
82- }
83- worker_ = std::jthread{};
53+ initiator_->stop (); // TODO(mils): does this need a try/catch?
54+ spdlog::info (" stopped FIX initiator" );
8455}
8556
8657moodycamel::ConcurrentQueue<std::shared_ptr<const FIX44::Message>>&
0 commit comments