fix oneshot flag erroneusly set as filter_flag

master
Loris Cro 2020-05-07 01:55:19 +02:00 committed by Andrew Kelley
parent a78ac96134
commit 7e8b859095
1 changed files with 13 additions and 6 deletions

View File

@ -503,7 +503,7 @@ pub const Loop = struct {
}
}
pub fn bsdWaitKev(self: *Loop, ident: usize, filter: i16, fflags: u32) callconv(.Async) void {
pub fn bsdWaitKev(self: *Loop, ident: usize, filter: i16, flags: u16) void {
var resume_node = ResumeNode.Basic{
.base = ResumeNode{
.id = ResumeNode.Id.Basic,
@ -512,21 +512,28 @@ pub const Loop = struct {
},
.kev = undefined,
};
defer self.bsdRemoveKev(ident, filter);
defer {
// If the kevent was set to be ONESHOT, it doesn't need to be deleted manually.
if (flags & os.EV_ONESHOT != 0) {
self.bsdRemoveKev(ident, filter);
}
}
suspend {
self.bsdAddKev(&resume_node, ident, filter, fflags) catch unreachable;
self.bsdAddKev(&resume_node, ident, filter, flags) catch unreachable;
}
}
/// resume_node must live longer than the anyframe that it holds a reference to.
pub fn bsdAddKev(self: *Loop, resume_node: *ResumeNode.Basic, ident: usize, filter: i16, fflags: u32) !void {
pub fn bsdAddKev(self: *Loop, resume_node: *ResumeNode.Basic, ident: usize, filter: i16, flags: u16) !void {
self.beginOneEvent();
errdefer self.finishOneEvent();
var kev = [1]os.Kevent{os.Kevent{
.ident = ident,
.filter = filter,
.flags = os.EV_ADD | os.EV_ENABLE | os.EV_CLEAR,
.fflags = fflags,
.flags = os.EV_ADD | os.EV_ENABLE | os.EV_CLEAR | flags,
.fflags = 0,
.data = 0,
.udata = @ptrToInt(&resume_node.base),
}};