From 54e32a8a3535d99d104775687af0731b0be3b129 Mon Sep 17 00:00:00 2001 From: Amlal Date: Tue, 12 Aug 2025 11:53:13 +0200 Subject: wip: work in progress network tests using GTest. Reworked print module too. Signed-off-by: Amlal --- dev/lib/fix/parser.hpp | 2 +- dev/lib/io/print.hpp | 24 +++++++++++++++++++----- dev/lib/net/network.hpp | 22 ++++++++++++++++------ dev/lib/net/url.hpp | 8 ++++++++ 4 files changed, 44 insertions(+), 12 deletions(-) (limited to 'dev/lib') diff --git a/dev/lib/fix/parser.hpp b/dev/lib/fix/parser.hpp index 1095e8d..0f2287e 100644 --- a/dev/lib/fix/parser.hpp +++ b/dev/lib/fix/parser.hpp @@ -13,7 +13,7 @@ #include #include #include - +#include #include #include #include diff --git a/dev/lib/io/print.hpp b/dev/lib/io/print.hpp index e326845..36192c4 100644 --- a/dev/lib/io/print.hpp +++ b/dev/lib/io/print.hpp @@ -8,20 +8,34 @@ #ifndef _SNU_PRINT_HPP #define _SNU_PRINT_HPP +#include #include +#include namespace snu::io -{ +{ + template + inline void printv(T fmt) noexcept + { + std::cout << fmt; + } + + template + inline void printv(std::initializer_list fmt) noexcept + { + std::cout << fmt; + } + template - inline void print(T... fmt) + inline void print(T... fmt) noexcept { - std::cout << std::move(fmt...); + (printv(fmt), ...); } template - inline void println(T... fmt) + inline void println(T... fmt) noexcept { - std::cout << std::move(fmt...); + print(static_cast(fmt)...); std::cout << std::endl; } } // namespace snu::io diff --git a/dev/lib/net/network.hpp b/dev/lib/net/network.hpp index a58cb1f..67f3740 100644 --- a/dev/lib/net/network.hpp +++ b/dev/lib/net/network.hpp @@ -11,7 +11,7 @@ #include #include #include - +#include #include #include @@ -38,7 +38,7 @@ namespace snu::net static constexpr auto local_address_ip6 = "127.0.0.1"; static constexpr auto local_address_ip4 = "::1"; - static constexpr auto backlog_count = 18U; + static constexpr auto backlog_count = 18U; socket_type fd_{}; @@ -58,7 +58,7 @@ namespace snu::net if (!len) return false; - auto ret = ::recv(fd_, out, len, MSG_WAITALL); + auto ret = ::recv(fd_, out, len, 0); return ret > 0; } @@ -79,12 +79,22 @@ namespace snu::net return ret > 0; } + template + bool transmit(std::basic_string out) noexcept + { + if (out.empty()) + return false; + + auto ret = ::send(fd_, out.data(), out.size(), 0); + + return ret > 0; + } + template bool construct(const char* addr = basic_modem::local_address_ip4, const bool& is_server = false) noexcept { - static_assert(af != 0, "AF is zero"); - static_assert(kind != 0, "Kind is zero"); - static_assert(ip_proto != 0, "IPProto is zero"); + static_assert(af != 0, "Address family is zero"); + static_assert(kind != 0, "Type is zero"); fd_ = ::socket(af, kind, ip_proto); diff --git a/dev/lib/net/url.hpp b/dev/lib/net/url.hpp index 5dc0d03..9a28f9b 100644 --- a/dev/lib/net/url.hpp +++ b/dev/lib/net/url.hpp @@ -18,10 +18,15 @@ namespace snu::net template class basic_url; + template + class basic_url_traits; + /// @brief Basic URL parser container. template class basic_url final { + friend basic_url_traits; + std::basic_stringstream ss_{}; public: @@ -33,6 +38,9 @@ namespace snu::net basic_url& operator/=(const std::basic_string& in) { + if (in.empty()) + return *this; + ss_ += in; return *this; } -- cgit v1.2.3