diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-08-27 13:27:55 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-08-27 13:27:55 +0200 |
| commit | 7ea0c074329dd55de43ea3b07ff545228cb0d729 (patch) | |
| tree | 0d5062fd2e715b6e0d0b31c99c80e1870ddcd889 /dev/lib/net | |
| parent | c4f4155f6f5a30641180050a1a5ea8967f6392fa (diff) | |
feat: `must_pass` should call error_handler instead of trapping. (FIX)
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev/lib/net')
| -rw-r--r-- | dev/lib/net/modem.hpp | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/dev/lib/net/modem.hpp b/dev/lib/net/modem.hpp index e350f91..bcf2a79 100644 --- a/dev/lib/net/modem.hpp +++ b/dev/lib/net/modem.hpp @@ -15,28 +15,34 @@ #include <utility> #include <cstddef> -#define OCL_MODEM_INTERFACE : protected ocl::net::basic_modem +#define OCL_MODEM_INTERFACE : public ocl::net::basic_modem namespace ocl::net { - template <typename char_type> class basic_modem; typedef int64_t socket_type; /// @brief Modem container concept, a container to read and write on a network stream. - template <typename char_type> class basic_modem { + private: socket_type fd_{}; - bool server_fd_{}; + bool server_fd_{false}; + bool bad_{true}; public: + const bool& bad{bad_}; + explicit basic_modem() = default; - virtual ~basic_modem() = default; + + virtual ~basic_modem() + { + this->destroy(); + } - basic_modem& operator=(const basic_modem&) = default; - basic_modem(const basic_modem&) = default; + basic_modem& operator=(const basic_modem&) = delete; + basic_modem(const basic_modem&) = delete; static constexpr auto local_address_ip4 = "127.0.0.1"; static constexpr auto local_address_ip6 = "::1"; @@ -44,7 +50,7 @@ namespace ocl::net bool is_valid() const noexcept { - return this->fd_ != -1; + return this->fd_ != -1 && !this->bad_; } template <typename ptr_type> @@ -71,7 +77,7 @@ namespace ocl::net template <typename ptr_type> bool transmit(ptr_type& out, std::size_t len) noexcept { - static_assert(std::is_pointer<ptr_type>::value, "char_type is not a pointer!"); + static_assert(std::is_pointer<ptr_type>::value, "ptr_type is not a pointer!"); if (!out) return false; @@ -81,18 +87,22 @@ namespace ocl::net auto ret = ::send(fd_, out, len, 0); - return ret > 0L; + bad_ = !(ret >= 0L); + + return ret >= 0L; } - template <typename ptr_type> - bool transmit(std::basic_string<ptr_type> out) noexcept + template <typename char_type> + bool transmit(const std::basic_string<char_type>& out) noexcept { if (out.empty()) return false; auto ret = ::send(fd_, out.data(), out.size(), 0); - return ret > 0L; + bad_ = !(ret >= 0L); + + return ret >= 0L; } template <int32_t af, int32_t kind, int32_t port> @@ -123,6 +133,8 @@ namespace ocl::net ::bind(fd_, (struct sockaddr*)&addr_, sizeof(addr_)); ::listen(fd_, basic_modem::backlog_count); + bad_ = false; + return true; } |
