A handle representing ownership of a buffer reservation for writing a packet, providing container-like access to the underlying buffer.
A socket may close between the time a WriteReservation is provisioned and Commit is called. If this occurs, Commit will return false, and no packet will be queued.
Destructing a WriteReservation releases the underlying buffer back to the transport.
Public Types | |
| using | iterator = Buf::iterator |
| using | const_iterator = Buf::const_iterator |
Public Member Functions | |
| WriteReservation (const WriteReservation &)=delete | |
| WriteReservation & | operator= (const WriteReservation &)=delete |
| WriteReservation (WriteReservation &&other) noexcept=default | |
| WriteReservation & | operator= (WriteReservation &&other) noexcept |
| std::byte * | data () |
| Returns a pointer to the start of the reserved write buffer. | |
| const std::byte * | data () const |
| size_t | size () const |
| Returns the size of the reserved write buffer in bytes. | |
| std::byte & | operator[] (size_t index) |
| Accesses the byte at the specified index. | |
| const std::byte & | operator[] (size_t index) const |
| iterator | begin () |
| Returns an iterator to the beginning of the reserved buffer. | |
| const_iterator | begin () const |
| const_iterator | cbegin () const |
| iterator | end () |
| Returns an iterator to the end of the reserved buffer. | |
| const_iterator | end () const |
| const_iterator | cend () const |
| bool | Commit (size_t size_bytes) |
| void | Cancel () |
Friends | |
| class | ReliableDatagramSocketImpl |
| void pw::transport::WriteReservation::Cancel | ( | ) |
Explicitly cancels the reservation, releasing the buffer back to the socket without transmitting any data.
| bool pw::transport::WriteReservation::Commit | ( | size_t | size_bytes | ) |
Commits the written data in the reserved buffer, queueing it for transmission. Truncates the buffer to size_bytes. Returns true on success, or false if the socket has closed or transmission fails. Once committed, the reservation is consumed and cannot be reused or canceled.
size_bytes must not exceed the reservation's size, or it will assert.