pike
pike copied to clipboard
Allow sockets and other handles to be conditionally driven by an I/O notifier.
This is just an idea so far, though the idea is that for each exposed syscall (e.g. read()
), there would be two variants: Socket.read(buf: []u8) !usize
, and Socket.readAsync(buf: []u8) callconv(.Async) !usize
.
Another method would be exposed, which is Socket.wait(.{ .read = ?, .write = ? }) callconv(.Async) void
which allows users to manually await until a read/write-readiness notification is provided by an I/O notifier for a given file handle.
Calling Socket.read(...)
will return immediately if the syscall cannot immediately be completed, and thus may be driven by Socket.wait(.{ .read = true })
. Calling Socket.readAsync(...)
will automatically retry the syscall, which is done by awaiting for readiness notifications from an I/O notifier via Socket.wait(.{ .read = true })
.
Exposing these two variants also allows for Socket
's in pike to be used in blocking mode (e.g. read()
/ write()
may be called directly, blocking the current thread until said read()
/ write()
is completed).