IoVecBuf
struct IoVecBufA heap-allocated struct iovec[n] array.
Owns the underlying buffer; frees on drop. Callers populate
cells via set(i, ptr, len); the buffer's base pointer is
exposed via base() for the writev(2) call.
Fields:
_buf: The owning heap pointer to the raw byte buffer
that backs the iovec array.
_n: Number of iovec cells the buffer holds. Bounded
on construction; cells are NOT bounds-checked at
set time for performance.
Example:
var iov = IoVecBuf(3)
iov.set(0, status_line_ptr, status_line_len)
iov.set(1, headers_ptr, headers_len)
iov.set(2, body_ptr, body_len)
var n = writev_buf(fd, iov.base(), 3)
Implements Movable
__init__
def __init__(out self, n: Int) Construct a buffer holding n iovec cells.
- Args
n: Number of cells. Must be > 0.
__deinit__
def __deinit__(deinit self) Free the underlying buffer.
size_for
def size_for(n: Int) -> Int Return the byte size of an iovec array of n cells.
Useful for stack_allocation callers that want to
avoid a heap allocation entirely::
var raw = stack_allocation[IoVecBuf.size_for(3), UInt8]()
base
def base(self) -> Pointer[UInt8, MutUntrackedOrigin] Return the buffer's base pointer (suitable as the iov arg to writev_buf).
count
def count(self) -> Int Return the number of cells in the buffer.
set
def set(mut self, i: Int, ptr: Int, n: Int) Write the i'th iovec cell.
- Args
i: Cell index. Bounds-checked under-D ASSERT=safe(the default). The check usesdebug_assertrather thanstd.collections.check_boundsbecausecheck_boundsrequires the call site to be@always_inline(it relies oncall_location[inline_count=2]()); the per-call cost of inliningsethere would bloat every keep-alive serialiser site without a measurable win. See.agent/rules/sanitizers-and-bounds-checking.mdc§3 / §4 for the rationale.ptr:iov_basevalue (typicallyInt(some_buffer.unsafe_ptr())).n:iov_lenvalue (number of bytes atptr).
cell_ptr
def cell_ptr(self, i: Int) -> Int Read back the i'th cell's iov_base.
Useful for tests + the writev_buf_all partial-write
loop that needs to advance the ptr after a short write.
Bounds-checked under -D ASSERT=safe.
cell_len
def cell_len(self, i: Int) -> Int Read back the i'th cell's iov_len.
Bounds-checked under -D ASSERT=safe.