diff options
| author | Amlal <amlal@nekernel.org> | 2025-08-12 11:53:13 +0200 |
|---|---|---|
| committer | Amlal <amlal@nekernel.org> | 2025-08-12 11:53:24 +0200 |
| commit | 54e32a8a3535d99d104775687af0731b0be3b129 (patch) | |
| tree | b43e378237a724699b785ae21ca63374c510564c /dev/lib | |
| parent | 2450c6579543ae94b3dcb2af4893cfc6ecd0fcef (diff) | |
wip: work in progress network tests using GTest. Reworked print module too.
Signed-off-by: Amlal <amlal@nekernel.org>
Diffstat (limited to 'dev/lib')
| -rw-r--r-- | dev/lib/fix/parser.hpp | 2 | ||||
| -rw-r--r-- | dev/lib/io/print.hpp | 24 | ||||
| -rw-r--r-- | dev/lib/net/network.hpp | 22 | ||||
| -rw-r--r-- | dev/lib/net/url.hpp | 8 |
4 files changed, 44 insertions, 12 deletions
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 <utility> #include <string> #include <vector> - +#include <cstdint> #include <sys/types.h> #include <unistd.h> #include <signal.h> 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 <initializer_list> #include <iostream> +#include <ostream> namespace snu::io -{ +{ + template <typename T> + inline void printv(T fmt) noexcept + { + std::cout << fmt; + } + + template <typename T> + inline void printv(std::initializer_list<T> fmt) noexcept + { + std::cout << fmt; + } + template <typename... T> - inline void print(T... fmt) + inline void print(T... fmt) noexcept { - std::cout << std::move(fmt...); + (printv(fmt), ...); } template <typename... T> - inline void println(T... fmt) + inline void println(T... fmt) noexcept { - std::cout << std::move(fmt...); + print(static_cast<T>(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 <unistd.h> #include <arpa/inet.h> #include <sys/socket.h> - +#include <string> #include <utility> #include <cstddef> @@ -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 <typename ptr_type> + bool transmit(std::basic_string<ptr_type> out) noexcept + { + if (out.empty()) + return false; + + auto ret = ::send(fd_, out.data(), out.size(), 0); + + return ret > 0; + } + template <int32_t af, int32_t kind, int32_t ip_proto, int32_t port> 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 <typename char_type> class basic_url; + template <typename char_type> + class basic_url_traits; + /// @brief Basic URL parser container. template <typename char_type> class basic_url final { + friend basic_url_traits<char_type>; + std::basic_stringstream<char_type> ss_{}; public: @@ -33,6 +38,9 @@ namespace snu::net basic_url& operator/=(const std::basic_string<char_type>& in) { + if (in.empty()) + return *this; + ss_ += in; return *this; } |
