Skip to content

Commit 5061a90

Browse files
timschumiawesomekling
authored andcommitted
LibCore: Remove Stream::is_{readable,writable}
Next to functions like `is_eof` these were really confusing to use, and the `read`/`write` functions should fail anyways if a stream is not readable/writable.
1 parent 5a346c4 commit 5061a90

File tree

7 files changed

+1
-32
lines changed

7 files changed

+1
-32
lines changed

Meta/Lagom/Wasm/js_repl.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ void displayln() { user_display("\n", 1); }
6565

6666
class UserDisplayStream final : public Core::Stream::Stream {
6767
virtual ErrorOr<Bytes> read(Bytes) override { return Error::from_string_view("Not readable"sv); };
68-
virtual bool is_writable() const override { return true; }
6968
virtual ErrorOr<size_t> write(ReadonlyBytes bytes) override
7069
{
7170
user_display(bit_cast<char const*>(bytes.data()), bytes.size());

Tests/LibCore/TestLibCoreStream.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ TEST_CASE(file_open)
2929
// Testing out some basic file properties.
3030
auto file = maybe_file.release_value();
3131
EXPECT(file->is_open());
32-
EXPECT(!file->is_readable());
33-
EXPECT(file->is_writable());
3432
EXPECT(!file->is_eof());
3533

3634
auto maybe_size = file->size();

Userland/Libraries/LibCompress/Brotli.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,7 @@ class BrotliDecompressionStream : public Stream {
107107
public:
108108
BrotliDecompressionStream(Stream&);
109109

110-
bool is_readable() const override { return m_input_stream.is_readable(); }
111110
ErrorOr<Bytes> read(Bytes output_buffer) override;
112-
bool is_writable() const override { return m_input_stream.is_writable(); }
113111
ErrorOr<size_t> write(ReadonlyBytes bytes) override { return m_input_stream.write(bytes); }
114112
bool is_eof() const override;
115113
bool is_open() const override { return m_input_stream.is_open(); }

Userland/Libraries/LibCore/InputBitStream.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class BigEndianInputBitStream : public Stream {
3030
}
3131

3232
// ^Stream
33-
virtual bool is_readable() const override { return m_stream.is_readable(); }
3433
virtual ErrorOr<Bytes> read(Bytes bytes) override
3534
{
3635
if (m_current_byte.has_value() && is_aligned_to_byte_boundary()) {
@@ -40,7 +39,6 @@ class BigEndianInputBitStream : public Stream {
4039
align_to_byte_boundary();
4140
return m_stream.read(bytes);
4241
}
43-
virtual bool is_writable() const override { return m_stream.is_writable(); }
4442
virtual ErrorOr<size_t> write(ReadonlyBytes bytes) override { return m_stream.write(bytes); }
4543
virtual bool write_or_error(ReadonlyBytes bytes) override { return m_stream.write_or_error(bytes); }
4644
virtual bool is_eof() const override { return m_stream.is_eof() && !m_current_byte.has_value(); }
@@ -147,7 +145,6 @@ class LittleEndianInputBitStream : public Stream {
147145
}
148146

149147
// ^Stream
150-
virtual bool is_readable() const override { return m_stream.is_readable(); }
151148
virtual ErrorOr<Bytes> read(Bytes bytes) override
152149
{
153150
if (m_current_byte.has_value() && is_aligned_to_byte_boundary()) {
@@ -157,7 +154,6 @@ class LittleEndianInputBitStream : public Stream {
157154
align_to_byte_boundary();
158155
return m_stream.read(bytes);
159156
}
160-
virtual bool is_writable() const override { return m_stream.is_writable(); }
161157
virtual ErrorOr<size_t> write(ReadonlyBytes bytes) override { return m_stream.write(bytes); }
162158
virtual bool write_or_error(ReadonlyBytes bytes) override { return m_stream.write_or_error(bytes); }
163159
virtual bool is_eof() const override { return m_stream.is_eof() && !m_current_byte.has_value(); }

Userland/Libraries/LibCore/Stream.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,6 @@ ErrorOr<void> File::open_path(StringView filename, mode_t permissions)
229229
return {};
230230
}
231231

232-
bool File::is_readable() const { return has_flag(m_mode, OpenMode::Read); }
233-
bool File::is_writable() const { return has_flag(m_mode, OpenMode::Write); }
234-
235232
ErrorOr<Bytes> File::read(Bytes buffer)
236233
{
237234
if (!has_flag(m_mode, OpenMode::Read)) {

Userland/Libraries/LibCore/Stream.h

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ namespace Core::Stream {
2828
/// operations one can perform on every stream in LibCore.
2929
class Stream {
3030
public:
31-
virtual bool is_readable() const { return false; }
3231
/// Reads into a buffer, with the maximum size being the size of the buffer.
3332
/// The amount of bytes read can be smaller than the size of the buffer.
3433
/// Returns either the bytes that were read, or an errno in the case of
@@ -46,7 +45,6 @@ class Stream {
4645
/// internal stack-based buffer.
4746
virtual ErrorOr<void> discard(size_t discarded_bytes);
4847

49-
virtual bool is_writable() const { return false; }
5048
/// Tries to write the entire contents of the buffer. It is possible for
5149
/// less than the full buffer to be written. Returns either the amount of
5250
/// bytes written into the stream, or an errno in the case of failure.
@@ -239,10 +237,8 @@ class File final : public SeekableStream {
239237
return *this;
240238
}
241239

242-
virtual bool is_readable() const override;
243240
virtual ErrorOr<Bytes> read(Bytes) override;
244241
virtual ErrorOr<ByteBuffer> read_all(size_t block_size = 4096) override;
245-
virtual bool is_writable() const override;
246242
virtual ErrorOr<size_t> write(ReadonlyBytes) override;
247243
virtual bool is_eof() const override;
248244
virtual bool is_open() const override;
@@ -346,8 +342,6 @@ class TCPSocket final : public Socket {
346342
return *this;
347343
}
348344

349-
virtual bool is_readable() const override { return is_open(); }
350-
virtual bool is_writable() const override { return is_open(); }
351345
virtual ErrorOr<Bytes> read(Bytes buffer) override { return m_helper.read(buffer, default_flags()); }
352346
virtual ErrorOr<size_t> write(ReadonlyBytes buffer) override { return m_helper.write(buffer, default_flags()); }
353347
virtual bool is_eof() const override { return m_helper.is_eof(); }
@@ -423,8 +417,6 @@ class UDPSocket final : public Socket {
423417
return m_helper.read(buffer, default_flags());
424418
}
425419

426-
virtual bool is_readable() const override { return is_open(); }
427-
virtual bool is_writable() const override { return is_open(); }
428420
virtual ErrorOr<size_t> write(ReadonlyBytes buffer) override { return m_helper.write(buffer, default_flags()); }
429421
virtual bool is_eof() const override { return m_helper.is_eof(); }
430422
virtual bool is_open() const override { return m_helper.is_open(); }
@@ -484,8 +476,6 @@ class LocalSocket final : public Socket {
484476
return *this;
485477
}
486478

487-
virtual bool is_readable() const override { return is_open(); }
488-
virtual bool is_writable() const override { return is_open(); }
489479
virtual ErrorOr<Bytes> read(Bytes buffer) override { return m_helper.read(buffer, default_flags()); }
490480
virtual ErrorOr<size_t> write(ReadonlyBytes buffer) override { return m_helper.write(buffer, default_flags()); }
491481
virtual bool is_eof() const override { return m_helper.is_eof(); }
@@ -717,7 +707,7 @@ class BufferedHelper {
717707
if (m_buffer.span().slice(0, m_buffered_size).contains_slow('\n'))
718708
return true;
719709

720-
if (!stream().is_readable())
710+
if (stream().is_eof())
721711
return false;
722712

723713
while (m_buffered_size < m_buffer.size()) {
@@ -818,9 +808,7 @@ class BufferedSeekable final : public SeekableStream {
818808
BufferedSeekable(BufferedSeekable&& other) = default;
819809
BufferedSeekable& operator=(BufferedSeekable&& other) = default;
820810

821-
virtual bool is_readable() const override { return m_helper.stream().is_readable(); }
822811
virtual ErrorOr<Bytes> read(Bytes buffer) override { return m_helper.read(move(buffer)); }
823-
virtual bool is_writable() const override { return m_helper.stream().is_writable(); }
824812
virtual ErrorOr<size_t> write(ReadonlyBytes buffer) override { return m_helper.stream().write(buffer); }
825813
virtual bool is_eof() const override { return m_helper.is_eof(); }
826814
virtual bool is_open() const override { return m_helper.stream().is_open(); }
@@ -889,9 +877,7 @@ class BufferedSocket final : public BufferedSocketBase {
889877
return *this;
890878
}
891879

892-
virtual bool is_readable() const override { return m_helper.stream().is_readable(); }
893880
virtual ErrorOr<Bytes> read(Bytes buffer) override { return m_helper.read(move(buffer)); }
894-
virtual bool is_writable() const override { return m_helper.stream().is_writable(); }
895881
virtual ErrorOr<size_t> write(ReadonlyBytes buffer) override { return m_helper.stream().write(buffer); }
896882
virtual bool is_eof() const override { return m_helper.is_eof(); }
897883
virtual bool is_open() const override { return m_helper.stream().is_open(); }
@@ -977,9 +963,7 @@ class BasicReusableSocket final : public ReusableSocket {
977963
return {};
978964
}
979965

980-
virtual bool is_readable() const override { return m_socket.is_readable(); }
981966
virtual ErrorOr<Bytes> read(Bytes buffer) override { return m_socket.read(move(buffer)); }
982-
virtual bool is_writable() const override { return m_socket.is_writable(); }
983967
virtual ErrorOr<size_t> write(ReadonlyBytes buffer) override { return m_socket.write(buffer); }
984968
virtual bool is_eof() const override { return m_socket.is_eof(); }
985969
virtual bool is_open() const override { return m_socket.is_open(); }

Userland/Libraries/LibTLS/TLSv12.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,6 @@ class TLSv12 final : public Core::Stream::Socket {
356356
}
357357

358358
public:
359-
virtual bool is_readable() const override { return true; }
360-
virtual bool is_writable() const override { return true; }
361-
362359
/// Reads into a buffer, with the maximum size being the size of the buffer.
363360
/// The amount of bytes read can be smaller than the size of the buffer.
364361
/// Returns either the bytes that were read, or an errno in the case of

0 commit comments

Comments
 (0)