diff options
author | sin-ack <sin-ack@users.noreply.github.com> | 2021-12-29 23:13:11 +0000 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2022-01-13 15:16:12 +0330 |
commit | 5f645e84d89a727eb9205a4e1c325e7cdc910421 (patch) | |
tree | df2edcbf33846bcb5db946bc5f7a9deb1ef09878 /Userland/Libraries/LibCore/Stream.h | |
parent | dbd25916a3029a4b87b658986e11a39803b15b64 (diff) | |
download | serenity-5f645e84d89a727eb9205a4e1c325e7cdc910421.zip |
LibCore: Use Error::from_errno in Stream APIs
This makes Stream APIs work with Lagom and is overall cleaner.
Diffstat (limited to 'Userland/Libraries/LibCore/Stream.h')
-rw-r--r-- | Userland/Libraries/LibCore/Stream.h | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/Userland/Libraries/LibCore/Stream.h b/Userland/Libraries/LibCore/Stream.h index af409537b1..d940760da6 100644 --- a/Userland/Libraries/LibCore/Stream.h +++ b/Userland/Libraries/LibCore/Stream.h @@ -340,7 +340,7 @@ public: // datagram to be discarded. That's not very nice, so let's bail // early, telling the caller that he should allocate a bigger // buffer. - return EMSGSIZE; + return Error::from_errno(EMSGSIZE); } return m_helper.read(buffer); @@ -469,13 +469,13 @@ public: static ErrorOr<NonnullOwnPtr<BufferedType<T>>> create_buffered(NonnullOwnPtr<T> stream, size_t buffer_size) { if (!buffer_size) - return EINVAL; + return Error::from_errno(EINVAL); if (!stream->is_open()) - return ENOTCONN; + return Error::from_errno(ENOTCONN); auto maybe_buffer = ByteBuffer::create_uninitialized(buffer_size); if (!maybe_buffer.has_value()) - return ENOMEM; + return Error::from_errno(ENOMEM); return adopt_nonnull_own_or_enomem(new BufferedType<T>(move(stream), maybe_buffer.release_value())); } @@ -486,9 +486,9 @@ public: ErrorOr<size_t> read(Bytes buffer) { if (!stream().is_open()) - return ENOTCONN; + return Error::from_errno(ENOTCONN); if (!buffer.size()) - return ENOBUFS; + return Error::from_errno(ENOBUFS); // Let's try to take all we can from the buffer first. size_t buffer_nread = 0; @@ -536,10 +536,10 @@ public: ErrorOr<size_t> read_until_any_of(Bytes buffer, Array<StringView, N> candidates) { if (!stream().is_open()) - return ENOTCONN; + return Error::from_errno(ENOTCONN); if (buffer.is_empty()) - return ENOBUFS; + return Error::from_errno(ENOBUFS); // We fill the buffer through can_read_line. if (!TRY(can_read_line())) @@ -557,7 +557,7 @@ public: // violating the invariant twice the next time the user attempts // to read, which is No Good. So let's give a descriptive error // to the caller about why it can't read. - return EMSGSIZE; + return Error::from_errno(EMSGSIZE); } m_buffer.span().slice(0, m_buffered_size).copy_to(buffer); |