From 2eb15ec434f6f638b03edf6a7ab2070e02b997c4 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 21 Jun 2021 13:38:27 -0400 Subject: [PATCH] all: expand generic error handling This cause things like ETIME to be converted to errors::timeout rather than errors::opaque. Signed-off-by: Drew DeVault --- io_uring/cqe.ha | 13 +++---------- io_uring/queue.ha | 6 +++--- io_uring/uring.ha | 2 +- diff --git a/io_uring/cqe.ha b/io_uring/cqe.ha index 0f5b7d5df6fe93aaa0cb611f2e4d3c8f8e059eba..d12f77edcbbba49f1a8a63333e054119c7a49d34 100644 --- a/io_uring/cqe.ha +++ b/io_uring/cqe.ha @@ -28,16 +28,9 @@ // queue. export fn peek(ring: *io_uring) (nullable *cqe | error) = get_cqe(ring, 0, 0); // Returns the result of a [[cqe]], or an error if unsuccessful. -export fn result(cqe: *cqe) (int | error) = { - // TODO: Flesh out more errors - return if (cqe.res < 0) switch (-cqe.res) { - rt::ETIME => errors::timeout, - rt::ECANCELED => errors::cancelled, - * => errors::errno(rt::wrap_errno(-cqe.res)), - } else { - cqe.res; - }; -}; +export fn result(cqe: *cqe) (int | error) = + if (cqe.res < 0) errors::errno(rt::wrap_errno(-cqe.res)) + else cqe.res; // Gets the user data field of a [[cqe]]. See [[set_user]] for the corresponding // SQE function. diff --git a/io_uring/queue.ha b/io_uring/queue.ha index 0e80937a658bb1cb202aaeb845ab24c426b29d3f..50ccfc9256c09e2a6f127a4e7dc83becebd73f6b 100644 --- a/io_uring/queue.ha +++ b/io_uring/queue.ha @@ -41,7 +41,7 @@ *ring.sq.kflags & sqring_flags::CQ_OVERFLOW == sqring_flags::CQ_OVERFLOW; // Submits queued I/O asynchronously. Returns the number of submissions accepted // by the kernel. -export fn submit(ring: *io_uring) (uint | errors::opaque) = +export fn submit(ring: *io_uring) (uint | errors::error) = do_submit(ring, flush_sq(ring), 0u); // Submits queued I/O asynchronously and blocks until at least "wait" events are @@ -50,7 +50,7 @@ // the "wait" parameter is different: a non-zero value will block until at least // one event is completed. // // Returns the number of submissions accepted by the kernel. -export fn submit_wait(ring: *io_uring, wait: uint) (uint | errors::opaque) = +export fn submit_wait(ring: *io_uring, wait: uint) (uint | errors::error) = do_submit(ring, flush_sq(ring), wait); fn flush_sq(ring: *io_uring) uint = { @@ -76,7 +76,7 @@ fn do_submit( ring: *io_uring, submitted: uint, wait: uint, -) (uint | errors::opaque) = { +) (uint | errors::error) = { let flags: enter_flags = enter_flags::GETEVENTS; if (needs_enter(ring, &flags) || wait != 0) { return match (rt::io_uring_enter(ring.fd, diff --git a/io_uring/uring.ha b/io_uring/uring.ha index da2802cd0c14c7d5eb337b7538dd4c7e43068448..6f1c68c46b5e9de19c7e7c3c364ea3d20dcfaf78 100644 --- a/io_uring/uring.ha +++ b/io_uring/uring.ha @@ -1,7 +1,7 @@ use errors; // All errors which may be returned by this module. -export type error = !(errors::timeout | errors::cancelled | errors::opaque); +export type error = !errors::error; // Converts an [[error]] into a human-readable string. export fn strerror(err: error) const str = { -- 2.48.1