Skip to content

Commit

Permalink
aio: add windows backend skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
Cloudef committed Jun 28, 2024
1 parent 0480792 commit c2a3f77
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 9 deletions.
5 changes: 3 additions & 2 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

const FallbackMode = enum { auto, force, disable };
var opts = b.addOptions();
const fallback = b.option(bool, "fallback", "use fallback event loop") orelse false;
opts.addOption(bool, "fallback", fallback);
const fallback = b.option(FallbackMode, "fallback", "fallback mode [auto, force, disable]") orelse .auto;
opts.addOption(FallbackMode, "fallback", fallback);

const minilib = b.addModule("minilib", .{
.root_source_file = b.path("src/minilib.zig"),
Expand Down
4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
echo "zig build test"
zig build test
if [[ "$(uname)" == "Linux" ]]; then
echo "zig build test -Dfallback=true"
zig build test -Dfallback=true
echo "zig build test -Dfallback=force"
zig build test -Dfallback=force
fi
'';

Expand Down
7 changes: 2 additions & 5 deletions src/aio.zig
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ pub const Options = struct {
/// This is unused if fallback is disabled, in that case you should check for a support manually.
required_ops: []const type = @import("aio/ops.zig").Operation.Types,
/// Choose a fallback mode.
fallback: enum {
auto,
force,
disable,
} = if (build_options.fallback) .force else .auto,
fallback: enum { auto, force, disable } = @enumFromInt(@intFromEnum(build_options.fallback)),
/// Max kludge threads for the fallback backend.
/// Kludge threads are used when operation cannot be polled for readiness.
/// One example is macos's /dev/tty which can only be queried for readiness using select/pselect.
Expand Down Expand Up @@ -185,6 +181,7 @@ pub const EventSource = struct {

const IO = switch (@import("builtin").target.os.tag) {
.linux => @import("aio/linux.zig").IO,
.windows => @import("aio/windows.zig").IO,
else => @import("aio/Fallback.zig"),
};

Expand Down
47 changes: 47 additions & 0 deletions src/aio/windows.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const std = @import("std");
const aio = @import("../aio.zig");
const Fallback = @import("Fallback.zig");
const windows = @import("posix/windows.zig");
const log = std.log.scoped(.aio_windows);

const Windows = @This();

pub const IO = switch (aio.options.fallback) {
.auto => Fallback, // Fallback until Windows backend is complete
.force => Fallback, // use only the fallback backend
.disable => Windows, // use only the Windows backend
};

pub const EventSource = windows.EventSource;

pub fn init(allocator: std.mem.Allocator, n: u16) aio.Error!@This() {
_ = allocator; // autofix
_ = n; // autofix
if (true) @panic("fixme");
return .{};
}

pub fn deinit(self: *@This(), allocator: std.mem.Allocator) void {
_ = allocator; // autofix
self.* = undefined;
}

pub fn queue(self: *@This(), comptime len: u16, work: anytype, cb: ?aio.Dynamic.QueueCallback) aio.Error!void {
_ = self; // autofix
_ = work; // autofix
_ = cb; // autofix
if (comptime len == 1) {} else {}
}

pub fn complete(self: *@This(), mode: aio.Dynamic.CompletionMode, cb: ?aio.Dynamic.CompletionCallback) aio.Error!aio.CompletionResult {
_ = self; // autofix
_ = mode; // autofix
_ = cb; // autofix
return .{};
}

pub fn immediate(comptime len: u16, work: anytype) aio.Error!u16 {
_ = len; // autofix
_ = work; // autofix
return 0;
}

0 comments on commit c2a3f77

Please sign in to comment.