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/net | |
| 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/net')
| -rw-r--r-- | dev/lib/net/network.hpp | 22 | ||||
| -rw-r--r-- | dev/lib/net/url.hpp | 8 |
2 files changed, 24 insertions, 6 deletions
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; } |
