package uring
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=73f7cd741940f0da81bd8a96db30e41908f11476324dcd88840d46bc543ddc80
sha512=3544c93f12117551a107501824829a1d1fb71340eba21beed34d7214f08718434b66be90de1a86a26ec0ad5ed1ac05cd5d7f8e86020e8e2795bf3524e0c02051
doc/uring/Uring/index.html
Module Uring
Source
Io_uring interface.
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 t
is a reference to an Io_uring structure.
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.
create ~queue_depth
will return a fresh Io_uring structure t
. Initially, t
has no fixed buffer. Use set_fixed_buffer
if you want one.
queue_depth t
returns the total number of submission slots for the uring t
Fixed buffers
Each uring may have 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.
set_fixed_buffer t buf
sets buf
as the fixed buffer for t
.
You will normally want to wrap this with Region.alloc
or similar to divide the buffer into chunks.
If t
already has a buffer set, the old one will be removed.
Returns `ENOMEM
if insufficient kernel resources are available or the caller's RLIMIT_MEMLOCK resource limit would be exceeded.
buf t
is the fixed internal memory buffer associated with uring t
using set_fixed_buffer
, or a zero-length buffer if none is set.
Queueing operations
Timeout
timeout t clock ns d
submits a timeout request to uring t
.
absolute
denotes how clock
and ns
relate to one another. Default value is false
ns
is the timeout time in nanoseconds
Flags that can be passed to openat2.
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
unlink t ~dir ~fd path
removes the directory entry path
, which is resolved relative to fd
. If fd
is not given, then the current working directory is used. If path
is a symlink, the link is removed, not the target.
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
.
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).
The maximum length of the list that can be passed to readv
and similar.
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.
connect t fd addr d
will submit a request to connect fd
to addr
.
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
.
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 send_msg :
?fds:Unix.file_descr list ->
?dst:Unix.sockaddr ->
'a t ->
Unix.file_descr ->
Cstruct.t list ->
'a ->
'a job option
send_msg t fd buffs d
will submit a sendmsg(2)
request. The Msghdr
will be constructed from the FDs (fds
), address (dst
) and buffers (buffs
).
Requires List.length buffs <= Uring.iov_max
recv_msg t fd msghdr d
will submit a recvmsg(2)
request. If the request is successful then the msghdr
will contain the sender address and the data received.
Probing
You can check which operations are supported by the running kernel.
Submitting operations
wait ?timeout t
will block indefinitely (the default) or for timeout
seconds for any outstanding events to complete on uring t
. This calls submit
automatically.
get_cqe_nonblocking t
returns the next completion entry from the uring t
. It is like wait
except that it returns None
instead of blocking.
error_of_errno e
converts the error code abs e
to a Unix error type.
active_ops t
returns the number of operations added to the ring (whether submitted or not) for which the completion event has not yet been collected.
get_debug_stats t
collects some metrics about the internal state of t
.