You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Align read_some/write_some to E2 semantics and add exception docs
Adopt the relaxed error postcondition (n >= 0 on error) from the
read-some-rationale consensus throughout headers, implementation,
docs, examples, and papers. Fix composed algorithms (read, write,
write_now, push_to) to use advance-then-check ordering. Replace
.failed() with operator bool() idiom. Add error reporting and
throws documentation to all concept Javadocs and the rationale doc.
Introduce await-returns terminology per stakeholder feedback. Use
C++ expressions for range constraints. Remove if(n > 0) guards
from echo loops in favor of unconditional write-then-check pattern.
Returns an awaitable yielding `(error_code, std::size_t)`:
31
+
Attempts to read up to `buffer_size(buffers)` bytes from the stream into the buffer sequence. Await-returns `(error_code, std::size_t)`:
32
32
33
-
* On success: `!ec`, and `n >= 1` bytes were read
34
-
* On error: `ec`, and `n == 0`
35
-
* On EOF: `ec == cond::eof`, and `n == 0`
33
+
If `buffer_size(buffers) > 0`:
36
34
37
-
If `buffer_empty(buffers)` is true, completes immediately with `n == 0` and no error.
35
+
* If `!ec`, then `n >= 1 && n \<= buffer_size(buffers)`. `n` bytes were read into the buffer sequence.
36
+
* If `ec`, then `n >= 0 && n \<= buffer_size(buffers)`. `n` is the number of bytes read before the I/O condition arose.
37
+
38
+
If `buffer_empty(buffers)` is true, `n` is 0. The empty buffer is not itself a cause for error, but `ec` may reflect the state of the stream.
39
+
40
+
I/O conditions from the underlying system are reported via `ec`. Failures in the library itself (such as allocation failure) are reported via exceptions.
41
+
42
+
*Throws:* `std::bad_alloc` if coroutine frame allocation fails.
38
43
39
44
=== Partial Transfer
40
45
@@ -45,7 +50,7 @@ If `buffer_empty(buffers)` is true, completes immediately with `n == 0` and no e
45
50
char buf[1024];
46
51
auto [ec, n] = co_await stream.read_some(mutable_buffer(buf));
47
52
// n might be 1, might be 500, might be 1024
48
-
// The only guarantee: if !ec && n > 0
53
+
// if !ec, then n >= 1
49
54
----
50
55
51
56
This matches underlying OS behavior—reads return when *some* data is available.
@@ -58,18 +63,15 @@ template<ReadStream Stream>
58
63
task<> dump_stream(Stream& stream)
59
64
{
60
65
char buf[256];
61
-
66
+
62
67
for (;;)
63
68
{
64
69
auto [ec, n] = co_await stream.read_some(mutable_buffer(buf));
Returns an awaitable yielding `(error_code, std::size_t)`:
100
+
Attempts to write up to `buffer_size(buffers)` bytes from the buffer sequence to the stream. Await-returns `(error_code, std::size_t)`:
99
101
100
-
* On success: `!ec`, and `n >= 1` bytes were written
101
-
* On error: `ec`, and `n == 0`
102
+
If `buffer_size(buffers) > 0`:
102
103
103
-
If `buffer_empty(buffers)` is true, completes immediately with `n == 0` and no error.
104
+
* If `!ec`, then `n >= 1 && n \<= buffer_size(buffers)`. `n` bytes were written from the buffer sequence.
105
+
* If `ec`, then `n >= 0 && n \<= buffer_size(buffers)`. `n` is the number of bytes written before the I/O condition arose.
106
+
107
+
If `buffer_empty(buffers)` is true, `n` is 0. The empty buffer is not itself a cause for error, but `ec` may reflect the state of the stream.
108
+
109
+
I/O conditions from the underlying system are reported via `ec`. Failures in the library itself (such as allocation failure) are reported via exceptions.
110
+
111
+
*Throws:* `std::bad_alloc` if coroutine frame allocation fails.
Copy file name to clipboardExpand all lines: doc/modules/ROOT/pages/6.streams/6d.buffer-concepts.adoc
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -52,11 +52,11 @@ concept BufferSource =
52
52
IoAwaitable auto pull(const_buffer* arr, std::size_t max_count);
53
53
----
54
54
55
-
Returns an awaitable yielding `(error_code, std::size_t)`:
55
+
Await-returns `(error_code, std::size_t)`:
56
56
57
-
* On success: `!ec.failed()`, fills `arr[0..count-1]` with buffer descriptors
57
+
* On success: `!ec`, fills `arr[0..count-1]` with buffer descriptors
58
58
* On exhausted: `count == 0` indicates no more data
59
-
* On error: `ec.failed()`
59
+
* On error: `ec`
60
60
61
61
The buffers point into the source's internal storage. You must consume all returned data before calling `pull()` again—the previous buffers become invalid.
0 commit comments