diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-11-19 03:42:46 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-19 03:42:46 +0100 |
| commit | 3bc2fca2c9beff13586b8bf3089ce439acb09de1 (patch) | |
| tree | 4cf13eb975ef8a133ca0b28de29814c94f7daccc /dev/lib/net/modem.hpp | |
| parent | c9fd682f3662e0eec09de49a36a4ea199656da34 (diff) | |
| parent | b0292253ca9732b228ef505e3e719ae05c07c10c (diff) | |
Merge pull request #12 from amlel-el-mahrouss/develop
New OCL Distrib helpers.
Diffstat (limited to 'dev/lib/net/modem.hpp')
| -rw-r--r-- | dev/lib/net/modem.hpp | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/dev/lib/net/modem.hpp b/dev/lib/net/modem.hpp index 7c07191..5bcf3fd 100644 --- a/dev/lib/net/modem.hpp +++ b/dev/lib/net/modem.hpp @@ -16,16 +16,18 @@ #include <string> #include <cstddef> -#define OCL_MODEM_INTERFACE : public ocl::net::basic_modem +#define OCL_MODEM_INTERFACE : public ocl::net::modem namespace ocl::net { - class basic_modem; - - typedef int64_t socket_type; + class modem; + using socket_type = int64_t; + + /// ============================================================================= /// @brief Modem container concept, a container to read and write on a network stream. - class basic_modem + /// ============================================================================= + class modem final { private: socket_type fd_{}; @@ -35,20 +37,25 @@ namespace ocl::net public: const bool& bad{bad_}; - explicit basic_modem() = default; + explicit modem() = default; - virtual ~basic_modem() + ~modem() { this->destroy(); } - basic_modem& operator=(const basic_modem&) = delete; - basic_modem(const basic_modem&) = delete; + modem& operator=(const modem&) = delete; + modem(const modem&) = delete; static constexpr auto local_address_ip4 = "127.0.0.1"; static constexpr auto local_address_ip6 = "::1"; static constexpr const auto backlog_count = 5U; + /// ============================================================================= + /// @brief Check if the modem is valid. + /// @return true if valid, false otherwise. + /// ============================================================================= + bool is_valid() const noexcept { return this->fd_ != -1 && !this->bad_; @@ -107,7 +114,7 @@ namespace ocl::net } template <int32_t af, int32_t kind, int32_t port> - bool construct(const char* addr = basic_modem::local_address_ip4, const bool& is_server = false) noexcept + bool construct(const char* addr = modem::local_address_ip4, const bool& is_server = false) noexcept { static_assert(af != 0, "Address family is zero"); static_assert(kind != 0, "Kind is zero"); @@ -139,7 +146,7 @@ namespace ocl::net bad_ = ret == -1; - ::listen(fd_, basic_modem::backlog_count); + ::listen(fd_, modem::backlog_count); return bad_ == false; } |
