![]() |
libghostty
|
Synchronous callback interfaces used by APIs that consume or produce byte streams. The callback and userdata pointers must remain valid for the full lifetime documented by the API receiving a GhosttyReader or GhosttyWriter.
Typedefs | |
| typedef bool(* | GhosttyReaderFn) (void *userdata, uint8_t *buffer, size_t capacity, size_t *out_read) |
| typedef bool(* | GhosttyWriterFn) (void *userdata, const uint8_t *data, size_t len) |
Data Structures | |
| struct | GhosttyReader |
| struct | GhosttyWriter |
| typedef bool(* GhosttyReaderFn) (void *userdata, uint8_t *buffer, size_t capacity, size_t *out_read) |
Read bytes from a source.
The callback must set out_read to a value no greater than capacity when returning true. A positive value reports progress; it may be less than capacity and does not indicate end-of-file. A zero value is definitive end-of-file. It must not be used to report temporary input starvation or a would-block condition.
Returning false reports a fatal read error and the value of out_read is ignored. The library does not inspect or modify errno.
All pointer arguments are borrowed and valid only for the duration of the callback. The callback is invoked synchronously on the calling thread.
| userdata | Opaque userdata from GhosttyReader | |
| buffer | Destination for read bytes; always non-NULL | |
| capacity | Writable capacity of buffer; always greater than zero | |
| [out] | out_read | Number of bytes read when returning true; non-NULL |
| typedef bool(* GhosttyWriterFn) (void *userdata, const uint8_t *data, size_t len) |
Write bytes to a destination.
Returning true means all len bytes were accepted. Returning false reports a fatal write error. A callback wrapping an interface that permits partial writes must retry internally until the full slice is accepted or an error occurs.
On failure, the destination may already contain a prefix of the bytes. The calling operation fails and must not be resumed from that partial output. The library does not inspect or modify errno.
data is borrowed and valid only for the duration of the callback. The callback is invoked synchronously on the calling thread. Successful return means the bytes were handed to the destination; it does not imply that the destination was flushed or made durable.
| userdata | Opaque userdata from GhosttyWriter |
| data | Source bytes; always non-NULL |
| len | Number of source bytes; always greater than zero |