From 7ea0c074329dd55de43ea3b07ff545228cb0d729 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 27 Aug 2025 13:27:55 +0200 Subject: feat: `must_pass` should call error_handler instead of trapping. (FIX) Signed-off-by: Amlal El Mahrouss --- dev/lib/fix/parser.hpp | 6 +++--- dev/lib/net/modem.hpp | 38 +++++++++++++++++++++++++------------- 2 files changed, 28 insertions(+), 16 deletions(-) (limited to 'dev/lib') diff --git a/dev/lib/fix/parser.hpp b/dev/lib/fix/parser.hpp index a93b846..6e8e57a 100644 --- a/dev/lib/fix/parser.hpp +++ b/dev/lib/fix/parser.hpp @@ -201,12 +201,12 @@ namespace ocl::fix } }; - template - inline void must_pass(basic_range_data& basic_range) + template + inline void must_pass(basic_range_data& basic_range, error_handler& handler) { if (!basic_range.is_valid()) { - ::kill(::getpid(), SIGTRAP); + handler("Invalid FIX packet"); } } diff --git a/dev/lib/net/modem.hpp b/dev/lib/net/modem.hpp index e350f91..bcf2a79 100644 --- a/dev/lib/net/modem.hpp +++ b/dev/lib/net/modem.hpp @@ -15,28 +15,34 @@ #include #include -#define OCL_MODEM_INTERFACE : protected ocl::net::basic_modem +#define OCL_MODEM_INTERFACE : public ocl::net::basic_modem namespace ocl::net { - template class basic_modem; typedef int64_t socket_type; /// @brief Modem container concept, a container to read and write on a network stream. - template class basic_modem { + private: socket_type fd_{}; - bool server_fd_{}; + bool server_fd_{false}; + bool bad_{true}; public: + const bool& bad{bad_}; + explicit basic_modem() = default; - virtual ~basic_modem() = default; + + virtual ~basic_modem() + { + this->destroy(); + } - basic_modem& operator=(const basic_modem&) = default; - basic_modem(const basic_modem&) = default; + basic_modem& operator=(const basic_modem&) = delete; + basic_modem(const basic_modem&) = delete; static constexpr auto local_address_ip4 = "127.0.0.1"; static constexpr auto local_address_ip6 = "::1"; @@ -44,7 +50,7 @@ namespace ocl::net bool is_valid() const noexcept { - return this->fd_ != -1; + return this->fd_ != -1 && !this->bad_; } template @@ -71,7 +77,7 @@ namespace ocl::net template bool transmit(ptr_type& out, std::size_t len) noexcept { - static_assert(std::is_pointer::value, "char_type is not a pointer!"); + static_assert(std::is_pointer::value, "ptr_type is not a pointer!"); if (!out) return false; @@ -81,18 +87,22 @@ namespace ocl::net auto ret = ::send(fd_, out, len, 0); - return ret > 0L; + bad_ = !(ret >= 0L); + + return ret >= 0L; } - template - bool transmit(std::basic_string out) noexcept + template + bool transmit(const std::basic_string& out) noexcept { if (out.empty()) return false; auto ret = ::send(fd_, out.data(), out.size(), 0); - return ret > 0L; + bad_ = !(ret >= 0L); + + return ret >= 0L; } template @@ -123,6 +133,8 @@ namespace ocl::net ::bind(fd_, (struct sockaddr*)&addr_, sizeof(addr_)); ::listen(fd_, basic_modem::backlog_count); + bad_ = false; + return true; } -- cgit v1.2.3