From 14cb83d0d70aa33135090aed2d6b750f69e189f3 Mon Sep 17 00:00:00 2001 From: Claudius Holeksa Date: Sun, 14 May 2023 12:46:49 +0200 Subject: c++: Fixing error handling in old source --- src/io/io.h | 5 +++++ src/io/io_unix.cpp | 23 +++++++++++------------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/io/io.h b/src/io/io.h index bcc59fd..b2792dd 100644 --- a/src/io/io.h +++ b/src/io/io.h @@ -16,6 +16,11 @@ struct disconnected { static constexpr std::string_view description = "Disconnected"; static constexpr bool is_critical = true; }; + +struct resource_busy { + static constexpr std::string_view description = "Resource busy"; + static constexpr bool is_critical = false; +}; } /* * Input stream diff --git a/src/io/io_unix.cpp b/src/io/io_unix.cpp index b5f17e5..e59fa66 100644 --- a/src/io/io_unix.cpp +++ b/src/io/io_unix.cpp @@ -496,10 +496,10 @@ error_or unix_io_stream::read(void *buffer, size_t length) { if (read_bytes > 0) { return static_cast(read_bytes); } else if (read_bytes == 0) { - return critical_error("Disconnected", error::code::Disconnected); + return make_error(); } - return recoverable_error("Currently busy"); + return make_error(); } conveyor unix_io_stream::read_ready() { @@ -523,10 +523,10 @@ error_or unix_io_stream::write(const void *buffer, size_t length) { int error = errno; if (error == EAGAIN || error == EWOULDBLOCK) { - return recoverable_error("Currently busy"); + return make_error(); } - return critical_error("Disconnected", error::code::Disconnected); + return make_error(); } conveyor unix_io_stream::write_ready() { @@ -609,7 +609,7 @@ error_or unix_datagram::read(void *buffer, size_t length) { if (read_bytes > 0) { return static_cast(read_bytes); } - return recoverable_error("Currently busy"); + return make_error(); } conveyor unix_datagram::read_ready() { @@ -628,7 +628,7 @@ error_or unix_datagram::write(const void *buffer, size_t length, if (write_bytes > 0) { return static_cast(write_bytes); } - return recoverable_error("Currently busy"); + return make_error(); } conveyor unix_datagram::write_ready() { @@ -742,12 +742,12 @@ conveyor> unix_network::connect(network_address &addr) { assert(address.unix_address_size() > 0); if (address.unix_address_size() == 0) { - return conveyor>{critical_error("No address found")}; + return conveyor>{make_error()}; } int fd = address.unix_address(0).socket(SOCK_STREAM); if (fd < 0) { - return conveyor>{critical_error("Couldn't open socket")}; + return conveyor>{make_error()}; } own io_str = @@ -780,8 +780,7 @@ conveyor> unix_network::connect(network_address &addr) { break; } else if (error != EINTR) { /// @todo Push error message from - return conveyor>{ - critical_error("Couldn't connect")}; + return conveyor>{make_error()}; } } else { success = true; @@ -790,7 +789,7 @@ conveyor> unix_network::connect(network_address &addr) { } if (!success) { - return critical_error("Couldn't connect"); + return conveyor>{make_error()}; } return conveyor>{std::move(io_str)}; @@ -888,7 +887,7 @@ error_or setup_async_io() { return {{std::move(io_provider), loop_ref, prt_ref}}; } catch (std::bad_alloc &) { - return critical_error("Out of memory"); + return make_error(); } } } // namespace saw -- cgit v1.2.3