Merge branch 'kristoff-it-macos-kqueue'

closes #5286
master
Andrew Kelley 2020-05-07 13:41:26 -04:00
commit 3aa259d119
2 changed files with 24 additions and 15 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),
}};
@ -616,14 +623,16 @@ pub const Loop = struct {
self.workerRun();
switch (builtin.os.tag) {
.linux,
.macosx,
.freebsd,
.netbsd,
.dragonfly,
=> self.fs_thread.wait(),
else => {},
if (!builtin.single_threaded) {
switch (builtin.os.tag) {
.linux,
.macosx,
.freebsd,
.netbsd,
.dragonfly,
=> self.fs_thread.wait(),
else => {},
}
}
for (self.extra_threads) |extra_thread| {

View File

@ -2549,7 +2549,7 @@ pub fn connect(sockfd: fd_t, sock_addr: *const sockaddr, len: socklen_t) Connect
EAFNOSUPPORT => return error.AddressFamilyNotSupported,
EAGAIN, EINPROGRESS => {
const loop = std.event.Loop.instance orelse return error.WouldBlock;
loop.waitUntilFdWritableOrReadable(sockfd);
loop.waitUntilFdWritable(sockfd);
return getsockoptError(sockfd);
},
EALREADY => unreachable, // The socket is nonblocking and a previous connection attempt has not yet been completed.