commit cbd9c051abc4f7409d4e9c09553e79297a8b4992
parent 60d120011e00068be17527a4b3de1d4d71b98c86
Author: Drew DeVault <sir@cmpwn.com>
Date: Tue, 19 Oct 2021 17:19:59 +0200
iobus: add setuser/getuser
Signed-off-by: Drew DeVault <sir@cmpwn.com>
Diffstat:
2 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/iobus/io_uring/handle.ha b/iobus/io_uring/handle.ha
@@ -11,6 +11,16 @@ export fn callback(
append(op.callbacks, (cb, data));
};
+// Sets an arbitrary user data field for this handle.
+fn setuser(handle: *handle, user: *void) void = {
+ handle.user = user;
+};
+
+// Returns the value, if any, of the user data field set by [[setuser]].
+fn getuser(handle: *handle) nullable *void = {
+ return handle.user;
+};
+
// Returns the [[handle]] which this [[result]] corresponds to.
export fn handleof(res: result) *handle = {
match (io_uring::get_user(res)) {
diff --git a/iobus/io_uring/types.ha b/iobus/io_uring/types.ha
@@ -21,6 +21,7 @@ export type result = *io_uring::cqe;
export type handle = struct {
sqe: *io_uring::sqe,
+ user: nullable *void,
callbacks: [](*fn(res: result, data: *void) void, *void),
union {
accept: accept_handle,