diff options
| author | Amlal <amlal@nekernel.org> | 2025-08-11 13:03:40 +0200 |
|---|---|---|
| committer | Amlal <amlal@nekernel.org> | 2025-08-11 13:03:40 +0200 |
| commit | 1d9328259052be88b86b958fdb1b2396307cacdb (patch) | |
| tree | b179c777d9b832ebdfcb7e5e4a4fae02b9b8fd5f /dev/lib | |
| parent | 87f10dad540971c4aa22d892c676dce590ca189a (diff) | |
feat: SOCL modem improvements and newly added is_valid method to modem.
Signed-off-by: Amlal <amlal@nekernel.org>
Diffstat (limited to 'dev/lib')
| -rw-r--r-- | dev/lib/fix/parser.hpp | 10 | ||||
| -rw-r--r-- | dev/lib/net/network.hpp | 41 | ||||
| -rw-r--r-- | dev/lib/net/url.hpp | 10 |
3 files changed, 37 insertions, 24 deletions
diff --git a/dev/lib/fix/parser.hpp b/dev/lib/fix/parser.hpp index f0f7141..1095e8d 100644 --- a/dev/lib/fix/parser.hpp +++ b/dev/lib/fix/parser.hpp @@ -21,7 +21,7 @@ namespace snu::fix { template <typename char_type> - struct basic_visitor; + class basic_visitor; template <typename char_type> struct basic_range; @@ -63,12 +63,12 @@ namespace snu::fix char_type* bytes_; size_t length_; - bool is_valid() + bool is_valid() noexcept { return this->bytes_ && this->length_ > 0; } - operator bool() + explicit operator bool() { return this->is_valid(); } @@ -77,7 +77,7 @@ namespace snu::fix /// @brief Convert basic_range to usable string. /// @note This function assumes that the basic_range is valid and contains ASCII bytes. template <typename char_type = char> - inline std::basic_string<char_type> to_string(basic_range<char_type>& basic_range) noexcept + std::basic_string<char_type> to_string(basic_range<char_type>& basic_range) noexcept { if (basic_range.length_ < 0) return std::basic_string<char_type>{}; @@ -126,7 +126,7 @@ namespace snu::fix return magic_.starts_with(basic_range_data<char_type>::begin); } - operator bool() + explicit operator bool() { return this->is_valid(); } diff --git a/dev/lib/net/network.hpp b/dev/lib/net/network.hpp index 22cc5b2..37b6819 100644 --- a/dev/lib/net/network.hpp +++ b/dev/lib/net/network.hpp @@ -13,35 +13,39 @@ #include <utility> #include <cstddef> -#define SNU_MODEM : protected snu::net::basic_delivery_modem +#define SNU_MODEM_INTERFACE : protected snu::net::basic_delivery_modem namespace snu::net { - class basic_delivery_modem; + template <typename char_type> + class basic_modem; typedef int64_t socket_type; /// @brief Delivery modem concept, a container to read and write on a network stream. - class basic_delivery_modem + template <typename char_type> + class basic_modem { public: - explicit basic_delivery_modem() = default; - virtual ~basic_delivery_modem() = default; + explicit basic_modem() = default; + virtual ~basic_modem() = default; - basic_delivery_modem& operator=(const basic_delivery_modem&) = default; - basic_delivery_modem(const basic_delivery_modem&) = default; + basic_modem& operator=(const basic_modem&) = default; + basic_modem(const basic_modem&) = default; - public: static constexpr auto local_address = "127.0.0.1"; static constexpr auto backlog_count = 18U; - public: socket_type fd_{}; - template <typename T> - bool receive(T& out, std::size_t len) noexcept + bool is_valid() const noexcept + { + return this->fd_ != -1; + } + + bool receive(char_type& out, std::size_t len) noexcept { - static_assert(std::is_pointer<T>::value, "T is not a pointer!"); + static_assert(std::is_pointer<char_type>::value, "char_type is not a pointer!"); if (!out) return false; @@ -54,10 +58,9 @@ namespace snu::net return ret > 0; } - template <typename T> - bool transmit(T& out, std::size_t len) noexcept + bool transmit(char_type& out, std::size_t len) noexcept { - static_assert(std::is_pointer<T>::value, "T is not a pointer!"); + static_assert(std::is_pointer<char_type>::value, "char_type is not a pointer!"); if (!out) return false; @@ -71,7 +74,7 @@ namespace snu::net } template <int32_t AF, int32_t Kind, int32_t IPProto, int32_t Port> - bool construct(const char* addr = basic_delivery_modem::local_address, const bool& is_server = false) noexcept + bool construct(const char* addr = basic_modem::local_address, const bool& is_server = false) noexcept { static_assert(AF != 0, "AF is zero"); static_assert(Kind != 0, "Kind is zero"); @@ -79,7 +82,7 @@ namespace snu::net fd_ = ::socket(AF, Kind, IPProto); - if (fd_ < 1) + if (fd_ == -1) return false; struct sockaddr_in addr_ @@ -91,11 +94,11 @@ namespace snu::net if (!is_server) { - auto ret = ::connect(fd_, (struct sockaddr*)&addr_, sizeof(decltype(addr_))); + const auto ret = ::connect(fd_, reinterpret_cast<struct sockaddr*>(&addr_), sizeof(decltype(addr_))); return ret == 0; } - ::listen(fd_, basic_delivery_modem::backlog_count); + ::listen(fd_, basic_modem::backlog_count); return true; } diff --git a/dev/lib/net/url.hpp b/dev/lib/net/url.hpp index 6c4dc36..0506cd3 100644 --- a/dev/lib/net/url.hpp +++ b/dev/lib/net/url.hpp @@ -6,3 +6,13 @@ */ #pragma once + +#include <string> +#include <iostream> + +namespace snu::net +{ + template <typename char_type> + class basic_url; + +}
\ No newline at end of file |
