17 Buffer-oriented streams [buffer.stream]

17.1 Requirements [buffer.stream.reqmts]

17.1.1 Buffer-oriented synchronous read stream requirements [buffer.stream.reqmts.syncreadstream]

A type X meets the SyncReadStream requirements if it satisfies the requirements listed in Table [tab:buffer.stream.reqmts.syncreadstream.requirements].

An orderly shutdown is the procedure for shutting down a stream after all work in progress has been completed, without loss of data.

In Table [tab:buffer.stream.reqmts.syncreadstream.requirements], a denotes a value of type X, mb denotes a (possibly const) value of a type satisfying the MutableBufferSequence ([buffer.reqmts.mutablebuffersequence]) requirements, and ec denotes an object of type error_code.

Table 16 — SyncReadStream requirements
operationtypesemantics, pre/post-conditions
a.read_some(mb) a.read_some(mb,ec) size_t Meets the requirements for a read operation ([buffer.reqmts.read.write]).
If buffer_size(mb) > 0, reads one or more bytes of data from the stream a into the buffer sequence mb. If successful, sets ec such that !ec is true, and returns the number of bytes read. If an error occurred, sets ec such that !!ec is true, and returns 0. If all data has been read from the stream, and the stream performed an orderly shutdown, sets ec to stream_errc::eof and returns 0. If buffer_size(mb) == 0, the operation shall not block. Sets ec such that !ec is true, and returns 0.

17.1.2 Buffer-oriented asynchronous read stream requirements [buffer.stream.reqmts.asyncreadstream]

A type X meets the AsyncReadStream requirements if it satisfies the requirements listed below.

In the table below, a denotes a value of type X, mb denotes a (possibly const) value of a type satisfying the MutableBufferSequence ([buffer.reqmts.mutablebuffersequence]) requirements, and t is a completion token.

Table 17 — AsyncReadStream requirements
operationtypesemantics, pre/post-conditions
a.get_executor() A type satisfying the Executor requirements ([async.reqmts.executor]). Returns the associated I/O executor.
a.async_read_some(mb,t) The return type is determined according to the requirements for an asynchronous operation ([async.reqmts.async]). Meets the requirements for a read operation ([buffer.reqmts.read.write]) and an asynchronous operation ([async.reqmts.async]) with completion signature void(error_code ec, size_t n).
If buffer_size(mb) > 0, initiates an asynchronous operation to read one or more bytes of data from the stream a into the buffer sequence mb. If successful, ec is set such that !ec is true, and n is the number of bytes read. If an error occurred, ec is set such that !!ec is true, and n is 0. If all data has been read from the stream, and the stream performed an orderly shutdown, ec is stream_errc::eof and n is 0. If buffer_size(mb) == 0, the operation completes immediately. ec is set such that !ec is true, and n is 0.

17.1.3 Buffer-oriented synchronous write stream requirements [buffer.stream.reqmts.syncwritestream]

A type X meets the SyncWriteStream requirements if it satisfies the requirements listed below.

In the table below, a denotes a value of type X, cb denotes a (possibly const) value of a type satisfying the ConstBufferSequence ([buffer.reqmts.constbuffersequence]) requirements, and ec denotes an object of type error_code.

Table 18 — SyncWriteStream requirements
operationtypesemantics, pre/post-conditions
a.write_some(cb) a.write_some(cb,ec) size_t Meets the requirements for a write operation ([buffer.reqmts.read.write]).
If buffer_size(cb) > 0, writes one or more bytes of data to the stream a from the buffer sequence cb. If successful, sets ec such that !ec is true, and returns the number of bytes written. If an error occurred, sets ec such that !!ec is true, and returns 0. If buffer_size(cb) == 0, the operation shall not block. Sets ec such that !ec is true, and returns 0.

17.1.4 Buffer-oriented asynchronous write stream requirements [buffer.stream.reqmts.asyncwritestream]

A type X meets the AsyncWriteStream requirements if it satisfies the requirements listed below.

In the table below, a denotes a value of type X, cb denotes a (possibly const) value of a type satisfying the ConstBufferSequence ([buffer.reqmts.constbuffersequence]) requirements, and t is a completion token.

Table 19 — AsyncWriteStream requirements
operationtypesemantics, pre/post-conditions
a.get_executor() A type satisfying the Executor requirements ([async.reqmts.executor]). Returns the associated I/O executor.
a.async_write_some(cb,t) The return type is determined according to the requirements for an asynchronous operation ([async.reqmts.async]). Meets the requirements for a write operation ([buffer.reqmts.read.write]) and an asynchronous operation ([async.reqmts.async]) with completion signature void(error_code ec, size_t n).
If buffer_size(cb) > 0, initiates an asynchronous operation to write one or more bytes of data to the stream a from the buffer sequence cb. If successful, ec is set such that !ec is true, and n is the number of bytes written. If an error occurred, ec is set such that !!ec is true, and n is 0. If buffer_size(cb) == 0, the operation completes immediately. ec is set such that !ec is true, and n is 0.

17.1.5 Completion condition requirements [buffer.stream.reqmts.completioncondition]

A completion condition is a function object that is used with the algorithms read ([buffer.read]), async_read ([buffer.async.read]), write ([buffer.write]), and async_write ([buffer.async.write]) to determine when the algorithm has completed transferring data.

A type X meets the CompletionCondition requirements if it satisfies the requirements of Destructible (C++ 2014 [destructible]) and CopyConstructible (C++ 2014 [copyconstructible]), as well as the additional requirements listed below.

In the table below, x denotes a value of type X, ec denotes a (possibly const) value of type error_code, and n denotes a (possibly const) value of type size_t.

Table 20 — CompletionCondition requirements
expressionreturn typeassertion/note pre/post-condition
x(ec, n) size_t Let n be the total number of bytes transferred by the read or write algorithm so far.
Returns the maximum number of bytes to be transferred on the next read_some, async_read_some, write_some, or async_write_some operation performed by the algorithm. Returns 0 to indicate that the algorithm is complete.