I/O
Read and write streams and HANDLEs, work with sockets and DNS, use owned buffers, and call filesystem wrappers. These calls look blocking from task code, but managed tasks park while the backend waits.
On this page
Stream and handle I/O
llam_readStream fd/socket I/O through the runtime path where possible.
ssize_t llam_read(llam_fd_t fd, void *buf, size_t count);Read from fd using the runtime I/O backend where possible.
Managed tasks first try a direct nonblocking fast path, then the platform backend, then a blocking helper so the scheduler worker is not pinned. Calls outside a managed LLAM task delegate to the platform read primitive directly and may block the calling OS thread.
llam_writeStream fd/socket I/O through the runtime path where possible.
ssize_t llam_write(llam_fd_t fd, const void *buf, size_t count);Write to fd using the runtime I/O backend where possible.
Managed tasks first try a direct nonblocking fast path, then the platform backend, then a blocking helper so the scheduler worker is not pinned. Calls outside a managed LLAM task delegate to the platform write primitive directly and may block the calling OS thread.
llam_read_handleGeneric platform handle I/O. On Windows, use this for HANDLEs.
ssize_t llam_read_handle(llam_handle_t handle, void *buf, size_t count);Read from a generic platform handle.
On Windows this API submits overlapped ReadFile operations to the native IOCP backend when the handle supports overlapped I/O. If the backend cannot accept the handle, managed tasks fall back to the blocking-helper pool so the scheduler worker is not pinned. On POSIX, llam_handle_t aliases llam_fd_t and this function delegates to llam_read. This API is intended for pipe, device, and explicitly overlapped HANDLE integrations. Sequential disk-file wrappers may prefer blocking offload unless they manage file offsets explicitly.
llam_write_handleGeneric platform handle I/O. On Windows, use this for HANDLEs.
ssize_t llam_write_handle(llam_handle_t handle,
const void *buf,
size_t count);Write to a generic platform handle.
On Windows this API submits overlapped WriteFile operations to the native IOCP backend when the handle supports overlapped I/O. If the backend cannot accept the handle, managed tasks fall back to the blocking-helper pool. On POSIX, llam_handle_t aliases llam_fd_t and this function delegates to llam_write.
llam_read_when_readyPoll and read in one runtime operation.
ssize_t llam_read_when_ready(llam_fd_t fd,
void *buf,
size_t count,
int timeout_ms);Wait for read readiness and read in one runtime operation.
Managed tasks first try an immediate nonblocking read. If the descriptor is not ready, LLAM waits for POLLIN and then retries the read directly, avoiding the duplicate safepoint/readiness checks of a separate llam_poll_fd + llam_read pair. Calls outside a managed LLAM task delegate to platform poll/read primitives and may block the calling OS thread.
fd- File descriptor to read from.
buf- Destination buffer.
count- Maximum bytes to read.
timeout_ms- Timeout in milliseconds; negative means infinite.
Returns Number of bytes read. -1 with errno set to ETIMEDOUT if the readiness wait expires, or another error from the poll/read path.
llam_writevScatter/gather write.
ssize_t llam_writev(llam_fd_t fd, const llam_iovec_t *iov, int iovcnt);Scatter/gather write using the runtime I/O path where possible.
Calls outside a managed LLAM task use the platform vector-write primitive where available. Managed POSIX tasks first try a nonblocking scatter/gather syscall and park cooperatively for writable readiness before falling back to per-slice llam_write. A partial return may occur after any slice boundary or partial slice write.
fd- File descriptor to write to.
iov- Array of buffers to write.
iovcnt- Number of buffers in
iov.
Returns Number of bytes written, or -1 with errno set.
llam_preadPositional I/O for POSIX-style descriptors.
ssize_t llam_pread(llam_fd_t fd, void *buf, size_t count, uint64_t offset);Positional read from a POSIX-style descriptor.
The file offset is not changed. On Windows, llam_fd_t is a SOCKET and positional file I/O is exposed through llam_pread_handle instead, so this function fails with ENOTSUP.
llam_pwritePositional I/O for POSIX-style descriptors.
ssize_t llam_pwrite(llam_fd_t fd,
const void *buf,
size_t count,
uint64_t offset);Positional write to a POSIX-style descriptor without changing file offset.
llam_preadvScatter/gather positional I/O for POSIX-style descriptors.
ssize_t llam_preadv(llam_fd_t fd,
const llam_mut_iovec_t *iov,
int iovcnt,
uint64_t offset);Scatter/gather positional read from a POSIX-style descriptor.
llam_pwritevScatter/gather positional I/O for POSIX-style descriptors.
ssize_t llam_pwritev(llam_fd_t fd,
const llam_iovec_t *iov,
int iovcnt,
uint64_t offset);Scatter/gather positional write to a POSIX-style descriptor.
llam_pread_handlePositional I/O for generic handles.
ssize_t llam_pread_handle(llam_handle_t handle,
void *buf,
size_t count,
uint64_t offset);Positional read from a generic platform handle.
Windows submits overlapped ReadFile with the supplied offset. Synchronous file handles use an independent reopened handle and must allow read sharing; managed tasks park while a blocking helper performs that I/O. The original file position is preserved, and end-of-file returns zero. On POSIX, llam_handle_t aliases llam_fd_t and this delegates to llam_pread.
llam_pwrite_handlePositional I/O for generic handles.
ssize_t llam_pwrite_handle(llam_handle_t handle,
const void *buf,
size_t count,
uint64_t offset);Positional write to a generic platform handle. The original file position is preserved. Synchronous Windows file handles must allow write sharing so an independent handle can perform the operation.
llam_preadv_handleScatter/gather positional I/O for generic handles.
ssize_t llam_preadv_handle(llam_handle_t handle,
const llam_mut_iovec_t *iov,
int iovcnt,
uint64_t offset);Scatter/gather positional read from a generic platform handle.
llam_pwritev_handleScatter/gather positional I/O for generic handles.
ssize_t llam_pwritev_handle(llam_handle_t handle,
const llam_iovec_t *iov,
int iovcnt,
uint64_t offset);Scatter/gather positional write to a generic platform handle.
llam_closeClose while invalidating runtime-local descriptor or handle state.
int llam_close(llam_fd_t fd);Close an fd/socket after invalidating LLAM-local descriptor state.
Prefer this for descriptors used with LLAM I/O; raw close remains legal but gives diagnostics less context around descriptor reuse.
Returns 0 on close, -1 with errno set. LLAM_INVALID_FD fails with EBADF.
llam_close_handleClose while invalidating runtime-local descriptor or handle state.
int llam_close_handle(llam_handle_t handle);Close a generic platform handle after invalidating LLAM-local handle state.
Windows calls CloseHandle. POSIX delegates to llam_close.
Deadlines and wait options
llam_wait_opts_t bounds one operation with an absolute deadline and an extra
cancellation token. The *_until forms take only the deadline, and 0 there means
already expired. New poll forms take an int mask in the short-mask range; the older
poll ABI is unchanged. Poll timeout returns 0; byte and connect timeout returns
-1/ETIMEDOUT. See the wait option fields
and Embed LLAM for
endpoint restrictions.
llam_wait_opts_initFill wait options with ABI-safe defaults.
int llam_wait_opts_init(llam_wait_opts_t *opts, size_t opts_size);Fill wait options with ABI-safe defaults: no deadline, token, or flags.
optsout- Options to initialize. Must not be NULL.
opts_size- Size of the caller's
llam_wait_opts_t; must be nonzero. LLAM writes only the prefix it knows.
Returns 0 on success, -1 with errno set to EINVAL.
llam_read_exStream I/O with a wait policy.
ssize_t llam_read_ex(llam_fd_t fd,
void *buf,
size_t count,
const llam_wait_opts_t *opts,
size_t opts_size);Read/write/connect/poll with one absolute deadline and extra token.
Managed operations use the earliest task/call deadline and observe task OR group OR call cancellation. Cancellation never releases a buffer while a backend/helper can still access it; a completed transfer can win the race. Every operation return (success, error, timeout or cancellation) ends access to its borrowed byte buffer. Requesting token cancellation or closing the descriptor from another task is not that completion boundary: retain the loan until the operation returns, or its owning task is fully drained. Bounded read/write/connect need a managed task. POSIX bounded byte I/O accepts sockets, nonblocking pipes/devices and regular files. Regular-file transfers use a private buffer (up to 64 KiB per call) and duplicate the descriptor. A running filesystem call can finish and affect the file or shared offset after a timeout/cancellation return. Block devices still report ENOTSUP. Windows HANDLE variants require native overlapped support when bounded. Poll supports host threads as well. Its timeout result is 0, like poll_fd. Existing read_when_ready and its relative millisecond timeout are unchanged.
fd- Descriptor or socket.
buf- Transfer buffer, in use until the call returns. May be NULL only when
countis 0. count- Maximum bytes to transfer.
opts- Optional wait policy; pass NULL for no additional limit.
opts_size- Size of
optswhen non-NULL; must then be nonzero.
Returns Bytes transferred for read and write, 0 for connect, and the ready count, or 0 on timeout, for poll. Failure returns -1 with errno set.
llam_write_exStream I/O with a wait policy.
ssize_t llam_write_ex(llam_fd_t fd,
const void *buf,
size_t count,
const llam_wait_opts_t *opts,
size_t opts_size);Read/write/connect/poll with one absolute deadline and extra token.
Managed operations use the earliest task/call deadline and observe task OR group OR call cancellation. Cancellation never releases a buffer while a backend/helper can still access it; a completed transfer can win the race. Every operation return (success, error, timeout or cancellation) ends access to its borrowed byte buffer. Requesting token cancellation or closing the descriptor from another task is not that completion boundary: retain the loan until the operation returns, or its owning task is fully drained. Bounded read/write/connect need a managed task. POSIX bounded byte I/O accepts sockets, nonblocking pipes/devices and regular files. Regular-file transfers use a private buffer (up to 64 KiB per call) and duplicate the descriptor. A running filesystem call can finish and affect the file or shared offset after a timeout/cancellation return. Block devices still report ENOTSUP. Windows HANDLE variants require native overlapped support when bounded. Poll supports host threads as well. Its timeout result is 0, like poll_fd. Existing read_when_ready and its relative millisecond timeout are unchanged.
fd- Descriptor or socket.
buf- Transfer buffer, in use until the call returns. May be NULL only when
countis 0. count- Maximum bytes to transfer.
opts- Optional wait policy; pass NULL for no additional limit.
opts_size- Size of
optswhen non-NULL; must then be nonzero.
Returns Bytes transferred for read and write, 0 for connect, and the ready count, or 0 on timeout, for poll. Failure returns -1 with errno set.
llam_read_handle_exHandle I/O with a wait policy.
ssize_t llam_read_handle_ex(llam_handle_t handle,
void *buf,
size_t count,
const llam_wait_opts_t *opts,
size_t opts_size);Read/write/connect/poll with one absolute deadline and extra token.
Managed operations use the earliest task/call deadline and observe task OR group OR call cancellation. Cancellation never releases a buffer while a backend/helper can still access it; a completed transfer can win the race. Every operation return (success, error, timeout or cancellation) ends access to its borrowed byte buffer. Requesting token cancellation or closing the descriptor from another task is not that completion boundary: retain the loan until the operation returns, or its owning task is fully drained. Bounded read/write/connect need a managed task. POSIX bounded byte I/O accepts sockets, nonblocking pipes/devices and regular files. Regular-file transfers use a private buffer (up to 64 KiB per call) and duplicate the descriptor. A running filesystem call can finish and affect the file or shared offset after a timeout/cancellation return. Block devices still report ENOTSUP. Windows HANDLE variants require native overlapped support when bounded. Poll supports host threads as well. Its timeout result is 0, like poll_fd. Existing read_when_ready and its relative millisecond timeout are unchanged.
handle- Platform handle.
buf- Transfer buffer, in use until the call returns. May be NULL only when
countis 0. count- Maximum bytes to transfer.
opts- Optional wait policy; pass NULL for no additional limit.
opts_size- Size of
optswhen non-NULL; must then be nonzero.
Returns Bytes transferred for read and write, 0 for connect, and the ready count, or 0 on timeout, for poll. Failure returns -1 with errno set.
llam_write_handle_exHandle I/O with a wait policy.
ssize_t llam_write_handle_ex(llam_handle_t handle,
const void *buf,
size_t count,
const llam_wait_opts_t *opts,
size_t opts_size);Read/write/connect/poll with one absolute deadline and extra token.
Managed operations use the earliest task/call deadline and observe task OR group OR call cancellation. Cancellation never releases a buffer while a backend/helper can still access it; a completed transfer can win the race. Every operation return (success, error, timeout or cancellation) ends access to its borrowed byte buffer. Requesting token cancellation or closing the descriptor from another task is not that completion boundary: retain the loan until the operation returns, or its owning task is fully drained. Bounded read/write/connect need a managed task. POSIX bounded byte I/O accepts sockets, nonblocking pipes/devices and regular files. Regular-file transfers use a private buffer (up to 64 KiB per call) and duplicate the descriptor. A running filesystem call can finish and affect the file or shared offset after a timeout/cancellation return. Block devices still report ENOTSUP. Windows HANDLE variants require native overlapped support when bounded. Poll supports host threads as well. Its timeout result is 0, like poll_fd. Existing read_when_ready and its relative millisecond timeout are unchanged.
handle- Platform handle.
buf- Transfer buffer, in use until the call returns. May be NULL only when
countis 0. count- Maximum bytes to transfer.
opts- Optional wait policy; pass NULL for no additional limit.
opts_size- Size of
optswhen non-NULL; must then be nonzero.
Returns Bytes transferred for read and write, 0 for connect, and the ready count, or 0 on timeout, for poll. Failure returns -1 with errno set.
llam_connect_exConnect with a wait policy.
int llam_connect_ex(llam_fd_t fd,
const struct sockaddr *addr,
socklen_t addrlen,
const llam_wait_opts_t *opts,
size_t opts_size);Read/write/connect/poll with one absolute deadline and extra token.
Managed operations use the earliest task/call deadline and observe task OR group OR call cancellation. Cancellation never releases a buffer while a backend/helper can still access it; a completed transfer can win the race. Every operation return (success, error, timeout or cancellation) ends access to its borrowed byte buffer. Requesting token cancellation or closing the descriptor from another task is not that completion boundary: retain the loan until the operation returns, or its owning task is fully drained. Bounded read/write/connect need a managed task. POSIX bounded byte I/O accepts sockets, nonblocking pipes/devices and regular files. Regular-file transfers use a private buffer (up to 64 KiB per call) and duplicate the descriptor. A running filesystem call can finish and affect the file or shared offset after a timeout/cancellation return. Block devices still report ENOTSUP. Windows HANDLE variants require native overlapped support when bounded. Poll supports host threads as well. Its timeout result is 0, like poll_fd. Existing read_when_ready and its relative millisecond timeout are unchanged.
fd- Descriptor or socket.
addr- Peer socket address. Must not be NULL.
addrlen- Size of
addrin bytes. opts- Optional wait policy; pass NULL for no additional limit.
opts_size- Size of
optswhen non-NULL; must then be nonzero.
Returns Bytes transferred for read and write, 0 for connect, and the ready count, or 0 on timeout, for poll. Failure returns -1 with errno set.
llam_poll_fd_exWait for readiness with a wait policy.
int llam_poll_fd_ex(llam_fd_t fd,
int events,
short *revents,
const llam_wait_opts_t *opts,
size_t opts_size);Read/write/connect/poll with one absolute deadline and extra token.
Managed operations use the earliest task/call deadline and observe task OR group OR call cancellation. Cancellation never releases a buffer while a backend/helper can still access it; a completed transfer can win the race. Every operation return (success, error, timeout or cancellation) ends access to its borrowed byte buffer. Requesting token cancellation or closing the descriptor from another task is not that completion boundary: retain the loan until the operation returns, or its owning task is fully drained. Bounded read/write/connect need a managed task. POSIX bounded byte I/O accepts sockets, nonblocking pipes/devices and regular files. Regular-file transfers use a private buffer (up to 64 KiB per call) and duplicate the descriptor. A running filesystem call can finish and affect the file or shared offset after a timeout/cancellation return. Block devices still report ENOTSUP. Windows HANDLE variants require native overlapped support when bounded. Poll supports host threads as well. Its timeout result is 0, like poll_fd. Existing read_when_ready and its relative millisecond timeout are unchanged.
fd- Descriptor or socket.
events- Poll events, in the range of a
short. reventsout- Optional returned events, set to 0 first.
opts- Optional wait policy; pass NULL for no additional limit.
opts_size- Size of
optswhen non-NULL; must then be nonzero.
Returns Bytes transferred for read and write, 0 for connect, and the ready count, or 0 on timeout, for poll. Failure returns -1 with errno set.
llam_read_untilStream I/O until an absolute deadline.
ssize_t llam_read_until(llam_fd_t fd,
void *buf,
size_t count,
uint64_t deadline_ns);Absolute-deadline forms; deadline 0 is already expired.
fd- Descriptor or socket.
buf- Transfer buffer, in use until the call returns. May be NULL only when
countis 0. count- Maximum bytes to transfer.
deadline_ns- Absolute
llam_now_nsdeadline.
Returns Bytes transferred for read and write, 0 for connect, and the ready count, or 0 on timeout, for poll. Failure returns -1 with errno set.
llam_write_untilStream I/O until an absolute deadline.
ssize_t llam_write_until(llam_fd_t fd,
const void *buf,
size_t count,
uint64_t deadline_ns);Absolute-deadline forms; deadline 0 is already expired.
fd- Descriptor or socket.
buf- Transfer buffer, in use until the call returns. May be NULL only when
countis 0. count- Maximum bytes to transfer.
deadline_ns- Absolute
llam_now_nsdeadline.
Returns Bytes transferred for read and write, 0 for connect, and the ready count, or 0 on timeout, for poll. Failure returns -1 with errno set.
llam_connect_untilConnect until an absolute deadline.
int llam_connect_until(llam_fd_t fd,
const struct sockaddr *addr,
socklen_t addrlen,
uint64_t deadline_ns);Absolute-deadline forms; deadline 0 is already expired.
fd- Descriptor or socket.
addr- Peer socket address. Must not be NULL.
addrlen- Size of
addrin bytes. deadline_ns- Absolute
llam_now_nsdeadline.
Returns Bytes transferred for read and write, 0 for connect, and the ready count, or 0 on timeout, for poll. Failure returns -1 with errno set.
llam_poll_fd_untilWait for readiness until an absolute deadline.
int llam_poll_fd_until(llam_fd_t fd,
int events,
uint64_t deadline_ns,
short *revents);Absolute-deadline forms; deadline 0 is already expired.
fd- Descriptor or socket.
events- Poll events, in the range of a
short. deadline_ns- Absolute
llam_now_nsdeadline. reventsout- Optional returned events, set to 0 first.
Returns Bytes transferred for read and write, 0 for connect, and the ready count, or 0 on timeout, for poll. Failure returns -1 with errno set.
Exact transfers
These calls loop until the whole count has moved and report confirmed progress
through a required size_t *, including on failure. Early EOF is EPIPE; a premature
zero-byte write is EIO.
llam_read_exactTransfer exactly the requested bytes.
int llam_read_exact(llam_fd_t fd,
void *buf,
size_t count,
size_t *progress);Transfer exactly count bytes, returning confirmed progress on failure.
EOF before a complete read is EPIPE, a zero-byte write is EIO. Completed chunks remain counted after timeout/cancel/error. These helpers cannot roll back bytes already transferred; do not resend the confirmed prefix.
fd- Descriptor or socket.
buf- Transfer buffer, in use until the call returns. May be NULL only when
countis 0. count- Bytes to transfer, at most
SIZE_MAX/ 2. progressout- Receives the confirmed byte count, starting at 0. Must not be NULL.
Returns 0 after count bytes, -1 with errno set otherwise.
llam_write_allTransfer exactly the requested bytes.
int llam_write_all(llam_fd_t fd,
const void *buf,
size_t count,
size_t *progress);Transfer exactly count bytes, returning confirmed progress on failure.
EOF before a complete read is EPIPE, a zero-byte write is EIO. Completed chunks remain counted after timeout/cancel/error. These helpers cannot roll back bytes already transferred; do not resend the confirmed prefix.
fd- Descriptor or socket.
buf- Transfer buffer, in use until the call returns. May be NULL only when
countis 0. count- Bytes to transfer, at most
SIZE_MAX/ 2. progressout- Receives the confirmed byte count, starting at 0. Must not be NULL.
Returns 0 after count bytes, -1 with errno set otherwise.
llam_read_exact_exTransfer exactly the requested bytes with a wait policy.
int llam_read_exact_ex(llam_fd_t fd,
void *buf,
size_t count,
const llam_wait_opts_t *opts,
size_t opts_size,
size_t *progress);Transfer exactly count bytes, returning confirmed progress on failure.
EOF before a complete read is EPIPE, a zero-byte write is EIO. Completed chunks remain counted after timeout/cancel/error. These helpers cannot roll back bytes already transferred; do not resend the confirmed prefix.
fd- Descriptor or socket.
buf- Transfer buffer, in use until the call returns. May be NULL only when
countis 0. count- Bytes to transfer, at most
SIZE_MAX/ 2. opts- Optional wait policy; pass NULL for no additional limit.
opts_size- Size of
optswhen non-NULL; must then be nonzero. progressout- Receives the confirmed byte count, starting at 0. Must not be NULL.
Returns 0 after count bytes, -1 with errno set otherwise.
llam_write_all_exTransfer exactly the requested bytes with a wait policy.
int llam_write_all_ex(llam_fd_t fd,
const void *buf,
size_t count,
const llam_wait_opts_t *opts,
size_t opts_size,
size_t *progress);Transfer exactly count bytes, returning confirmed progress on failure.
EOF before a complete read is EPIPE, a zero-byte write is EIO. Completed chunks remain counted after timeout/cancel/error. These helpers cannot roll back bytes already transferred; do not resend the confirmed prefix.
fd- Descriptor or socket.
buf- Transfer buffer, in use until the call returns. May be NULL only when
countis 0. count- Bytes to transfer, at most
SIZE_MAX/ 2. opts- Optional wait policy; pass NULL for no additional limit.
opts_size- Size of
optswhen non-NULL; must then be nonzero. progressout- Receives the confirmed byte count, starting at 0. Must not be NULL.
Returns 0 after count bytes, -1 with errno set otherwise.
Datagram, socket, and DNS
llam_recvfromDatagram I/O with peer addresses.
ssize_t llam_recvfrom(llam_fd_t fd,
void *buf,
size_t count,
int flags,
struct sockaddr *src_addr,
socklen_t *addrlen);Receive a datagram and optionally return the peer address.
Managed tasks first try a nonblocking recvfrom, then park on read readiness. Calls outside a managed task delegate to the platform recvfrom and may block. src_addr and addrlen must either both be NULL or both be non-NULL.
fd- Datagram socket.
buf- Destination buffer, in use until the call returns.
count- Maximum bytes to receive.
flagsrecvfromflags.src_addrout- Optional peer address.
addrlenin,out- Capacity of
src_addron entry, peer address size on return.
Returns Bytes received, or -1 with errno set.
llam_sendtoDatagram I/O with peer addresses.
ssize_t llam_sendto(llam_fd_t fd,
const void *buf,
size_t count,
int flags,
const struct sockaddr *dst_addr,
socklen_t addrlen);Send a datagram to dst_addr.
Managed tasks first try a nonblocking sendto, then park on write readiness. Calls outside a managed task delegate to the platform sendto and may block.
llam_recv_ownedSocket receive into a runtime-owned buffer, with recv flags such as MSG_PEEK. Works on stream and datagram sockets.
ssize_t llam_recv_owned(llam_fd_t fd,
size_t max_count,
int flags,
llam_io_buffer_t **out);Receive into a runtime-owned buffer with recv flags.
On success with a positive byte count, out receives a non-NULL buffer that must be released with llam_io_buffer_release. The returned buffer remains valid until release, even if the runtime is shut down first. On EOF or zero-byte receive, the function returns 0 and stores NULL in out. On failure, the function returns -1, stores NULL in out, and sets errno.
fd- Socket, stream or datagram.
max_count- Maximum bytes to receive.
flagsrecvflags, such asMSG_PEEK.outout- Receives the buffer or NULL. Must not be NULL.
llam_recvfrom_ownedDatagram receive into a runtime-owned buffer, also returning the peer address.
ssize_t llam_recvfrom_owned(llam_fd_t fd,
size_t max_count,
int flags,
struct sockaddr *src_addr,
socklen_t *addrlen,
llam_io_buffer_t **out);Receive a datagram into a runtime-owned buffer.
On success with a positive byte count, out receives a non-NULL owned buffer that must be released. A zero-length datagram returns 0 and stores NULL in out, matching the existing owned-buffer EOF/zero rule.
fd- Datagram socket.
max_count- Maximum bytes to receive.
flagsrecvfromflags.src_addrout- Optional peer address.
addrlenin,out- Capacity of
src_addron entry, peer address size on return. outout- Receives the buffer or NULL. Must not be NULL.
Returns Bytes received, or -1 with errno set.
llam_acceptAccept a socket connection with scheduler-safe waiting.
llam_fd_t llam_accept(llam_fd_t fd,
struct sockaddr *addr,
socklen_t *addrlen);Accept a connection from a listener fd using the runtime I/O backend where possible.
Managed tasks submit to the platform backend where possible and otherwise use a blocking helper so the scheduler worker is not pinned. Calls outside a managed LLAM task delegate to the platform accept primitive directly and may block the calling OS thread. addr and addrlen must either both be NULL or both be non-NULL; mismatched peer-address outputs fail with EINVAL before any connection is consumed.
fd- Listening socket.
addrout- Optional peer address.
addrlenin,out- Capacity of
addron entry, peer address size on return.
Returns Accepted descriptor on success, or LLAM_INVALID_FD on failure with errno set.
llam_connectConnect a socket with scheduler-safe waiting.
int llam_connect(llam_fd_t fd,
const struct sockaddr *addr,
socklen_t addrlen);Connect a socket without blocking the scheduler worker. Managed tasks submit the connection attempt to the runtime backend where possible and otherwise use the blocking-worker fallback. Calls outside a managed task delegate to connect directly.
fd- Socket descriptor.
addr- Peer socket address. Must not be NULL.
addrlen- Size of
addrin bytes.
Returns 0 on connection, -1 with errno set on failure.
llam_poll_fdWait for descriptor/socket readiness.
int llam_poll_fd(llam_fd_t fd,
short events,
int timeout_ms,
short *revents);Wait for fd readiness.
Calls from managed LLAM tasks park cooperatively. Calls outside a managed task delegate to the platform poll/select backend and may block the calling OS thread. timeout_ms < 0 waits indefinitely, timeout_ms == 0 performs a non-blocking readiness check, and positive values bound the wait in milliseconds.
fd- Descriptor or socket.
events- Poll events.
timeout_ms- Relative timeout in milliseconds, as described above.
reventsout- Optional returned events.
Returns Ready count, 0 on timeout, or -1 with errno set.
llam_poll_handleWait for generic handle readiness where supported.
int llam_poll_handle(llam_handle_t handle,
short events,
int timeout_ms,
short *revents);Wait for a generic platform handle.
Windows HANDLE waits use the blocking-helper pool in managed tasks; this is not socket readiness and does not replace llam_poll_fd. POSIX delegates to llam_poll_fd.
handle- Handle to wait on.
events- Poll events.
timeout_ms- Relative timeout in milliseconds, as for
llam_poll_fd. reventsout- Optional returned events.
Returns Ready count, 0 on timeout, or -1 with errno set.
llam_getaddrinfo_resultDNS through the runtime blocking path.
int llam_getaddrinfo_result(const char *node,
const char *service,
const struct addrinfo *hints,
struct addrinfo **out,
int *gai_error);Resolve addresses through the runtime blocking path.
LLAM submission/cancellation failures return -1 with errno set. Resolver failures return 0, store the getaddrinfo EAI_* status in gai_error, and store NULL in out. Successful results must be freed with llam_freeaddrinfo_result.
node- Host name or address; may be NULL when
serviceis set. service- Service name or port; may be NULL when
nodeis set. hints- Optional lookup hints.
outout- Receives the result list, set to NULL first. Must not be NULL.
gai_errorout- Receives the
EAI_*status, set to 0 first. Must not be NULL.
Returns 0 when the lookup ran, -1 with errno set otherwise.
llam_freeaddrinfo_resultRelease DNS results returned by llam_getaddrinfo_result.
void llam_freeaddrinfo_result(struct addrinfo *result);Free a result returned by llam_getaddrinfo_result.
Filesystem and processes
These operations park LLAM tasks while the blocking pool runs the native call.
llam_fsync_asyncFlush a file or directory.
int llam_fsync_async(llam_handle_t handle);Filesystem operations routed through the blocking pool in a task.
A started operation may take effect even when cancellation is reported. Windows uses its native file handles and directory permissions. Directory synchronization depends on filesystem support.
Returns 0 on success, or -1 with errno set.
llam_sync_dir_asyncFlush a file or directory.
int llam_sync_dir_async(const char *path);Filesystem operations routed through the blocking pool in a task.
A started operation may take effect even when cancellation is reported. Windows uses its native file handles and directory permissions. Directory synchronization depends on filesystem support.
Returns 0 on success, or -1 with errno set.
llam_rename_asyncRename or remove a file.
int llam_rename_async(const char *source, const char *destination);Filesystem operations routed through the blocking pool in a task.
A started operation may take effect even when cancellation is reported. Windows uses its native file handles and directory permissions. Directory synchronization depends on filesystem support.
Returns 0 on success, or -1 with errno set.
llam_unlink_asyncRename or remove a file.
int llam_unlink_async(const char *path);Filesystem operations routed through the blocking pool in a task.
A started operation may take effect even when cancellation is reported. Windows uses its native file handles and directory permissions. Directory synchronization depends on filesystem support.
Returns 0 on success, or -1 with errno set.
llam_mkdir_asyncCreate a directory.
int llam_mkdir_async(const char *path, uint32_t mode);Filesystem operations routed through the blocking pool in a task.
A started operation may take effect even when cancellation is reported. Windows uses its native file handles and directory permissions. Directory synchronization depends on filesystem support.
Returns 0 on success, or -1 with errno set.
llam_readdir_asyncReturn NUL-terminated entry names and the required buffer size.
int llam_readdir_async(const char *path,
char *names,
size_t capacity,
size_t *required);Write packed NUL-terminated directory names, omitting dot entries.
required must be non-NULL. On success or ERANGE it receives the total bytes needed, including terminators. On ERANGE a prefix of complete names may have been written. A zero-capacity query may pass NULL for names.
llam_ftruncate_asyncSet a file's length.
int llam_ftruncate_async(llam_handle_t handle, uint64_t length);Filesystem operations routed through the blocking pool in a task.
A started operation may take effect even when cancellation is reported. Windows uses its native file handles and directory permissions. Directory synchronization depends on filesystem support.
Returns 0 on success, or -1 with errno set.
llam_flock_asyncApply or release an advisory whole-file lock.
int llam_flock_async(llam_handle_t handle, uint32_t flags);Whole-file lock through the blocking pool, with platform locking semantics.
llam_process_status_asyncStart a child and wait for its terminal status.
int llam_process_status_async(const char *path,
char *const argv[],
llam_process_result_t *out,
size_t out_size);Run a child at the specified path and wait for its terminal status.
argv is NULL-terminated. A managed task parks while the blocking worker owns the child. In-flight cancellation waits for the child to be reaped. On Windows arguments use the C runtime's command-line quoting rules.
Returns 0 on a completed wait, or -1 with errno set.
llam_process_output_asyncStart a child and capture stdout and stderr into bounded caller buffers.
int llam_process_output_async(const char *path,
char *const argv[],
const llam_process_capture_t *capture,
size_t capture_size,
llam_process_result_t *out,
size_t out_size);Run a child and capture stdout and stderr concurrently into caller buffers.
Child output beyond either capacity is drained and marked truncated. Counts are bytes actually stored. NULL capture leaves the streams inherited.
LLAM_PROCESS_CAPTURE_CURRENT_SIZECurrent sizes for the capture and result structs used in the caller-size arguments.
#define LLAM_PROCESS_CAPTURE_CURRENT_SIZELLAM_PROCESS_RESULT_CURRENT_SIZECurrent sizes for the capture and result structs used in the caller-size arguments.
#define LLAM_PROCESS_RESULT_CURRENT_SIZEOwned I/O buffers
llam_io_buffer_opts_initFill owned-buffer options with ABI-safe defaults.
int llam_io_buffer_opts_init(llam_io_buffer_opts_t *opts, size_t opts_size);Initialize I/O buffer allocation options with ABI-safe defaults.
LLAM writes only the prefix known to the loaded library. Caller-side tail bytes from newer struct definitions are left untouched.
llam_io_buffer_alloc_exAllocate a runtime-owned buffer from explicit options.
int llam_io_buffer_alloc_ex(const llam_io_buffer_opts_t *opts,
size_t opts_size,
llam_io_buffer_t **out);Allocate a runtime-owned buffer with explicit capacity/alignment options.
opts- Optional buffer options.
opts_size- Size of
optswhen non-NULL; must then be nonzero. outout- Receives the buffer; set to NULL on failure. Must not be NULL.
Returns 0 on success, -1 with errno set.
llam_io_buffer_allocAllocate a buffer by capacity.
int llam_io_buffer_alloc(size_t capacity, llam_io_buffer_t **out);Allocate a runtime-owned buffer with default alignment.
capacity- Minimum usable capacity in bytes.
outout- Receives the buffer; set to NULL on failure. Must not be NULL.
Returns 0 on success, -1 with errno set.
llam_io_buffer_alloc_alignedAllocate a buffer with explicit alignment.
int llam_io_buffer_alloc_aligned(size_t capacity,
size_t alignment,
llam_io_buffer_t **out);Allocate a runtime-owned buffer with a power-of-two alignment.
capacity- Minimum usable capacity in bytes.
alignment- Required power-of-two alignment in bytes.
outout- Receives the buffer; set to NULL on failure. Must not be NULL.
Returns 0 on success, -1 with errno set.
llam_io_buffer_alignmentReturn buffer alignment.
size_t llam_io_buffer_alignment(const llam_io_buffer_t *buffer);Return the alignment requested when the owned buffer was allocated.
Invalid, stale, or consumed handles return 0 with errno set to EINVAL. Saturated or corrupt lifecycle accounting returns 0 with errno set to EBUSY.
llam_read_ownedRead into a runtime-owned buffer.
ssize_t llam_read_owned(llam_fd_t fd,
size_t max_count,
llam_io_buffer_t **out);On success with a positive byte count, out receives a non-NULL buffer that must be released with llam_io_buffer_release. The returned buffer remains valid until release, even if the runtime is shut down first. On EOF or zero-byte read, the function returns 0 and stores NULL in out. On failure, the function returns -1, stores NULL in out, and sets errno.
fd- Descriptor or socket.
max_count- Maximum bytes to read.
outout- Receives the buffer or NULL. Must not be NULL.
llam_pread_owned_alignedPositional read into an aligned owned buffer.
ssize_t llam_pread_owned_aligned(llam_fd_t fd,
size_t max_count,
uint64_t offset,
size_t alignment,
llam_io_buffer_t **out);Positional read into a newly allocated aligned owned buffer.
On success with a positive byte count, out receives a buffer that must be released with llam_io_buffer_release. EOF returns 0 and stores NULL. Failure returns -1, stores NULL in out, and sets errno.
fd- Descriptor to read.
max_count- Maximum bytes to read.
offset- File offset in bytes.
alignment- Required power-of-two alignment in bytes.
outout- Receives the buffer or NULL. Must not be NULL.
llam_pread_handle_owned_alignedHandle-based positional read into an aligned owned buffer.
ssize_t llam_pread_handle_owned_aligned(llam_handle_t handle,
size_t max_count,
uint64_t offset,
size_t alignment,
llam_io_buffer_t **out);HANDLE variant of llam_pread_owned_aligned.
handle- Handle to read.
max_count- Maximum bytes to read.
offset- File offset in bytes.
alignment- Required power-of-two alignment in bytes.
outout- Receives the buffer or NULL. Must not be NULL.
llam_io_buffer_dataReturn mutable buffer storage.
void *llam_io_buffer_data(llam_io_buffer_t *buffer);Return the data pointer for a runtime-owned I/O buffer.
The returned pointer is a borrowed view into buffer. It remains valid only while the buffer remains unreleased; LLAM protects the accessor itself from stale public handles, but it cannot make a raw C pointer safe after another thread releases the buffer. If lifecycle accounting is saturated or corrupt, this returns NULL with errno set to EBUSY. Invalid, stale, or consumed handles return NULL with errno set to EINVAL.
llam_io_buffer_sizeReturn the number of valid bytes.
size_t llam_io_buffer_size(const llam_io_buffer_t *buffer);Return the number of valid bytes in a runtime-owned I/O buffer.
Invalid, stale, or consumed handles return 0 with errno set to EINVAL. Saturated or corrupt lifecycle accounting returns 0 with errno set to EBUSY.
llam_io_buffer_capacityReturn usable capacity.
size_t llam_io_buffer_capacity(const llam_io_buffer_t *buffer);Return total capacity of a runtime-owned I/O buffer.
Invalid, stale, or consumed handles return 0 with errno set to EINVAL. Saturated or corrupt lifecycle accounting returns 0 with errno set to EBUSY.
llam_io_buffer_releaseRelease a runtime-owned buffer.
void llam_io_buffer_release(llam_io_buffer_t *buffer);Release a runtime-owned I/O buffer.
The buffer handle is consumed. Duplicate or stale releases are ignored, but any data pointer previously returned by llam_io_buffer_data is invalid once release begins. Callers that share a buffer between threads must serialize release against data-pointer use.
Filesystem wrappers
llam_open_asyncOpen a filesystem path through the blocking path.
int llam_open_async(const char *path,
int flags,
uint32_t mode,
llam_handle_t *out);Open a filesystem path through the runtime blocking path.
POSIX callers pass normal open flags and mode bits. Windows maps the common O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_EXCL, and O_TRUNC flags to CreateFileA. On success, out receives a llam_handle_t that must be closed with llam_close_handle.
path- Path to open. Must not be NULL.
flags- Open flags.
mode- Mode bits for a created file.
outout- Receives the handle, set to
LLAM_INVALID_HANDLEfirst. Must not be NULL.
Returns 0 on success, -1 with errno set.
llam_stat_path_exFill portable file metadata into llam_file_stat_t.
int llam_stat_path_ex(const char *path,
llam_file_stat_t *out,
size_t out_size);Stat a filesystem path through the runtime blocking path.
path- Path to query. Must not be NULL.
outout- Receives the metadata; its prefix is cleared first. Must not be NULL.
out_size- Size of the caller's
llam_file_stat_t; must be nonzero.
Returns 0 on success, -1 with errno set.
LLAM_FILE_TYPE_*Portable file type values used by llam_file_stat_t.Borrowed buffer completion
A byte-transfer operation returning to its caller is the boundary after which that request's backend, kernel and helper callback may no longer access its borrowed buffer. This applies to success, error, timeout and cancellation; a successful partial transfer still reports its confirmed byte count.
A cancellation request or close from another task is not an operation-completion
acknowledgement. Retain every active buffer loan until the corresponding call
returns, or until its owning child has passed a successful group drain. Do not
free/reuse buffers just because llam_cancel_token_cancel, llam_close or
llam_close_handle returned. On Windows, cancellation must still be followed by
terminal completion, as described in Microsoft's
I/O cancellation guidance.
On Linux, closing the application's descriptor does not automatically cancel an in-flight io_uring read or write: the request retains its own file reference. Request cancellation explicitly when shutdown must stop that operation, then wait for the original call to return before releasing its buffer. See liburing's cancellation contract.
test_borrowed_lifetime --io exercises pending reads and writes, cancellation and
close races, then immediately reuses each returned buffer while the backend
continues to make progress. Close cases also allow peer I/O to complete a retained
native request; they never treat close return as buffer-loan return.
The POSIX --io-helper variant disables byte-operation capabilities before
dispatch to exercise the actual blocking fallback. These tests accompany native platform verification; a test
on one backend is not evidence for a different OS.