libghostty
Loading...
Searching...
No Matches
I/O

Detailed Description

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)
typedef bool(*) GhosttyMimeReaderFn(void *userdata, GhosttyString mime, GhosttyWriter writer)

Data Structures

struct  GhosttyReader
struct  GhosttyWriter
struct  GhosttyMimeReader

Typedef Documentation

◆ GhosttyMimeReaderFn

typedef bool(*) GhosttyMimeReaderFn(void *userdata, GhosttyString mime, GhosttyWriter writer)

Read one MIME-typed representation of some content, streaming its bytes to a writer.

The library calls this with the MIME type of the representation it needs. The callback writes all of that representation's data to writer, in as many calls to writer.write(writer.userdata, data, len) as is convenient (one call with everything or many small pieces both work), and returns true. Nothing written is retained beyond each write call, so the data may be borrowed from anywhere: a pasteboard item, a file being read, a stream.

Returning false reports that the data could not be read. If the writer refuses a write (returns false), stop and return false without writing more.

All pointer arguments, the mime, and the writer are borrowed and valid only for the duration of the callback. The callback is invoked synchronously on the calling thread. The API receiving the GhosttyMimeReader defines which MIME types are requested, how many times, and any consistency requirements across repeated reads.

Parameters
userdataOpaque userdata from GhosttyMimeReader
mimeThe MIME type of the representation to read
writerWhere to write the data; valid only during this call
Returns
true once all the data was written, false if it could not be read or the writer refused a write

Definition at line 130 of file io.h.

◆ GhosttyReaderFn

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.

Parameters
userdataOpaque userdata from GhosttyReader
bufferDestination for read bytes; always non-NULL
capacityWritable capacity of buffer; always greater than zero
[out]out_readNumber of bytes read when returning true; non-NULL
Returns
true for a successful read or end-of-file, false for a fatal error

Definition at line 49 of file io.h.

◆ GhosttyWriterFn

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.

Parameters
userdataOpaque userdata from GhosttyWriter
dataSource bytes; always non-NULL
lenNumber of source bytes; always greater than zero
Returns
true if the complete slice was accepted, false on fatal error

Definition at line 77 of file io.h.