commit 021d33e70c674ce10d1d04c1f74a79ba21646ae0
parent 6f732edf9a2c8479a499fd7766c560613cefc91d
Author: Drew DeVault <sir@cmpwn.com>
Date: Tue, 19 Oct 2021 13:16:53 +0200
iobus: docs improvements
Signed-off-by: Drew DeVault <sir@cmpwn.com>
Diffstat:
2 files changed, 15 insertions(+), 14 deletions(-)
diff --git a/iobus/io_uring/bus.ha b/iobus/io_uring/bus.ha
@@ -45,6 +45,18 @@ export fn submit(bus: *bus, ops: *handle...) (void | error) = {
return;
};
+// Waits until at least one I/O event completes, then returns the result. The
+// caller must call [[done]] with the result when done with it.
+export fn dispatch(bus: *bus) (result | error) = {
+ const res = _dispatch(bus)?;
+ const handle = handleof(res);
+ for (let i = 0z; i < len(handle.callbacks); i += 1) {
+ const cb = handle.callbacks[i];
+ cb.0(res, cb.1);
+ };
+ return res;
+};
+
fn _dispatch(bus: *bus) (result | error) = {
match (io_uring::peek(&bus.uring)?) {
case null => void;
@@ -63,18 +75,6 @@ fn _dispatch(bus: *bus) (result | error) = {
};
};
-// Waits until at least one I/O event completes, then returns the result. The
-// caller must call [[done]] with the result when done with it.
-export fn dispatch(bus: *bus) (result | error) = {
- const res = _dispatch(bus)?;
- const handle = handleof(res);
- for (let i = 0z; i < len(handle.callbacks); i += 1) {
- const cb = handle.callbacks[i];
- cb.0(res, cb.1);
- };
- return res;
-};
-
// Registers a file with the iobus, returning a [[registered_file]] object to
// use for I/O operations. It is not necessary to register files to use them for
// I/O, but it improves performance if you do.
diff --git a/iobus/io_uring/types.ha b/iobus/io_uring/types.ha
@@ -5,8 +5,10 @@ use net::ip;
use net::unix;
use rt;
+// All errors which may be raised by iobus.
export type error = io_uring::error;
+// Converts an [[error]] into a user-friendly string.
export fn strerror(err: error) const str = {
return io_uring::strerror(err);
};
@@ -17,10 +19,8 @@ export type bus = struct {
lastfd: size,
};
-// The result of a completed I/O operation.
export type result = *io_uring::cqe;
-// An I/O operation handle.
export type handle = struct {
sqe: *io_uring::sqe,
callbacks: [](*fn(res: result, data: *void) void, *void),
@@ -36,6 +36,7 @@ export type accept_handle = struct {
export type registered_file = int;
+// A file object which accepts multiplexed I/O operations.
export type file = (registered_file | io::file);
// Returned if the submission queue is full and new I/O submissions are not