PdcommSecs1Read
Typedef
Reads bytes from the serial stream without blocking.
typedef uint32_t (*PdcommSecs1Read)(void *context, uint8_t *buffer, size_t capacity, size_t *count)Called only from pdcomm_secs1_poll() on the endpoint's thread. The endpoint asks for one byte while it expects a line-control character and otherwise for at most one block's worth of bytes, never more than PdcommSecs1Options::max_io_chunk. For every result other than #PDCOMM_SECS1_IO_OK, buffer and count are ignored.
Parameters
| Name | Description |
|---|---|
context | The PdcommSecs1Io::context value. |
buffer | Destination for at most capacity bytes. |
capacity | Number of bytes requested; at least 1. |
count | Receives the number of bytes stored. It is 0 on entry and is read only when the callback returns #PDCOMM_SECS1_IO_OK. |
Returns
#PDCOMM_SECS1_IO_OK with *count bytes stored (0 means end of stream); #PDCOMM_SECS1_IO_WOULD_BLOCK or #PDCOMM_SECS1_IO_INTERRUPTED when no data is available now; #PDCOMM_SECS1_IO_CLOSED at end of stream; any other PDCOMM_SECS1_IO_* value to report a failure, which faults the endpoint.
Notes
- Do not block: a blocking read stalls pdcomm_secs1_poll(). Do not call endpoint functions from the callback; reentry returns #PDCOMM_INVALID_STATE. A count greater than
capacityfaults the endpoint with detail #PDCOMM_SECS1_IO_INVALID_DATA. - C++ implementations must catch every exception before returning; pdcomm_secs1.hpp provides a safe typed adapter.