aboutsummaryrefslogtreecommitdiff
path: root/std/event
diff options
context:
space:
mode:
Diffstat (limited to 'std/event')
-rw-r--r--std/event/fs.zig31
-rw-r--r--std/event/loop.zig27
2 files changed, 35 insertions, 23 deletions
diff --git a/std/event/fs.zig b/std/event/fs.zig
index 2ce3014178..1b8e1aa5dc 100644
--- a/std/event/fs.zig
+++ b/std/event/fs.zig
@@ -83,6 +83,7 @@ pub async fn pwritev(loop: *Loop, fd: os.FileHandle, data: []const []const u8, o
switch (builtin.os) {
builtin.Os.macosx,
builtin.Os.linux,
+ builtin.Os.freebsd,
=> {
const iovecs = try loop.allocator.alloc(os.posix.iovec_const, data.len);
defer loop.allocator.free(iovecs);
@@ -219,6 +220,7 @@ pub async fn preadv(loop: *Loop, fd: os.FileHandle, data: []const []u8, offset:
switch (builtin.os) {
builtin.Os.macosx,
builtin.Os.linux,
+ builtin.Os.freebsd,
=> {
const iovecs = try loop.allocator.alloc(os.posix.iovec, data.len);
defer loop.allocator.free(iovecs);
@@ -399,7 +401,7 @@ pub async fn openPosix(
pub async fn openRead(loop: *Loop, path: []const u8) os.File.OpenError!os.FileHandle {
switch (builtin.os) {
- builtin.Os.macosx, builtin.Os.linux => {
+ builtin.Os.macosx, builtin.Os.linux, builtin.Os.freebsd => {
const flags = posix.O_LARGEFILE | posix.O_RDONLY | posix.O_CLOEXEC;
return await (async openPosix(loop, path, flags, os.File.default_mode) catch unreachable);
},
@@ -427,6 +429,7 @@ pub async fn openWriteMode(loop: *Loop, path: []const u8, mode: os.File.Mode) os
switch (builtin.os) {
builtin.Os.macosx,
builtin.Os.linux,
+ builtin.Os.freebsd,
=> {
const flags = posix.O_LARGEFILE | posix.O_WRONLY | posix.O_CREAT | posix.O_CLOEXEC | posix.O_TRUNC;
return await (async openPosix(loop, path, flags, os.File.default_mode) catch unreachable);
@@ -449,7 +452,7 @@ pub async fn openReadWrite(
mode: os.File.Mode,
) os.File.OpenError!os.FileHandle {
switch (builtin.os) {
- builtin.Os.macosx, builtin.Os.linux => {
+ builtin.Os.macosx, builtin.Os.linux, builtin.Os.freebsd => {
const flags = posix.O_LARGEFILE | posix.O_RDWR | posix.O_CREAT | posix.O_CLOEXEC;
return await (async openPosix(loop, path, flags, mode) catch unreachable);
},
@@ -477,7 +480,7 @@ pub const CloseOperation = struct {
os_data: OsData,
const OsData = switch (builtin.os) {
- builtin.Os.linux, builtin.Os.macosx => OsDataPosix,
+ builtin.Os.linux, builtin.Os.macosx, builtin.Os.freebsd => OsDataPosix,
builtin.Os.windows => struct {
handle: ?os.FileHandle,
@@ -496,7 +499,7 @@ pub const CloseOperation = struct {
self.* = CloseOperation{
.loop = loop,
.os_data = switch (builtin.os) {
- builtin.Os.linux, builtin.Os.macosx => initOsDataPosix(self),
+ builtin.Os.linux, builtin.Os.macosx, builtin.Os.freebsd => initOsDataPosix(self),
builtin.Os.windows => OsData{ .handle = null },
else => @compileError("Unsupported OS"),
},
@@ -525,6 +528,7 @@ pub const CloseOperation = struct {
switch (builtin.os) {
builtin.Os.linux,
builtin.Os.macosx,
+ builtin.Os.freebsd,
=> {
if (self.os_data.have_fd) {
self.loop.posixFsRequest(&self.os_data.close_req_node);
@@ -546,6 +550,7 @@ pub const CloseOperation = struct {
switch (builtin.os) {
builtin.Os.linux,
builtin.Os.macosx,
+ builtin.Os.freebsd,
=> {
self.os_data.close_req_node.data.msg.Close.fd = handle;
self.os_data.have_fd = true;
@@ -562,6 +567,7 @@ pub const CloseOperation = struct {
switch (builtin.os) {
builtin.Os.linux,
builtin.Os.macosx,
+ builtin.Os.freebsd,
=> {
self.os_data.have_fd = false;
},
@@ -576,6 +582,7 @@ pub const CloseOperation = struct {
switch (builtin.os) {
builtin.Os.linux,
builtin.Os.macosx,
+ builtin.Os.freebsd,
=> {
assert(self.os_data.have_fd);
return self.os_data.close_req_node.data.msg.Close.fd;
@@ -599,6 +606,7 @@ pub async fn writeFileMode(loop: *Loop, path: []const u8, contents: []const u8,
switch (builtin.os) {
builtin.Os.linux,
builtin.Os.macosx,
+ builtin.Os.freebsd,
=> return await (async writeFileModeThread(loop, path, contents, mode) catch unreachable),
builtin.Os.windows => return await (async writeFileWindows(loop, path, contents) catch unreachable),
else => @compileError("Unsupported OS"),
@@ -704,7 +712,7 @@ pub fn Watch(comptime V: type) type {
os_data: OsData,
const OsData = switch (builtin.os) {
- builtin.Os.macosx => struct {
+ builtin.Os.macosx, builtin.Os.freebsd => struct {
file_table: FileTable,
table_lock: event.Lock,
@@ -793,7 +801,7 @@ pub fn Watch(comptime V: type) type {
return self;
},
- builtin.Os.macosx => {
+ builtin.Os.macosx, builtin.Os.freebsd => {
const self = try loop.allocator.createOne(Self);
errdefer loop.allocator.destroy(self);
@@ -813,7 +821,7 @@ pub fn Watch(comptime V: type) type {
/// All addFile calls and removeFile calls must have completed.
pub fn destroy(self: *Self) void {
switch (builtin.os) {
- builtin.Os.macosx => {
+ builtin.Os.macosx, builtin.Os.freebsd => {
// TODO we need to cancel the coroutines before destroying the lock
self.os_data.table_lock.deinit();
var it = self.os_data.file_table.iterator();
@@ -855,14 +863,14 @@ pub fn Watch(comptime V: type) type {
pub async fn addFile(self: *Self, file_path: []const u8, value: V) !?V {
switch (builtin.os) {
- builtin.Os.macosx => return await (async addFileMacosx(self, file_path, value) catch unreachable),
+ builtin.Os.macosx, builtin.Os.freebsd => return await (async addFileKEvent(self, file_path, value) catch unreachable),
builtin.Os.linux => return await (async addFileLinux(self, file_path, value) catch unreachable),
builtin.Os.windows => return await (async addFileWindows(self, file_path, value) catch unreachable),
else => @compileError("Unsupported OS"),
}
}
- async fn addFileMacosx(self: *Self, file_path: []const u8, value: V) !?V {
+ async fn addFileKEvent(self: *Self, file_path: []const u8, value: V) !?V {
const resolved_path = try os.path.resolve(self.channel.loop.allocator, file_path);
var resolved_path_consumed = false;
defer if (!resolved_path_consumed) self.channel.loop.allocator.free(resolved_path);
@@ -871,7 +879,10 @@ pub fn Watch(comptime V: type) type {
var close_op_consumed = false;
defer if (!close_op_consumed) close_op.finish();
- const flags = posix.O_SYMLINK | posix.O_EVTONLY;
+ const flags = switch (builtin.os) {
+ builtin.Os.macosx => posix.O_SYMLINK | posix.O_EVTONLY,
+ else => 0,
+ };
const mode = 0;
const fd = try await (async openPosix(self.channel.loop, resolved_path, flags, mode) catch unreachable);
close_op.setHandle(fd);
diff --git a/std/event/loop.zig b/std/event/loop.zig
index fb47a9f253..43965e8293 100644
--- a/std/event/loop.zig
+++ b/std/event/loop.zig
@@ -49,7 +49,7 @@ pub const Loop = struct {
};
pub const EventFd = switch (builtin.os) {
- builtin.Os.macosx => MacOsEventFd,
+ builtin.Os.macosx, builtin.Os.freebsd => KEventFd,
builtin.Os.linux => struct {
base: ResumeNode,
epoll_op: u32,
@@ -62,13 +62,13 @@ pub const Loop = struct {
else => @compileError("unsupported OS"),
};
- const MacOsEventFd = struct {
+ const KEventFd = struct {
base: ResumeNode,
kevent: posix.Kevent,
};
pub const Basic = switch (builtin.os) {
- builtin.Os.macosx => MacOsBasic,
+ builtin.Os.macosx, builtin.Os.freebsd => KEventBasic,
builtin.Os.linux => struct {
base: ResumeNode,
},
@@ -78,7 +78,7 @@ pub const Loop = struct {
else => @compileError("unsupported OS"),
};
- const MacOsBasic = struct {
+ const KEventBasic = struct {
base: ResumeNode,
kev: posix.Kevent,
};
@@ -214,7 +214,7 @@ pub const Loop = struct {
self.extra_threads[extra_thread_index] = try os.spawnThread(self, workerRun);
}
},
- builtin.Os.macosx => {
+ builtin.Os.macosx, builtin.Os.freebsd => {
self.os_data.kqfd = try os.bsdKQueue();
errdefer os.close(self.os_data.kqfd);
@@ -369,7 +369,7 @@ pub const Loop = struct {
os.close(self.os_data.epollfd);
self.allocator.free(self.eventfd_resume_nodes);
},
- builtin.Os.macosx => {
+ builtin.Os.macosx, builtin.Os.freebsd => {
os.close(self.os_data.kqfd);
os.close(self.os_data.fs_kqfd);
},
@@ -484,7 +484,7 @@ pub const Loop = struct {
const eventfd_node = &resume_stack_node.data;
eventfd_node.base.handle = next_tick_node.data;
switch (builtin.os) {
- builtin.Os.macosx => {
+ builtin.Os.macosx, builtin.Os.freebsd => {
const kevent_array = (*[1]posix.Kevent)(&eventfd_node.kevent);
const empty_kevs = ([*]posix.Kevent)(undefined)[0..0];
_ = os.bsdKEvent(self.os_data.kqfd, kevent_array, empty_kevs, null) catch {
@@ -546,6 +546,7 @@ pub const Loop = struct {
switch (builtin.os) {
builtin.Os.linux,
builtin.Os.macosx,
+ builtin.Os.freebsd,
=> self.os_data.fs_thread.wait(),
else => {},
}
@@ -610,7 +611,7 @@ pub const Loop = struct {
os.posixWrite(self.os_data.final_eventfd, wakeup_bytes) catch unreachable;
return;
},
- builtin.Os.macosx => {
+ builtin.Os.macosx, builtin.Os.freebsd => {
self.posixFsRequest(&self.os_data.fs_end_request);
const final_kevent = (*[1]posix.Kevent)(&self.os_data.final_kevent);
const empty_kevs = ([*]posix.Kevent)(undefined)[0..0];
@@ -668,7 +669,7 @@ pub const Loop = struct {
}
}
},
- builtin.Os.macosx => {
+ builtin.Os.macosx, builtin.Os.freebsd => {
var eventlist: [1]posix.Kevent = undefined;
const empty_kevs = ([*]posix.Kevent)(undefined)[0..0];
const count = os.bsdKEvent(self.os_data.kqfd, empty_kevs, eventlist[0..], null) catch unreachable;
@@ -731,7 +732,7 @@ pub const Loop = struct {
self.beginOneEvent(); // finished in posixFsRun after processing the msg
self.os_data.fs_queue.put(request_node);
switch (builtin.os) {
- builtin.Os.macosx => {
+ builtin.Os.macosx, builtin.Os.freebsd => {
const fs_kevs = (*[1]posix.Kevent)(&self.os_data.fs_kevent_wake);
const empty_kevs = ([*]posix.Kevent)(undefined)[0..0];
_ = os.bsdKEvent(self.os_data.fs_kqfd, fs_kevs, empty_kevs, null) catch unreachable;
@@ -801,7 +802,7 @@ pub const Loop = struct {
else => unreachable,
}
},
- builtin.Os.macosx => {
+ builtin.Os.macosx, builtin.Os.freebsd => {
const fs_kevs = (*[1]posix.Kevent)(&self.os_data.fs_kevent_wait);
var out_kevs: [1]posix.Kevent = undefined;
_ = os.bsdKEvent(self.os_data.fs_kqfd, fs_kevs, out_kevs[0..], null) catch unreachable;
@@ -813,7 +814,7 @@ pub const Loop = struct {
const OsData = switch (builtin.os) {
builtin.Os.linux => LinuxOsData,
- builtin.Os.macosx => MacOsData,
+ builtin.Os.macosx, builtin.Os.freebsd => KEventData,
builtin.Os.windows => struct {
io_port: windows.HANDLE,
extra_thread_count: usize,
@@ -821,7 +822,7 @@ pub const Loop = struct {
else => struct {},
};
- const MacOsData = struct {
+ const KEventData = struct {
kqfd: i32,
final_kevent: posix.Kevent,
fs_kevent_wake: posix.Kevent,