Skip to content

Commit b2ffe11

Browse files
authored
x/os/Reactor: implement remove function (#13330)
* x/os/Reactor: implement remove function * x/os/Reactor: update tests
1 parent 81dadbc commit b2ffe11

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lib/std/x/os/io.zig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,21 @@ pub const Reactor = struct {
9595
};
9696
}
9797

98+
pub fn remove(self: Reactor, fd: os.fd_t) !void {
99+
// directly from man epoll_ctl BUGS section
100+
// In kernel versions before 2.6.9, the EPOLL_CTL_DEL operation re‐
101+
// quired a non-null pointer in event, even though this argument is
102+
// ignored. Since Linux 2.6.9, event can be specified as NULL when
103+
// using EPOLL_CTL_DEL. Applications that need to be portable to
104+
// kernels before 2.6.9 should specify a non-null pointer in event.
105+
var event = linux.epoll_event{
106+
.events = 0,
107+
.data = .{ .ptr = 0 },
108+
};
109+
110+
return os.epoll_ctl(self.fd, linux.EPOLL.CTL_DEL, fd, &event);
111+
}
112+
98113
pub fn poll(self: Reactor, comptime max_num_events: comptime_int, closure: anytype, timeout_milliseconds: ?u64) !void {
99114
var events: [max_num_events]linux.epoll_event = undefined;
100115

@@ -203,4 +218,7 @@ test "reactor/linux: drive async tcp client/listener pair" {
203218
}, event);
204219
}
205220
}, null);
221+
222+
try reactor.remove(client.socket.fd);
223+
try reactor.remove(listener.socket.fd);
206224
}

0 commit comments

Comments
 (0)