diff options
author | AnotherTest <ali.mpfard@gmail.com> | 2020-05-15 10:45:09 +0430 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-15 09:50:48 +0200 |
commit | 3485613f4ad2e766378c6a503879d04a8884bf89 (patch) | |
tree | 022ff50666ba302c974496591ce2500c4df7a21d /Libraries/LibCore | |
parent | 5386508119e5f4d9837e1015a4a3f819da7082a7 (diff) | |
download | serenity-3485613f4ad2e766378c6a503879d04a8884bf89.zip |
LibCore: Make IODevice::can_read_line() const
This also makes LibHTTP's Job::can_read_line() const, as IODevice was
keeping that from being const.
Fixes #2219
Diffstat (limited to 'Libraries/LibCore')
-rw-r--r-- | Libraries/LibCore/IODevice.cpp | 4 | ||||
-rw-r--r-- | Libraries/LibCore/IODevice.h | 17 |
2 files changed, 10 insertions, 11 deletions
diff --git a/Libraries/LibCore/IODevice.cpp b/Libraries/LibCore/IODevice.cpp index 3ee2ea0317..df69d3b182 100644 --- a/Libraries/LibCore/IODevice.cpp +++ b/Libraries/LibCore/IODevice.cpp @@ -121,7 +121,7 @@ bool IODevice::can_read_from_fd() const return FD_ISSET(m_fd, &rfds); } -bool IODevice::can_read_line() +bool IODevice::can_read_line() const { if (m_eof && !m_buffered_data.is_empty()) return true; @@ -206,7 +206,7 @@ ByteBuffer IODevice::read_line(size_t max_size) return {}; } -bool IODevice::populate_read_buffer() +bool IODevice::populate_read_buffer() const { if (m_fd < 0) return false; diff --git a/Libraries/LibCore/IODevice.h b/Libraries/LibCore/IODevice.h index 081e21f015..8c8ee6beb6 100644 --- a/Libraries/LibCore/IODevice.h +++ b/Libraries/LibCore/IODevice.h @@ -65,8 +65,7 @@ public: bool write(const u8*, int size); bool write(const StringView&); - // FIXME: I would like this to be const but currently it needs to call populate_read_buffer(). - bool can_read_line(); + bool can_read_line() const; bool can_read() const; @@ -88,20 +87,20 @@ protected: void set_fd(int); void set_mode(OpenMode mode) { m_mode = mode; } - void set_error(int error) { m_error = error; } - void set_eof(bool eof) { m_eof = eof; } + void set_error(int error) const { m_error = error; } + void set_eof(bool eof) const { m_eof = eof; } - virtual void did_update_fd(int) {} + virtual void did_update_fd(int) { } private: - bool populate_read_buffer(); + bool populate_read_buffer() const; bool can_read_from_fd() const; int m_fd { -1 }; - int m_error { 0 }; - bool m_eof { false }; OpenMode m_mode { NotOpen }; - Vector<u8> m_buffered_data; + mutable int m_error { 0 }; + mutable bool m_eof { false }; + mutable Vector<u8> m_buffered_data; }; } |