| ... | @@ -95,6 +95,21 @@ pub const Reactor = struct { | ... | @@ -95,6 +95,21 @@ pub const Reactor = struct { |
| 95 | }; | 95 | }; |
| 96 | } | 96 | } |
| 97 | | 97 | |
| | 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 | |
| 98 | pub fn poll(self: Reactor, comptime max_num_events: comptime_int, closure: anytype, timeout_milliseconds: ?u64) !void { | 113 | pub fn poll(self: Reactor, comptime max_num_events: comptime_int, closure: anytype, timeout_milliseconds: ?u64) !void { |
| 99 | var events: [max_num_events]linux.epoll_event = undefined; | 114 | var events: [max_num_events]linux.epoll_event = undefined; |
| 100 | | 115 | |
| ... | @@ -203,4 +218,7 @@ test "reactor/linux: drive async tcp client/listener pair" { | ... | @@ -203,4 +218,7 @@ test "reactor/linux: drive async tcp client/listener pair" { |
| 203 | }, event); | 218 | }, event); |
| 204 | } | 219 | } |
| 205 | }, null); | 220 | }, null); |
| | 221 | |
| | 222 | try reactor.remove(client.socket.fd); |
| | 223 | try reactor.remove(listener.socket.fd); |
| 206 | } | 224 | } |