Skip to content

Commit 6b87aba

Browse files
committed
Removing all kqueue events after wait
1 parent fe9b1a1 commit 6b87aba

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

ext/socket/selector-kqueue.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static SgObject wait_selector(unix_context_t *ctx, int nsock,
5959
{
6060
SgObject cp, r = SG_NIL;
6161
int i, c, n = nsock + 1;
62-
struct kevent *evm, ev;
62+
struct kevent *evm;
6363

6464
evm = SG_NEW_ATOMIC2(struct kevent *, n * sizeof(struct kevent));
6565
i = 0;
@@ -82,10 +82,22 @@ static SgObject wait_selector(unix_context_t *ctx, int nsock,
8282
interrupted_unix_stop(ctx);
8383
} else if (evm[i].filter == EVFILT_READ) {
8484
r = Sg_Cons(evm[i].udata, r);
85+
#if 0
8586
EV_SET(&ev, evm[i].ident, EVFILT_READ, EV_DELETE, 0, 0, NULL);
8687
kevent(ctx->fd, &ev, 1, NULL, 0, 0); /* reset event of the target socket */
88+
#endif
8789
}
8890
}
91+
92+
i = 0;
93+
SG_FOR_EACH(cp, sockets) {
94+
int fd = SG_SOCKET(SG_CAAR(cp))->socket;
95+
EV_SET(&evm[i++], fd, EVFILT_READ, EV_DELETE, 0, 0, NULL);
96+
if (i == nsock) break;
97+
}
98+
EV_SET(&evm[i++], ctx->stop_fd, EVFILT_READ, EV_DELETE, 0, 0, NULL);
99+
kevent(ctx->fd, evm, n, NULL, 0, 0);
100+
89101
return r;
90102
}
91103

0 commit comments

Comments
 (0)