Skip to content

Commit

Permalink
AK+LibTest: Relax read size requirement for AsyncInputStream
Browse files Browse the repository at this point in the history
This turned out to be a bit too strict. Streams might have sub-byte
structure which will be difficult to lex while satisfying the old size
condition. Since replacing the strict comparison with a non-strict one
doesn't break anything (including time complexity), just do this.
  • Loading branch information
DanShaders committed May 19, 2024
1 parent bd70274 commit 4eefc2a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions AK/AsyncStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ class AsyncResource {
// should ensure the following: at the time of `read`, let (s_1, s_2, ..., s_n) be a sequence of
// lengths of ReadonlyBytes returned from `peek` or `peek_or_eof` since the last read (or since the
// creation of the stream, if there were no previous reads). If n > 1 and s_n != s_{n - 1},
// s_{n - 1} must be strictly less than `bytes` parameter. If n == 1 and s_n == s_{n - 1} (EOF
// has been reached), `bytes` must equal to s_n. While the behavior if the caller fails to satisfy
// the requirement is well-defined, violation of it almost always indicates a bug in the caller's
// code. Additionally, the asynchronous streams framework doesn't guarantee linear asymptotic
// runtime complexity in the case of violation.
// s_{n - 1} must be not greater than `bytes` parameter. If n == 1 and s_n == s_{n - 1} (EOF has
// been reached), `bytes` must equal to s_n. While the behavior if the caller fails to satisfy the
// requirement is well-defined, violation of it almost always indicates a bug in the caller's code.
// Additionally, the asynchronous streams framework doesn't guarantee linear asymptotic runtime
// complexity in the case of violation.
//
// Note that `read` always returns exactly `bytes` bytes. If `bytes` is larger than s_n or n is 0,
// `read` will return more data than previously peeked (by reading the stream, obviously).
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibTest/AsyncTestStreams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ ReadonlyBytes AsyncMemoryInputStream::buffered_data_unchecked(Badge<AsyncInputSt
void AsyncMemoryInputStream::dequeue(Badge<AsyncInputStream>, size_t bytes)
{
m_read_head += bytes;
VERIFY(m_last_enqueue < m_read_head && m_read_head <= m_peek_head);
VERIFY(m_last_enqueue <= m_read_head && m_read_head <= m_peek_head);
}

AsyncMemoryOutputStream::AsyncMemoryOutputStream(StreamCloseExpectation expectation)
Expand Down

0 comments on commit 4eefc2a

Please sign in to comment.