diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-08-01 09:09:57 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-08-01 09:09:57 +0100 |
| commit | 284708d1e8a14867b5276a8e760588d8531835d8 (patch) | |
| tree | 9f651db6d8b51bf97f2fd2fb41efbf5e53498eea /dev/lib/fix | |
| parent | 574d373163f7edade42e935b9e6957cdaf08d94b (diff) | |
feat: generic: new `except` module, network model for FIX, and tracked_ptr improvements.
feat: introduce the `must_pass` concept to validate a container.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev/lib/fix')
| -rw-r--r-- | dev/lib/fix/network.hpp | 63 | ||||
| -rw-r--r-- | dev/lib/fix/parser.hpp | 19 |
2 files changed, 70 insertions, 12 deletions
diff --git a/dev/lib/fix/network.hpp b/dev/lib/fix/network.hpp index 0ca0920..637559c 100644 --- a/dev/lib/fix/network.hpp +++ b/dev/lib/fix/network.hpp @@ -1,5 +1,5 @@ /* -* File: fix/netowrk.hpp + * File: fix/netowrk.hpp * Purpose: Financial Information Exchange in C++ * Author: Amlal El Mahrouss (founder@snu.systems) * Copyright 2025, Amlal El Mahrouss and SNU Systems Corp all rights reserved. @@ -11,10 +11,67 @@ #include <arpa/inet.h> #include <sys/socket.h> +#include <cstddef> + namespace snu::fix { - class network_rx; - class network_tx; + class delivery_modem; + + typedef int delivery_type; + + /// @brief a delivery modem is a container which establishes a comm. channel between the FIX session and application. + class delivery_modem final + { + public: + explicit delivery_modem() = default; + ~delivery_modem() = default; + + delivery_modem& operator=(const delivery_modem&) = default; + delivery_modem(const delivery_modem&) = default; + + public: + delivery_type fd_{}; + + template <typename T> + bool receive(T& out, std::size_t len) noexcept + { + if (!len) + return false; + + auto ret = ::recv(fd_, &out, len, 0); + return ret > 0; + } + + template <typename T> + bool transmit(T& out, std::size_t len) noexcept + { + if (!out) + return false; + if (!len) + return false; + + auto ret = ::send(fd_, out, len, 0); + return ret > 0; + } + + bool construct() noexcept + { + fd_ = ::socket(SOCK_STREAM, AF_INET, 0); + return fd_ > 0; + } + + bool destroy() noexcept + { + if (!fd_) + return false; + + ::shutdown(fd_, SHUT_RDWR); + + fd_ = 0U; + + return true; + } + }; } // namespace snu::fix #endif // ifndef _SNU_FIX_NETWORK_HPP
\ No newline at end of file diff --git a/dev/lib/fix/parser.hpp b/dev/lib/fix/parser.hpp index e432b6c..e007906 100644 --- a/dev/lib/fix/parser.hpp +++ b/dev/lib/fix/parser.hpp @@ -86,9 +86,9 @@ namespace snu::fix class range_data final { public: - std::basic_string<char_type> msg_magic_; - std::size_t msg_body_len_; - std::vector<std::pair<std::basic_string<char_type>, std::basic_string<char_type>>> msg_body_; + 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_; static inline const char_type* begin = detail::begin_fix<char_type>(); @@ -105,19 +105,20 @@ namespace snu::fix return std::basic_string<char_type>{}; } - for (const auto& pair : msg_body_) + for (const auto& pair : this->body_) { if (pair.first == key) { return pair.second; } } + return std::basic_string<char_type>{}; } bool is_valid() { - return msg_magic_.starts_with(range_data<char_type>::begin); + return magic_.starts_with(range_data<char_type>::begin); } operator bool() @@ -170,14 +171,14 @@ namespace snu::fix 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); - if (ret.msg_magic_.empty()) + if (ret.magic_.empty()) { - ret.msg_magic_ = val; + ret.magic_ = val; } else { - ret.msg_body_.emplace_back(std::make_pair(key, val)); - ret.msg_body_len_ += in_tmp.size(); + ret.body_.emplace_back(std::make_pair(key, val)); + ret.body_len_ += in_tmp.size(); } in_tmp.clear(); |
