hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 80f0833a99201590dca745a6d67fc64b02f5c70f
parent 990d02e8a91be9c559ded38e813f418133268720
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sat, 15 May 2021 21:40:59 -0400

linux::io_uring: add readv/writev

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Mlinux/io_uring/sqe.ha | 54++++++++++++++++++++++++++++++++++++++++++++++--------
Mlinux/io_uring/uring.ha | 4++--
2 files changed, 48 insertions(+), 10 deletions(-)

diff --git a/linux/io_uring/sqe.ha b/linux/io_uring/sqe.ha @@ -1,3 +1,6 @@ +// TODO: +// - Interface for buffer registration +use rt; use types; fn prep(sq: *sqe, op: op, flags: sqe_flags...) void = { @@ -8,6 +11,47 @@ fn prep(sq: *sqe, op: op, flags: sqe_flags...) void = { }; }; +fn preprw( + sqe: *sqe, + op: op, + fd: int, + addr: nullable *void, + length: uint, + offs: u64, + flags: sqe_flags... +) void = { + prep(sqe, op, flags...); + sqe.fd = fd; + sqe.addr = addr; + sqe.length = length; + sqe.off = offs; +}; + +// Prepares a no-op "operation" for an [[sqe]]. +export fn nop(sqe: *sqe, flags: sqe_flags...) void = { + prep(sqe, op::NOP, flags...); +}; + +// Prepares a vectored read operation for an [[sqe]]. +export fn readv( + sqe: *sqe, + fd: int, + iov: []rt::iovec, + offs: size, +) void = { + preprw(sqe, op::READV, fd, iov: *[*]rt::iovec, len(iov): uint, offs); +}; + +// Prepares a vectored write operation for an [[sqe]]. +export fn writev( + sqe: *sqe, + fd: int, + iov: []rt::iovec, + offs: size, +) void = { + preprw(sqe, op::WRITEV, fd, iov: *[*]rt::iovec, len(iov): uint, offs); +}; + // Prepares a read operation for an [[sqe]]. export fn read( sqe: *sqe, @@ -16,11 +60,8 @@ export fn read( count: size, flags: sqe_flags..., ) void = { - prep(sqe, op::READ, flags...); - sqe.fd = fd; - sqe.addr = buf: uintptr: u64; assert(count <= types::U32_MAX); - sqe.length = count: u32; + preprw(sqe, op::READ, fd, buf, count: u32, 0, flags...); }; // Prepares a write operation for an [[sqe]]. @@ -31,9 +72,6 @@ export fn write( count: size, flags: sqe_flags..., ) void = { - prep(sqe, op::WRITE, flags...); - sqe.fd = fd; - sqe.addr = buf: uintptr: u64; assert(count <= types::U32_MAX); - sqe.length = count: u32; + preprw(sqe, op::WRITE, fd, buf, count: u32, 0, flags...); }; diff --git a/linux/io_uring/uring.ha b/linux/io_uring/uring.ha @@ -95,10 +95,10 @@ export type sqe = struct { fd: i32, union { off: u64, - addr2: u64, + addr2: nullable *void, }, union { - addr: u64, + addr: nullable *void, splice_off_in: u64, }, length: u32,