diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-08-02 01:29:15 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-08-02 01:29:15 +0100 |
| commit | 678f457a9797ae064634f8ba2a83b156f2892871 (patch) | |
| tree | 31e5d6625e16dd5842022e5d99de4dd51ea55277 /dev/lib/fix | |
| parent | 4dbb5cc1283eed26cb9b66600fe9bb594aad8ef3 (diff) | |
refactor! breaking API changes of SOCL, also reworked must_pass helpers, and added one for the fix parser.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev/lib/fix')
| -rw-r--r-- | dev/lib/fix/network.hpp | 7 | ||||
| -rw-r--r-- | dev/lib/fix/parser.hpp | 37 |
2 files changed, 30 insertions, 14 deletions
diff --git a/dev/lib/fix/network.hpp b/dev/lib/fix/network.hpp index 48234e6..e663869 100644 --- a/dev/lib/fix/network.hpp +++ b/dev/lib/fix/network.hpp @@ -28,8 +28,9 @@ namespace snu::fix delivery_modem& operator=(const delivery_modem&) = default; delivery_modem(const delivery_modem&) = default; + public: static constexpr auto local_address = "127.0.0.1"; - static constexpr auto backlog_cnt = 18U; + static constexpr auto backlog_count = 18U; public: delivery_socket_type fd_{}; @@ -63,7 +64,7 @@ namespace snu::fix } template <int32_t AF, int32_t Kind, int32_t IPProto, int32_t Port> - bool construct(const char* addr = local_address, const bool& is_server = false) noexcept + bool construct(const char* addr = delivery_modem::local_address, const bool& is_server = false) noexcept { static_assert(AF != 0, "AF is zero"); static_assert(Kind != 0, "Kind is zero"); @@ -87,7 +88,7 @@ namespace snu::fix return ret == 0; } - ::listen(fd_, backlog_cnt); + ::listen(fd_, delivery_modem::backlog_count); return true; } diff --git a/dev/lib/fix/parser.hpp b/dev/lib/fix/parser.hpp index e007906..5e3bc3b 100644 --- a/dev/lib/fix/parser.hpp +++ b/dev/lib/fix/parser.hpp @@ -14,10 +14,14 @@ #include <string> #include <vector> +#include <sys/types.h> +#include <unistd.h> +#include <signal.h> + namespace snu::fix { template <typename char_type> - struct visitor; + struct basic_visitor; template <typename char_type> struct range; @@ -86,6 +90,7 @@ namespace snu::fix class range_data final { public: + std::size_t magic_len_; std::basic_string<char_type> magic_; std::size_t body_len_; std::vector<std::pair<std::basic_string<char_type>, std::basic_string<char_type>>> body_; @@ -127,20 +132,20 @@ namespace snu::fix } }; - /// @brief visitor object which returns a fix::range_data instance. + /// @brief basic_visitor object which returns a fix::range_data instance. template <typename char_type> - class visitor final + class basic_visitor final { public: static constexpr const char_type soh = '|'; static constexpr const char_type eq = '='; static constexpr uint32_t base = 10U; - explicit visitor() = default; - ~visitor() = default; + explicit basic_visitor() = default; + ~basic_visitor() = default; - visitor& operator=(const visitor&) = default; - visitor(const visitor&) = default; + basic_visitor& operator=(const basic_visitor&) = default; + basic_visitor(const basic_visitor&) = default; range<char_type> operator()(const std::basic_string<char_type>& in) { @@ -162,18 +167,19 @@ namespace snu::fix { for (auto& ch : in) { - if (ch != visitor::soh) + if (ch != basic_visitor::soh) { in_tmp += ch; continue; } - std::basic_string<char_type> key = in_tmp.substr(0, in_tmp.find(visitor::eq)); - std::basic_string<char_type> val = in_tmp.substr(in_tmp.find(visitor::eq) + 1); + std::basic_string<char_type> key = in_tmp.substr(0, in_tmp.find(basic_visitor::eq)); + std::basic_string<char_type> val = in_tmp.substr(in_tmp.find(basic_visitor::eq) + 1); if (ret.magic_.empty()) { - ret.magic_ = val; + ret.magic_ = val; + ret.magic_len_ = ret.magic_.size(); } else { @@ -194,6 +200,15 @@ namespace snu::fix return ret; } }; + + template <typename char_type = char> + inline void must_pass(range_data<char_type>& range) + { + if (!range.is_valid()) + { + ::kill(::getpid(), SIGTRAP); + } + } } // namespace snu::fix #endif // ifndef _SNU_FIX_PARSER_HPP |
