-
Notifications
You must be signed in to change notification settings - Fork 38
/
node-libuv.diff
117 lines (102 loc) · 4.35 KB
/
node-libuv.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
commit 6913f8b92dd44a525152afd3ae770bc429f133e5
Author: Dean McNamee <[email protected]>
Date: Fri Dec 21 16:11:34 2012 +0100
Patch libuv to allow hooking into the kqueue calls.
diff --git a/deps/uv/include/uv.h b/deps/uv/include/uv.h
index 57ce8ae..b02d767 100644
--- a/deps/uv/include/uv.h
+++ b/deps/uv/include/uv.h
@@ -1933,6 +1933,7 @@ struct uv_loop_s {
unsigned int active_handles;
ngx_queue_t handle_queue;
ngx_queue_t active_reqs;
+ void* keventfunc;
UV_LOOP_PRIVATE_FIELDS
};
diff --git a/deps/uv/src/unix/kqueue.c b/deps/uv/src/unix/kqueue.c
index af9078e..4e42222 100644
--- a/deps/uv/src/unix/kqueue.c
+++ b/deps/uv/src/unix/kqueue.c
@@ -66,6 +66,9 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
int fd;
int op;
int i;
+ int (*keventfunc)(int kq, const struct kevent *changelist, int nchanges,
+ struct kevent *eventlist, int nevents, const struct timespec *timeout) =
+ loop->keventfunc ? loop->keventfunc : &kevent;
if (loop->nfds == 0) {
assert(ngx_queue_empty(&loop->watcher_queue));
@@ -105,7 +108,7 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
EV_SET(events + nevents, w->fd, filter, op, fflags, 0, 0);
if (++nevents == ARRAY_SIZE(events)) {
- if (kevent(loop->backend_fd, events, nevents, NULL, 0, NULL))
+ if (keventfunc(loop->backend_fd, events, nevents, NULL, 0, NULL))
abort();
nevents = 0;
}
@@ -115,7 +118,7 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
EV_SET(events + nevents, w->fd, EVFILT_WRITE, EV_ADD, 0, 0, 0);
if (++nevents == ARRAY_SIZE(events)) {
- if (kevent(loop->backend_fd, events, nevents, NULL, 0, NULL))
+ if (keventfunc(loop->backend_fd, events, nevents, NULL, 0, NULL))
abort();
nevents = 0;
}
@@ -134,7 +137,7 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
spec.tv_nsec = (timeout % 1000) * 1000000;
}
- nfds = kevent(loop->backend_fd,
+ nfds = keventfunc(loop->backend_fd,
events,
nevents,
events,
@@ -173,7 +176,7 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
struct kevent events[1];
EV_SET(events + 0, fd, ev->filter, EV_DELETE, 0, 0, 0);
- if (kevent(loop->backend_fd, events, 1, NULL, 0, NULL))
+ if (keventfunc(loop->backend_fd, events, 1, NULL, 0, NULL))
if (errno != EBADF && errno != ENOENT)
abort();
@@ -197,7 +200,7 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
/* TODO batch up */
struct kevent events[1];
EV_SET(events + 0, fd, ev->filter, EV_DELETE, 0, 0, 0);
- if (kevent(loop->backend_fd, events, 1, NULL, 0, NULL))
+ if (keventfunc(loop->backend_fd, events, 1, NULL, 0, NULL))
if (errno != ENOENT)
abort();
}
@@ -210,7 +213,7 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
/* TODO batch up */
struct kevent events[1];
EV_SET(events + 0, fd, ev->filter, EV_DELETE, 0, 0, 0);
- if (kevent(loop->backend_fd, events, 1, NULL, 0, NULL))
+ if (keventfunc(loop->backend_fd, events, 1, NULL, 0, NULL))
if (errno != ENOENT)
abort();
}
@@ -260,6 +263,9 @@ static void uv__fs_event(uv_loop_t* loop, uv__io_t* w, unsigned int fflags) {
uv_fs_event_t* handle;
struct kevent ev;
int events;
+ int (*keventfunc)(int kq, const struct kevent *changelist, int nchanges,
+ struct kevent *eventlist, int nevents, const struct timespec *timeout) =
+ loop->keventfunc ? loop->keventfunc : &kevent;
handle = container_of(w, uv_fs_event_t, event_watcher);
@@ -279,7 +285,7 @@ static void uv__fs_event(uv_loop_t* loop, uv__io_t* w, unsigned int fflags) {
EV_SET(&ev, w->fd, EVFILT_VNODE, EV_ADD | EV_ONESHOT, fflags, 0, 0);
- if (kevent(loop->backend_fd, &ev, 1, NULL, 0, NULL))
+ if (keventfunc(loop->backend_fd, &ev, 1, NULL, 0, NULL))
abort();
}
diff --git a/deps/uv/src/unix/loop.c b/deps/uv/src/unix/loop.c
index e63f12a..c09d68b 100644
--- a/deps/uv/src/unix/loop.c
+++ b/deps/uv/src/unix/loop.c
@@ -56,6 +56,7 @@ int uv__loop_init(uv_loop_t* loop, int default_loop) {
loop->signal_pipefd[1] = -1;
loop->backend_fd = -1;
loop->emfile_fd = -1;
+ loop->keventfunc = NULL;
if (uv__platform_loop_init(loop, default_loop))
return -1;