Fix kqueue_close_cb logic to use EV_RECEIPT

Using this flag tells kevent to keep processing even when an error is
encountered adding an event. This means that it will actually check both
EVFILT_READ and EVFILT_WRITE now.

With the old code, we were leaking descriptors created for EVFILT_WRITE.
This commit is contained in:
Ariel Abreu 2022-03-09 17:09:26 -05:00
parent f721a1d2d8
commit f3f8cb99b0
No known key found for this signature in database
GPG Key ID: D67AE16CCEA85B70

View File

@ -139,16 +139,17 @@ static void _kqueue_close_cb(int kqfd, void* kqptr, void* private)
struct kqueue* kq = (struct kqueue*) kqptr;
int closing_fd = (int) private;
struct kevent64_s ev[2];
struct kevent64_s results[2];
ev[0].ident = closing_fd;
ev[0].flags = EV_DELETE;
ev[0].flags = EV_DELETE | EV_RECEIPT;
ev[0].filter = EVFILT_READ;
ev[1].ident = closing_fd;
ev[1].flags = EV_DELETE;
ev[1].flags = EV_DELETE | EV_RECEIPT;
ev[1].filter = EVFILT_WRITE;
// We don't care if it fails or not...
kevent64(kqfd, ev, 2, NULL, 0, 0, NULL);
kevent64(kqfd, ev, 2, results, 2, KEVENT_FLAG_ERROR_EVENTS, NULL);
}
void VISIBLE