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,38 +20,25 @@ 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) {
4832 std::unique_ptr<IAuth> auth =
4933 std::make_unique<Auth>(conf.api_key , conf.private_key_path );
50- auto app = std::make_unique<FixApp>(conf.symbols , std::move (auth), conf.MAX_DEPTH );
34+ auto app = std::make_unique<FixApp>(conf.symbols , std::move (auth), conf.MAX_DEPTH ,
35+ conf.PX_SESSION_CPU_AFFINITY ,
36+ conf.TX_SESSION_CPU_AFFINITY );
5137 auto settings = FIX ::SessionSettings{conf.fix_config_path };
5238 auto store = std::make_unique<FIX ::FileStoreFactory>(settings);
5339 auto log = std::make_unique<FIX ::FileLogFactory>(settings);
54- auto initiator = std::make_unique<FIX ::SocketInitiator>(*app, *store, settings, *log);
40+ auto initiator =
41+ std::make_unique<FIX ::ThreadedSocketInitiator>(*app, *store, settings, *log);
5542
5643 // hand over object ownership to the instance being created (by the static
5744 // function)
@@ -60,27 +47,13 @@ Worker Worker::from_conf(Config& conf) {
6047}
6148
6249void 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- }
50+ initiator_->start ();
51+ spdlog::info (" started FIX initiator" );
7052}
7153
7254void 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{};
55+ initiator_->stop (); // TODO(mils): does this need a try/catch?
56+ spdlog::info (" stopped FIX initiator" );
8457}
8558
8659moodycamel::ConcurrentQueue<std::shared_ptr<const FIX44 ::Message>>&
0 commit comments