From 89f76f6c30101246a751897f50723814a4de029c Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 19 May 2021 12:58:31 -0400 Subject: [PATCH] linux::io_uring: send/recv/sendmsg/recvmsg Signed-off-by: Drew DeVault --- io_uring/sqe.ha | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++ io_uring/uring.ha | 2 +- diff --git a/io_uring/sqe.ha b/io_uring/sqe.ha index 07ff93b559521609b0b9a8101dc5be073dadd8a2..df469cbf0b91bcbed820197f93242580b1b5f236 100644 --- a/io_uring/sqe.ha +++ b/io_uring/sqe.ha @@ -153,3 +153,59 @@ export fn poll_remove(sqe: *sqe, user_data: *void, flags: sqe_flags...) void = { preprw(sqe, op::POLL_REMOVE, -1, null, 0, 0, flags...); set_user(sqe, user_data); }; + +// Prepares a sendmsg operation for an [[sqe]], equivalent to the sendmsg(2) +// system call. +export fn sendmsg( + sqe: *sqe, + fd: int, + msghdr: *rt::msghdr, + sendmsg_flags: int, + flags: sqe_flags... +) void = { + preprw(sqe, op::SENDMSG, fd, msghdr, 0, 0, flags...); + sqe.msg_flags = sendmsg_flags; +}; + +// Prepares a recvmsg operation for an [[sqe]], equivalent to the sendmsg(2) +// system call. +export fn recvmsg( + sqe: *sqe, + fd: int, + msghdr: *rt::msghdr, + recvmsg_flags: int, + flags: sqe_flags... +) void = { + preprw(sqe, op::RECVMSG, fd, msghdr, 0, 0, flags...); + sqe.msg_flags = recvmsg_flags; +}; + +// Prepares a send operation for an [[sqe]], equivalent to the send(2) system +// call. +export fn send( + sqe: *sqe, + fd: int, + buf: *void, + count: size, + send_flags: int, + flags: sqe_flags... +) void = { + assert(count <= types::U32_MAX); + preprw(sqe, op::SEND, fd, buf, count: u32, 0, flags...); + sqe.msg_flags = send_flags; +}; + +// Prepares a recv operation for an [[sqe]], equivalent to the send(2) system +// call. +export fn recv( + sqe: *sqe, + fd: int, + buf: *void, + count: size, + recv_flags: int, + flags: sqe_flags... +) void = { + assert(count <= types::U32_MAX); + preprw(sqe, op::RECV, fd, buf, count: u32, 0, flags...); + sqe.msg_flags = recv_flags; +}; diff --git a/io_uring/uring.ha b/io_uring/uring.ha index 343734cd050d802326a50f20fd6bf805dc1e06b1..e6e7441f3cbd4dea81ac27fe91f7c825fe954df8 100644 --- a/io_uring/uring.ha +++ b/io_uring/uring.ha @@ -111,7 +111,7 @@ fsync_flags: fsync_flags, poll_events: u16, poll32_events: u32, sync_range_flags: u32, - msg_flags: u32, + msg_flags: int, timeout_flags: timeout_flags, accept_flags: u32, cancel_flags: u32, -- 2.48.1