Skip to content

Commit 2fb2ecb

Browse files
committed
backend/kqueue: update for Zig 0.14.0-dev.1304+7d54c62c8
1 parent 43c7e4b commit 2fb2ecb

File tree

1 file changed

+42
-42
lines changed

1 file changed

+42
-42
lines changed

src/backend/kqueue.zig

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub const Loop = struct {
4747
/// Values in the completion queue must not be in the kqueue.
4848
completions: queue.Intrusive(Completion) = .{},
4949

50-
/// Heap of timers. We use heaps instead of the EVFILT_TIMER because
50+
/// Heap of timers. We use heaps instead of the EVFILT.TIMER because
5151
/// it avoids a lot of syscalls in the case where there are a LOT of
5252
/// timers.
5353
timers: TimerHeap = .{ .context = {} },
@@ -169,7 +169,7 @@ pub const Loop = struct {
169169
self.completions.push(c);
170170

171171
events[events_len] = ev;
172-
events[events_len].flags = posix.system.EV_DELETE;
172+
events[events_len].flags = posix.system.EV.DELETE;
173173
events_len += 1;
174174
if (events_len >= events.len) break :queue_pop;
175175
},
@@ -209,12 +209,12 @@ pub const Loop = struct {
209209
const c: *Completion = @ptrFromInt(@as(usize, @intCast(ev.udata)));
210210

211211
// We handle deletions separately.
212-
if (ev.flags & posix.system.EV_DELETE != 0) continue;
212+
if (ev.flags & posix.system.EV.DELETE != 0) continue;
213213

214-
// If EV_ERROR is set, then submission failed for this
214+
// If EV.ERROR is set, then submission failed for this
215215
// completion. We get the syscall errorcode from data and
216216
// store it.
217-
if (ev.flags & posix.system.EV_ERROR != 0) {
217+
if (ev.flags & posix.system.EV.ERROR != 0) {
218218
c.result = c.syscall_result(-@as(i32, @intCast(ev.data)));
219219
} else {
220220
// No error, means that this completion is ready to work.
@@ -288,9 +288,9 @@ pub const Loop = struct {
288288
// event. We have to add here because we need a stable self pointer.
289289
const events = [_]Kevent{.{
290290
.ident = @as(usize, @intCast(self.mach_port.port)),
291-
.filter = posix.system.EVFILT_MACHPORT,
292-
.flags = posix.system.EV_ADD | posix.system.EV_ENABLE,
293-
.fflags = posix.system.MACH_RCV_MSG,
291+
.filter = posix.system.EVFILT.MACHPORT,
292+
.flags = posix.system.EV.ADD | posix.system.EV.ENABLE,
293+
.fflags = posix.system.MACH_PORT_RIGHT.RECEIVE,
294294
.data = 0,
295295
.udata = 0,
296296
.ext = .{
@@ -425,7 +425,7 @@ pub const Loop = struct {
425425
.disarm => {
426426
if (disarm_ev) |ev| {
427427
events[changes] = ev;
428-
events[changes].flags = posix.system.EV_DELETE;
428+
events[changes].flags = posix.system.EV.DELETE;
429429
events[changes].udata = 0;
430430
changes += 1;
431431
assert(changes <= events.len);
@@ -448,16 +448,16 @@ pub const Loop = struct {
448448
const t = self.timers.peek() orelse break :timeout null;
449449

450450
// Determine the time in milliseconds.
451-
const ms_now = @as(u64, @intCast(self.cached_now.tv_sec)) * std.time.ms_per_s +
452-
@as(u64, @intCast(self.cached_now.tv_nsec)) / std.time.ns_per_ms;
453-
const ms_next = @as(u64, @intCast(t.next.tv_sec)) * std.time.ms_per_s +
454-
@as(u64, @intCast(t.next.tv_nsec)) / std.time.ns_per_ms;
451+
const ms_now = @as(u64, @intCast(self.cached_now.sec)) * std.time.ms_per_s +
452+
@as(u64, @intCast(self.cached_now.nsec)) / std.time.ns_per_ms;
453+
const ms_next = @as(u64, @intCast(t.next.sec)) * std.time.ms_per_s +
454+
@as(u64, @intCast(t.next.nsec)) / std.time.ns_per_ms;
455455
const ms = ms_next -| ms_now;
456456

457457
// Convert to s/ns for the timespec
458458
const sec = ms / std.time.ms_per_s;
459459
const nsec = (ms % std.time.ms_per_s) * std.time.ns_per_ms;
460-
break :timeout .{ .tv_sec = @intCast(sec), .tv_nsec = @intCast(nsec) };
460+
break :timeout .{ .sec = @intCast(sec), .nsec = @intCast(nsec) };
461461
};
462462

463463
// Wait for changes. Note that we ALWAYS attempt to get completions
@@ -495,13 +495,13 @@ pub const Loop = struct {
495495
// Ignore any successful deletions. This can only happen
496496
// from disarms below and in that case we already processed
497497
// their callback.
498-
if (ev.flags & posix.system.EV_DELETE != 0) continue;
498+
if (ev.flags & posix.system.EV.DELETE != 0) continue;
499499

500500
// This can only be set during changelist processing so
501501
// that means that this event was never actually active.
502502
// Therefore, we only decrement the waiters by 1 if we
503503
// processed an active change.
504-
if (ev.flags & posix.system.EV_ERROR != 0) {
504+
if (ev.flags & posix.system.EV.ERROR != 0) {
505505
// We cannot use c here because c is already dead
506506
// at this point for this event.
507507
continue;
@@ -521,7 +521,7 @@ pub const Loop = struct {
521521
// Mark this event for deletion, it'll happen
522522
// on the next tick.
523523
events[changes] = ev;
524-
events[changes].flags = posix.system.EV_DELETE;
524+
events[changes].flags = posix.system.EV.DELETE;
525525
events[changes].udata = 0;
526526
changes += 1;
527527
assert(changes <= events.len);
@@ -559,8 +559,8 @@ pub const Loop = struct {
559559

560560
// Calculate all the values, being careful about overflows in order
561561
// to just return the maximum value.
562-
const sec = std.math.mul(isize, self.cached_now.tv_sec, std.time.ms_per_s) catch return max;
563-
const nsec = @divFloor(self.cached_now.tv_nsec, std.time.ns_per_ms);
562+
const sec = std.math.mul(isize, self.cached_now.sec, std.time.ms_per_s) catch return max;
563+
const nsec = @divFloor(self.cached_now.nsec, std.time.ns_per_ms);
564564
return std.math.lossyCast(i64, sec +| nsec);
565565
}
566566

@@ -638,8 +638,8 @@ pub const Loop = struct {
638638
// There are lots of failure scenarios here in math. If we see any
639639
// of them we just use the maximum value.
640640
const max: posix.timespec = .{
641-
.tv_sec = std.math.maxInt(isize),
642-
.tv_nsec = std.math.maxInt(isize),
641+
.sec = std.math.maxInt(isize),
642+
.nsec = std.math.maxInt(isize),
643643
};
644644

645645
const next_s = std.math.cast(isize, next_ms / std.time.ms_per_s) orelse
@@ -650,9 +650,9 @@ pub const Loop = struct {
650650
) orelse return max;
651651

652652
return .{
653-
.tv_sec = std.math.add(isize, self.cached_now.tv_sec, next_s) catch
653+
.sec = std.math.add(isize, self.cached_now.sec, next_s) catch
654654
return max,
655-
.tv_nsec = std.math.add(isize, self.cached_now.tv_nsec, next_ns) catch
655+
.nsec = std.math.add(isize, self.cached_now.nsec, next_ns) catch
656656
return max,
657657
};
658658
}
@@ -1026,17 +1026,17 @@ pub const Completion = struct {
10261026

10271027
.accept => |v| kevent_init(.{
10281028
.ident = @intCast(v.socket),
1029-
.filter = posix.system.EVFILT_READ,
1030-
.flags = posix.system.EV_ADD | posix.system.EV_ENABLE,
1029+
.filter = posix.system.EVFILT.READ,
1030+
.flags = posix.system.EV.ADD | posix.system.EV.ENABLE,
10311031
.fflags = 0,
10321032
.data = 0,
10331033
.udata = @intFromPtr(self),
10341034
}),
10351035

10361036
.connect => |v| kevent_init(.{
10371037
.ident = @intCast(v.socket),
1038-
.filter = posix.system.EVFILT_WRITE,
1039-
.flags = posix.system.EV_ADD | posix.system.EV_ENABLE,
1038+
.filter = posix.system.EVFILT.WRITE,
1039+
.flags = posix.system.EV.ADD | posix.system.EV.ENABLE,
10401040
.fflags = 0,
10411041
.data = 0,
10421042
.udata = @intFromPtr(self),
@@ -1053,12 +1053,12 @@ pub const Completion = struct {
10531053

10541054
// The kevent below waits for a machport to have a message
10551055
// available AND automatically reads the message into the
1056-
// buffer since MACH_RCV_MSG is set.
1056+
// buffer since MACH_PORT_RIGHT.RECEIVE is set.
10571057
break :kevent .{
10581058
.ident = @intCast(v.port),
1059-
.filter = posix.system.EVFILT_MACHPORT,
1060-
.flags = posix.system.EV_ADD | posix.system.EV_ENABLE,
1061-
.fflags = posix.system.MACH_RCV_MSG,
1059+
.filter = posix.system.EVFILT.MACHPORT,
1060+
.flags = posix.system.EV.ADD | posix.system.EV.ENABLE,
1061+
.fflags = posix.system.MACH_PORT_RIGHT.RECEIVE,
10621062
.data = 0,
10631063
.udata = @intFromPtr(self),
10641064
.ext = .{ @intFromPtr(slice.ptr), slice.len },
@@ -1067,26 +1067,26 @@ pub const Completion = struct {
10671067

10681068
.proc => |v| kevent_init(.{
10691069
.ident = @intCast(v.pid),
1070-
.filter = posix.system.EVFILT_PROC,
1071-
.flags = posix.system.EV_ADD | posix.system.EV_ENABLE,
1070+
.filter = posix.system.EVFILT.PROC,
1071+
.flags = posix.system.EV.ADD | posix.system.EV.ENABLE,
10721072
.fflags = v.flags,
10731073
.data = 0,
10741074
.udata = @intFromPtr(self),
10751075
}),
10761076

10771077
inline .write, .pwrite, .send, .sendto => |v| kevent_init(.{
10781078
.ident = @intCast(v.fd),
1079-
.filter = posix.system.EVFILT_WRITE,
1080-
.flags = posix.system.EV_ADD | posix.system.EV_ENABLE,
1079+
.filter = posix.system.EVFILT.WRITE,
1080+
.flags = posix.system.EV.ADD | posix.system.EV.ENABLE,
10811081
.fflags = 0,
10821082
.data = 0,
10831083
.udata = @intFromPtr(self),
10841084
}),
10851085

10861086
inline .read, .pread, .recv, .recvfrom => |v| kevent_init(.{
10871087
.ident = @intCast(v.fd),
1088-
.filter = posix.system.EVFILT_READ,
1089-
.flags = posix.system.EV_ADD | posix.system.EV_ENABLE,
1088+
.filter = posix.system.EVFILT.READ,
1089+
.flags = posix.system.EV.ADD | posix.system.EV.ENABLE,
10901090
.fflags = 0,
10911091
.data = 0,
10921092
.udata = @intFromPtr(self),
@@ -1220,7 +1220,7 @@ pub const Completion = struct {
12201220
const ev = ev_ orelse break :res .{ .proc = ProcError.MissingKevent };
12211221

12221222
// If we have the exit status, we read it.
1223-
if (ev.fflags & (posix.system.NOTE_EXIT | posix.system.NOTE_EXITSTATUS) > 0) {
1223+
if (ev.fflags & (posix.system.NOTE.EXIT | posix.system.NOTE.EXITSTATUS) > 0) {
12241224
const data: u32 = @intCast(ev.data);
12251225
if (posix.W.IFEXITED(data)) break :res .{
12261226
.proc = posix.W.EXITSTATUS(data),
@@ -1653,16 +1653,16 @@ const Timer = struct {
16531653
/// any software is running in 584 years waiting on this timer...
16541654
/// shame on me I guess... but I'll be dead.
16551655
fn ns(self: *const Timer) u64 {
1656-
assert(self.next.tv_sec >= 0);
1657-
assert(self.next.tv_nsec >= 0);
1656+
assert(self.next.sec >= 0);
1657+
assert(self.next.nsec >= 0);
16581658

16591659
const max = std.math.maxInt(u64);
16601660
const s_ns = std.math.mul(
16611661
u64,
1662-
@as(u64, @intCast(self.next.tv_sec)),
1662+
@as(u64, @intCast(self.next.sec)),
16631663
std.time.ns_per_s,
16641664
) catch return max;
1665-
return std.math.add(u64, s_ns, @as(u64, @intCast(self.next.tv_nsec))) catch
1665+
return std.math.add(u64, s_ns, @as(u64, @intCast(self.next.nsec))) catch
16661666
return max;
16671667
}
16681668
};

0 commit comments

Comments
 (0)