Library
Module
Module type
Parameter
Class
Class type
Io_uring interface.
module Region : sig ... end
Region
handles carving up a block of external memory into smaller chunks. This is currently just a slab allocator of a fixed size, on the basis that most IO operations operate on predictable chunks of memory. Since the block of memory in a region is contiguous, it can be used in Uring's fixed buffer model to map it into kernel space for more efficient IO.
A handle for a submitted job, which can be used to cancel it. If an operation returns None
, this means that submission failed because the ring is full.
val create : ?fixed_buf_len:int -> queue_depth:int -> unit -> 'a t
create ?fixed_buf_len ~queue_depth
will return a fresh Io_uring structure t
. Each t
has associated with it a fixed region of memory that is used for the "fixed buffer" mode of io_uring to avoid data copying between userspace and the kernel.
val queue_depth : 'a t -> int
queue_depth t
returns the total number of submission slots for the uring t
val buf : 'a t -> Cstruct.buffer
buf t
is the fixed internal memory buffer associated with uring t
. You will normally want to wrap this with Region.alloc
or similar to divide the buffer into chunks.
val realloc : 'a t -> Cstruct.buffer -> unit
realloc t buf
will replace the internal fixed buffer associated with uring t
with a fresh one.
val exit : 'a t -> unit
exit t
will shut down the uring t
. Any subsequent requests will fail.
module type FLAGS = sig ... end
module Open_flags : sig ... end
Flags that can be passed to openat2.
module Resolve : sig ... end
Flags that can be passed to openat2 to control path resolution.
val openat2 :
'a t ->
access:[ `R | `W | `RW ] ->
flags:Open_flags.t ->
perm:Unix.file_perm ->
resolve:Resolve.t ->
?fd:Unix.file_descr ->
string ->
'a ->
'a job option
module Poll_mask : sig ... end
val poll_add : 'a t -> Unix.file_descr -> Poll_mask.t -> 'a -> 'a job option
poll_add t fd mask d
will submit a poll(2)
request to uring t
. It completes and returns d
when an event in mask
is ready on fd
.
type offset := Optint.Int63.t
For files, give the absolute offset, or use Optint.Int63.minus_one
for the current position. For sockets, use an offset of Optint.Int63.zero
(minus_one
is not allowed here).
val readv :
'a t ->
file_offset:offset ->
Unix.file_descr ->
Cstruct.t list ->
'a ->
'a job option
val writev :
'a t ->
file_offset:offset ->
Unix.file_descr ->
Cstruct.t list ->
'a ->
'a job option
val read_fixed :
'a t ->
file_offset:offset ->
Unix.file_descr ->
off:int ->
len:int ->
'a ->
'a job option
read t ~file_offset fd ~off ~len d
will submit a read(2)
request to uring t
. It reads up to len
bytes from absolute file_offset
on the fd
file descriptor and writes the results into the fixed memory buffer associated with uring t
at offset off
. The user data d
will be returned by wait
or peek
upon completion.
val read_chunk :
?len:int ->
'a t ->
file_offset:offset ->
Unix.file_descr ->
Region.chunk ->
'a ->
'a job option
read_chunk
is like read_fixed
, but gets the offset from chunk
.
val write_fixed :
'a t ->
file_offset:offset ->
Unix.file_descr ->
off:int ->
len:int ->
'a ->
'a job option
val write_chunk :
?len:int ->
'a t ->
file_offset:offset ->
Unix.file_descr ->
Region.chunk ->
'a ->
'a job option
write_chunk
is like write_fixed
, but gets the offset from chunk
.
val splice :
'a t ->
src:Unix.file_descr ->
dst:Unix.file_descr ->
len:int ->
'a ->
'a job option
splice t ~src ~dst ~len d
will submit a request to copy len
bytes from src
to dst
. The operation returns the number of bytes transferred, or 0 for end-of-input. The result is EINVAL
if the file descriptors don't support splicing.
val connect : 'a t -> Unix.file_descr -> Unix.sockaddr -> 'a -> 'a job option
connect t fd addr d
will submit a request to connect fd
to addr
.
val accept : 'a t -> Unix.file_descr -> Sockaddr.t -> 'a -> 'a job option
accept t fd addr d
will submit a request to accept a new connection on fd
. The new FD will be configured with SOCK_CLOEXEC
. The remote address will be stored in addr
.
val close : 'a t -> Unix.file_descr -> 'a -> 'a job option
cancel t job d
submits a request to cancel job
. The cancel job itself returns 0 on success, or ENOTFOUND
if job
had already completed by the time the kernel processed the cancellation request.
val submit : 'a t -> int
val wait : ?timeout:float -> 'a t -> 'a completion_option
wait ?timeout t
will block indefinitely (the default) or for timeout
seconds for any outstanding events to complete on uring t
. Events should have been queued via submit
previously to this call.
val peek : 'a t -> 'a completion_option
peek t
looks for completed requests on the uring t
without blocking.
val error_of_errno : int -> Unix.error
error_of_errno e
converts the error code abs e
to a Unix error type.
module Private : sig ... end