rbuv 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +5 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +0 -1
- data/README.md +6 -1
- data/Rakefile +42 -0
- data/deps/libuv/.gitignore +34 -0
- data/deps/libuv/.mailmap +16 -0
- data/deps/libuv/AUTHORS +81 -0
- data/deps/libuv/ChangeLog +45 -0
- data/deps/libuv/LICENSE +41 -0
- data/deps/libuv/Makefile +53 -0
- data/deps/libuv/README.md +118 -0
- data/deps/libuv/build.mk +164 -0
- data/deps/libuv/checksparse.sh +230 -0
- data/deps/libuv/common.gypi +197 -0
- data/deps/libuv/config-mingw.mk +48 -0
- data/deps/libuv/config-unix.mk +167 -0
- data/deps/libuv/gyp_uv +98 -0
- data/deps/libuv/include/uv-private/ngx-queue.h +129 -0
- data/deps/libuv/include/uv-private/stdint-msvc2008.h +247 -0
- data/deps/libuv/include/uv-private/tree.h +768 -0
- data/deps/libuv/include/uv-private/uv-bsd.h +34 -0
- data/deps/libuv/include/uv-private/uv-darwin.h +61 -0
- data/deps/libuv/include/uv-private/uv-linux.h +34 -0
- data/deps/libuv/include/uv-private/uv-sunos.h +44 -0
- data/deps/libuv/include/uv-private/uv-unix.h +332 -0
- data/deps/libuv/include/uv-private/uv-win.h +585 -0
- data/deps/libuv/include/uv.h +1987 -0
- data/deps/libuv/src/fs-poll.c +248 -0
- data/deps/libuv/src/inet.c +298 -0
- data/deps/libuv/src/unix/aix.c +393 -0
- data/deps/libuv/src/unix/async.c +281 -0
- data/deps/libuv/src/unix/core.c +714 -0
- data/deps/libuv/src/unix/cygwin.c +93 -0
- data/deps/libuv/src/unix/darwin-proctitle.m +78 -0
- data/deps/libuv/src/unix/darwin.c +431 -0
- data/deps/libuv/src/unix/dl.c +83 -0
- data/deps/libuv/src/unix/error.c +109 -0
- data/deps/libuv/src/unix/freebsd.c +343 -0
- data/deps/libuv/src/unix/fs.c +869 -0
- data/deps/libuv/src/unix/fsevents.c +299 -0
- data/deps/libuv/src/unix/getaddrinfo.c +159 -0
- data/deps/libuv/src/unix/internal.h +259 -0
- data/deps/libuv/src/unix/kqueue.c +347 -0
- data/deps/libuv/src/unix/linux-core.c +724 -0
- data/deps/libuv/src/unix/linux-inotify.c +236 -0
- data/deps/libuv/src/unix/linux-syscalls.c +388 -0
- data/deps/libuv/src/unix/linux-syscalls.h +150 -0
- data/deps/libuv/src/unix/loop-watcher.c +64 -0
- data/deps/libuv/src/unix/loop.c +114 -0
- data/deps/libuv/src/unix/netbsd.c +353 -0
- data/deps/libuv/src/unix/openbsd.c +304 -0
- data/deps/libuv/src/unix/pipe.c +261 -0
- data/deps/libuv/src/unix/poll.c +108 -0
- data/deps/libuv/src/unix/process.c +501 -0
- data/deps/libuv/src/unix/proctitle.c +103 -0
- data/deps/libuv/src/unix/signal.c +455 -0
- data/deps/libuv/src/unix/stream.c +1380 -0
- data/deps/libuv/src/unix/sunos.c +647 -0
- data/deps/libuv/src/unix/tcp.c +357 -0
- data/deps/libuv/src/unix/thread.c +431 -0
- data/deps/libuv/src/unix/threadpool.c +286 -0
- data/deps/libuv/src/unix/timer.c +153 -0
- data/deps/libuv/src/unix/tty.c +179 -0
- data/deps/libuv/src/unix/udp.c +715 -0
- data/deps/libuv/src/uv-common.c +431 -0
- data/deps/libuv/src/uv-common.h +204 -0
- data/deps/libuv/src/version.c +60 -0
- data/deps/libuv/src/win/async.c +99 -0
- data/deps/libuv/src/win/atomicops-inl.h +56 -0
- data/deps/libuv/src/win/core.c +310 -0
- data/deps/libuv/src/win/dl.c +86 -0
- data/deps/libuv/src/win/error.c +164 -0
- data/deps/libuv/src/win/fs-event.c +506 -0
- data/deps/libuv/src/win/fs.c +1951 -0
- data/deps/libuv/src/win/getaddrinfo.c +365 -0
- data/deps/libuv/src/win/handle-inl.h +164 -0
- data/deps/libuv/src/win/handle.c +153 -0
- data/deps/libuv/src/win/internal.h +346 -0
- data/deps/libuv/src/win/loop-watcher.c +124 -0
- data/deps/libuv/src/win/pipe.c +1656 -0
- data/deps/libuv/src/win/poll.c +615 -0
- data/deps/libuv/src/win/process-stdio.c +503 -0
- data/deps/libuv/src/win/process.c +1048 -0
- data/deps/libuv/src/win/req-inl.h +224 -0
- data/deps/libuv/src/win/req.c +25 -0
- data/deps/libuv/src/win/signal.c +354 -0
- data/deps/libuv/src/win/stream-inl.h +67 -0
- data/deps/libuv/src/win/stream.c +198 -0
- data/deps/libuv/src/win/tcp.c +1422 -0
- data/deps/libuv/src/win/thread.c +666 -0
- data/deps/libuv/src/win/threadpool.c +82 -0
- data/deps/libuv/src/win/timer.c +230 -0
- data/deps/libuv/src/win/tty.c +1857 -0
- data/deps/libuv/src/win/udp.c +744 -0
- data/deps/libuv/src/win/util.c +946 -0
- data/deps/libuv/src/win/winapi.c +152 -0
- data/deps/libuv/src/win/winapi.h +4476 -0
- data/deps/libuv/src/win/winsock.c +560 -0
- data/deps/libuv/src/win/winsock.h +171 -0
- data/deps/libuv/test/benchmark-async-pummel.c +119 -0
- data/deps/libuv/test/benchmark-async.c +139 -0
- data/deps/libuv/test/benchmark-fs-stat.c +136 -0
- data/deps/libuv/test/benchmark-getaddrinfo.c +91 -0
- data/deps/libuv/test/benchmark-list.h +163 -0
- data/deps/libuv/test/benchmark-loop-count.c +90 -0
- data/deps/libuv/test/benchmark-million-async.c +112 -0
- data/deps/libuv/test/benchmark-million-timers.c +77 -0
- data/deps/libuv/test/benchmark-multi-accept.c +432 -0
- data/deps/libuv/test/benchmark-ping-pongs.c +212 -0
- data/deps/libuv/test/benchmark-pound.c +325 -0
- data/deps/libuv/test/benchmark-pump.c +459 -0
- data/deps/libuv/test/benchmark-sizes.c +45 -0
- data/deps/libuv/test/benchmark-spawn.c +163 -0
- data/deps/libuv/test/benchmark-tcp-write-batch.c +141 -0
- data/deps/libuv/test/benchmark-thread.c +64 -0
- data/deps/libuv/test/benchmark-udp-pummel.c +238 -0
- data/deps/libuv/test/blackhole-server.c +118 -0
- data/deps/libuv/test/dns-server.c +329 -0
- data/deps/libuv/test/echo-server.c +384 -0
- data/deps/libuv/test/fixtures/empty_file +0 -0
- data/deps/libuv/test/fixtures/load_error.node +1 -0
- data/deps/libuv/test/run-benchmarks.c +64 -0
- data/deps/libuv/test/run-tests.c +159 -0
- data/deps/libuv/test/runner-unix.c +328 -0
- data/deps/libuv/test/runner-unix.h +36 -0
- data/deps/libuv/test/runner-win.c +318 -0
- data/deps/libuv/test/runner-win.h +43 -0
- data/deps/libuv/test/runner.c +394 -0
- data/deps/libuv/test/runner.h +165 -0
- data/deps/libuv/test/task.h +122 -0
- data/deps/libuv/test/test-active.c +83 -0
- data/deps/libuv/test/test-async.c +136 -0
- data/deps/libuv/test/test-barrier.c +98 -0
- data/deps/libuv/test/test-callback-order.c +77 -0
- data/deps/libuv/test/test-callback-stack.c +204 -0
- data/deps/libuv/test/test-condvar.c +173 -0
- data/deps/libuv/test/test-connection-fail.c +150 -0
- data/deps/libuv/test/test-cwd-and-chdir.c +64 -0
- data/deps/libuv/test/test-delayed-accept.c +189 -0
- data/deps/libuv/test/test-dlerror.c +58 -0
- data/deps/libuv/test/test-embed.c +136 -0
- data/deps/libuv/test/test-error.c +59 -0
- data/deps/libuv/test/test-fail-always.c +29 -0
- data/deps/libuv/test/test-fs-event.c +504 -0
- data/deps/libuv/test/test-fs-poll.c +148 -0
- data/deps/libuv/test/test-fs.c +1899 -0
- data/deps/libuv/test/test-get-currentexe.c +63 -0
- data/deps/libuv/test/test-get-loadavg.c +36 -0
- data/deps/libuv/test/test-get-memory.c +38 -0
- data/deps/libuv/test/test-getaddrinfo.c +120 -0
- data/deps/libuv/test/test-getsockname.c +344 -0
- data/deps/libuv/test/test-hrtime.c +54 -0
- data/deps/libuv/test/test-idle.c +82 -0
- data/deps/libuv/test/test-ipc-send-recv.c +218 -0
- data/deps/libuv/test/test-ipc.c +625 -0
- data/deps/libuv/test/test-list.h +492 -0
- data/deps/libuv/test/test-loop-handles.c +337 -0
- data/deps/libuv/test/test-loop-stop.c +73 -0
- data/deps/libuv/test/test-multiple-listen.c +103 -0
- data/deps/libuv/test/test-mutexes.c +63 -0
- data/deps/libuv/test/test-pass-always.c +28 -0
- data/deps/libuv/test/test-ping-pong.c +250 -0
- data/deps/libuv/test/test-pipe-bind-error.c +144 -0
- data/deps/libuv/test/test-pipe-connect-error.c +98 -0
- data/deps/libuv/test/test-platform-output.c +87 -0
- data/deps/libuv/test/test-poll-close.c +73 -0
- data/deps/libuv/test/test-poll.c +575 -0
- data/deps/libuv/test/test-process-title.c +49 -0
- data/deps/libuv/test/test-ref.c +415 -0
- data/deps/libuv/test/test-run-nowait.c +46 -0
- data/deps/libuv/test/test-run-once.c +49 -0
- data/deps/libuv/test/test-semaphore.c +111 -0
- data/deps/libuv/test/test-shutdown-close.c +105 -0
- data/deps/libuv/test/test-shutdown-eof.c +184 -0
- data/deps/libuv/test/test-signal-multiple-loops.c +270 -0
- data/deps/libuv/test/test-signal.c +152 -0
- data/deps/libuv/test/test-spawn.c +938 -0
- data/deps/libuv/test/test-stdio-over-pipes.c +250 -0
- data/deps/libuv/test/test-tcp-bind-error.c +198 -0
- data/deps/libuv/test/test-tcp-bind6-error.c +159 -0
- data/deps/libuv/test/test-tcp-close-while-connecting.c +81 -0
- data/deps/libuv/test/test-tcp-close.c +130 -0
- data/deps/libuv/test/test-tcp-connect-error-after-write.c +96 -0
- data/deps/libuv/test/test-tcp-connect-error.c +71 -0
- data/deps/libuv/test/test-tcp-connect-timeout.c +86 -0
- data/deps/libuv/test/test-tcp-connect6-error.c +69 -0
- data/deps/libuv/test/test-tcp-flags.c +52 -0
- data/deps/libuv/test/test-tcp-open.c +175 -0
- data/deps/libuv/test/test-tcp-read-stop.c +73 -0
- data/deps/libuv/test/test-tcp-shutdown-after-write.c +132 -0
- data/deps/libuv/test/test-tcp-unexpected-read.c +114 -0
- data/deps/libuv/test/test-tcp-write-to-half-open-connection.c +136 -0
- data/deps/libuv/test/test-tcp-writealot.c +171 -0
- data/deps/libuv/test/test-thread.c +183 -0
- data/deps/libuv/test/test-threadpool-cancel.c +311 -0
- data/deps/libuv/test/test-threadpool.c +77 -0
- data/deps/libuv/test/test-timer-again.c +142 -0
- data/deps/libuv/test/test-timer.c +266 -0
- data/deps/libuv/test/test-tty.c +111 -0
- data/deps/libuv/test/test-udp-dgram-too-big.c +87 -0
- data/deps/libuv/test/test-udp-ipv6.c +158 -0
- data/deps/libuv/test/test-udp-multicast-join.c +140 -0
- data/deps/libuv/test/test-udp-multicast-ttl.c +87 -0
- data/deps/libuv/test/test-udp-open.c +154 -0
- data/deps/libuv/test/test-udp-options.c +87 -0
- data/deps/libuv/test/test-udp-send-and-recv.c +210 -0
- data/deps/libuv/test/test-util.c +97 -0
- data/deps/libuv/test/test-walk-handles.c +78 -0
- data/deps/libuv/uv.gyp +431 -0
- data/deps/libuv/vcbuild.bat +128 -0
- data/ext/rbuv/debug.h +27 -0
- data/ext/rbuv/error.c +7 -0
- data/ext/rbuv/error.h +10 -0
- data/ext/rbuv/extconf.rb +35 -0
- data/ext/rbuv/handle.c +40 -0
- data/ext/rbuv/handle.h +14 -0
- data/ext/rbuv/libuv.mk +12 -0
- data/ext/rbuv/loop.c +50 -0
- data/ext/rbuv/loop.h +13 -0
- data/ext/rbuv/rbuv.c +15 -0
- data/ext/rbuv/rbuv.h +27 -0
- data/ext/rbuv/timer.c +133 -0
- data/ext/rbuv/timer.h +13 -0
- data/lib/rbuv/timer.rb +7 -0
- data/lib/rbuv/version.rb +1 -1
- data/lib/rbuv.rb +24 -2
- data/rbuv.gemspec +5 -1
- data/spec/spec_helper.rb +22 -0
- data/spec/timer_spec.rb +144 -0
- metadata +278 -9
@@ -0,0 +1,224 @@
|
|
1
|
+
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
2
|
+
*
|
3
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
* of this software and associated documentation files (the "Software"), to
|
5
|
+
* deal in the Software without restriction, including without limitation the
|
6
|
+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
7
|
+
* sell copies of the Software, and to permit persons to whom the Software is
|
8
|
+
* furnished to do so, subject to the following conditions:
|
9
|
+
*
|
10
|
+
* The above copyright notice and this permission notice shall be included in
|
11
|
+
* all copies or substantial portions of the Software.
|
12
|
+
*
|
13
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
18
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
19
|
+
* IN THE SOFTWARE.
|
20
|
+
*/
|
21
|
+
|
22
|
+
#ifndef UV_WIN_REQ_INL_H_
|
23
|
+
#define UV_WIN_REQ_INL_H_
|
24
|
+
|
25
|
+
#include <assert.h>
|
26
|
+
|
27
|
+
#include "uv.h"
|
28
|
+
#include "internal.h"
|
29
|
+
|
30
|
+
|
31
|
+
#define SET_REQ_STATUS(req, status) \
|
32
|
+
(req)->overlapped.Internal = (ULONG_PTR) (status)
|
33
|
+
|
34
|
+
#define SET_REQ_ERROR(req, error) \
|
35
|
+
SET_REQ_STATUS((req), NTSTATUS_FROM_WIN32((error)))
|
36
|
+
|
37
|
+
#define SET_REQ_SUCCESS(req) \
|
38
|
+
SET_REQ_STATUS((req), STATUS_SUCCESS)
|
39
|
+
|
40
|
+
#define GET_REQ_STATUS(req) \
|
41
|
+
((NTSTATUS) (req)->overlapped.Internal)
|
42
|
+
|
43
|
+
#define REQ_SUCCESS(req) \
|
44
|
+
(NT_SUCCESS(GET_REQ_STATUS((req))))
|
45
|
+
|
46
|
+
#define GET_REQ_ERROR(req) \
|
47
|
+
(pRtlNtStatusToDosError(GET_REQ_STATUS((req))))
|
48
|
+
|
49
|
+
#define GET_REQ_SOCK_ERROR(req) \
|
50
|
+
(uv_ntstatus_to_winsock_error(GET_REQ_STATUS((req))))
|
51
|
+
|
52
|
+
|
53
|
+
#define REGISTER_HANDLE_REQ(loop, handle, req) \
|
54
|
+
do { \
|
55
|
+
INCREASE_ACTIVE_COUNT((loop), (handle)); \
|
56
|
+
uv__req_register((loop), (req)); \
|
57
|
+
} while (0)
|
58
|
+
|
59
|
+
#define UNREGISTER_HANDLE_REQ(loop, handle, req) \
|
60
|
+
do { \
|
61
|
+
DECREASE_ACTIVE_COUNT((loop), (handle)); \
|
62
|
+
uv__req_unregister((loop), (req)); \
|
63
|
+
} while (0)
|
64
|
+
|
65
|
+
|
66
|
+
#define UV_SUCCEEDED_WITHOUT_IOCP(result) \
|
67
|
+
((result) && (handle->flags & UV_HANDLE_SYNC_BYPASS_IOCP))
|
68
|
+
|
69
|
+
#define UV_SUCCEEDED_WITH_IOCP(result) \
|
70
|
+
((result) || (GetLastError() == ERROR_IO_PENDING))
|
71
|
+
|
72
|
+
|
73
|
+
#define POST_COMPLETION_FOR_REQ(loop, req) \
|
74
|
+
if (!PostQueuedCompletionStatus((loop)->iocp, \
|
75
|
+
0, \
|
76
|
+
0, \
|
77
|
+
&((req)->overlapped))) { \
|
78
|
+
uv_fatal_error(GetLastError(), "PostQueuedCompletionStatus"); \
|
79
|
+
}
|
80
|
+
|
81
|
+
|
82
|
+
INLINE static void uv_req_init(uv_loop_t* loop, uv_req_t* req) {
|
83
|
+
req->type = UV_UNKNOWN_REQ;
|
84
|
+
SET_REQ_SUCCESS(req);
|
85
|
+
}
|
86
|
+
|
87
|
+
|
88
|
+
INLINE static uv_req_t* uv_overlapped_to_req(OVERLAPPED* overlapped) {
|
89
|
+
return CONTAINING_RECORD(overlapped, uv_req_t, overlapped);
|
90
|
+
}
|
91
|
+
|
92
|
+
|
93
|
+
INLINE static void uv_insert_pending_req(uv_loop_t* loop, uv_req_t* req) {
|
94
|
+
req->next_req = NULL;
|
95
|
+
if (loop->pending_reqs_tail) {
|
96
|
+
req->next_req = loop->pending_reqs_tail->next_req;
|
97
|
+
loop->pending_reqs_tail->next_req = req;
|
98
|
+
loop->pending_reqs_tail = req;
|
99
|
+
} else {
|
100
|
+
req->next_req = req;
|
101
|
+
loop->pending_reqs_tail = req;
|
102
|
+
}
|
103
|
+
}
|
104
|
+
|
105
|
+
|
106
|
+
#define DELEGATE_STREAM_REQ(loop, req, method, handle_at) \
|
107
|
+
do { \
|
108
|
+
switch (((uv_handle_t*) (req)->handle_at)->type) { \
|
109
|
+
case UV_TCP: \
|
110
|
+
uv_process_tcp_##method##_req(loop, \
|
111
|
+
(uv_tcp_t*) ((req)->handle_at), \
|
112
|
+
req); \
|
113
|
+
break; \
|
114
|
+
\
|
115
|
+
case UV_NAMED_PIPE: \
|
116
|
+
uv_process_pipe_##method##_req(loop, \
|
117
|
+
(uv_pipe_t*) ((req)->handle_at), \
|
118
|
+
req); \
|
119
|
+
break; \
|
120
|
+
\
|
121
|
+
case UV_TTY: \
|
122
|
+
uv_process_tty_##method##_req(loop, \
|
123
|
+
(uv_tty_t*) ((req)->handle_at), \
|
124
|
+
req); \
|
125
|
+
break; \
|
126
|
+
\
|
127
|
+
default: \
|
128
|
+
assert(0); \
|
129
|
+
} \
|
130
|
+
} while (0)
|
131
|
+
|
132
|
+
|
133
|
+
INLINE static void uv_process_reqs(uv_loop_t* loop) {
|
134
|
+
uv_req_t* req;
|
135
|
+
uv_req_t* first;
|
136
|
+
uv_req_t* next;
|
137
|
+
|
138
|
+
if (loop->pending_reqs_tail == NULL) {
|
139
|
+
return;
|
140
|
+
}
|
141
|
+
|
142
|
+
first = loop->pending_reqs_tail->next_req;
|
143
|
+
next = first;
|
144
|
+
loop->pending_reqs_tail = NULL;
|
145
|
+
|
146
|
+
while (next != NULL) {
|
147
|
+
req = next;
|
148
|
+
next = req->next_req != first ? req->next_req : NULL;
|
149
|
+
|
150
|
+
switch (req->type) {
|
151
|
+
case UV_READ:
|
152
|
+
DELEGATE_STREAM_REQ(loop, req, read, data);
|
153
|
+
break;
|
154
|
+
|
155
|
+
case UV_WRITE:
|
156
|
+
DELEGATE_STREAM_REQ(loop, (uv_write_t*) req, write, handle);
|
157
|
+
break;
|
158
|
+
|
159
|
+
case UV_ACCEPT:
|
160
|
+
DELEGATE_STREAM_REQ(loop, req, accept, data);
|
161
|
+
break;
|
162
|
+
|
163
|
+
case UV_CONNECT:
|
164
|
+
DELEGATE_STREAM_REQ(loop, (uv_connect_t*) req, connect, handle);
|
165
|
+
break;
|
166
|
+
|
167
|
+
case UV_SHUTDOWN:
|
168
|
+
/* Tcp shutdown requests don't come here. */
|
169
|
+
assert(((uv_shutdown_t*) req)->handle->type == UV_NAMED_PIPE);
|
170
|
+
uv_process_pipe_shutdown_req(
|
171
|
+
loop,
|
172
|
+
(uv_pipe_t*) ((uv_shutdown_t*) req)->handle,
|
173
|
+
(uv_shutdown_t*) req);
|
174
|
+
break;
|
175
|
+
|
176
|
+
case UV_UDP_RECV:
|
177
|
+
uv_process_udp_recv_req(loop, (uv_udp_t*) req->data, req);
|
178
|
+
break;
|
179
|
+
|
180
|
+
case UV_UDP_SEND:
|
181
|
+
uv_process_udp_send_req(loop,
|
182
|
+
((uv_udp_send_t*) req)->handle,
|
183
|
+
(uv_udp_send_t*) req);
|
184
|
+
break;
|
185
|
+
|
186
|
+
case UV_WAKEUP:
|
187
|
+
uv_process_async_wakeup_req(loop, (uv_async_t*) req->data, req);
|
188
|
+
break;
|
189
|
+
|
190
|
+
case UV_SIGNAL_REQ:
|
191
|
+
uv_process_signal_req(loop, (uv_signal_t*) req->data, req);
|
192
|
+
break;
|
193
|
+
|
194
|
+
case UV_POLL_REQ:
|
195
|
+
uv_process_poll_req(loop, (uv_poll_t*) req->data, req);
|
196
|
+
break;
|
197
|
+
|
198
|
+
case UV_GETADDRINFO:
|
199
|
+
uv_process_getaddrinfo_req(loop, (uv_getaddrinfo_t*) req);
|
200
|
+
break;
|
201
|
+
|
202
|
+
case UV_PROCESS_EXIT:
|
203
|
+
uv_process_proc_exit(loop, (uv_process_t*) req->data);
|
204
|
+
break;
|
205
|
+
|
206
|
+
case UV_FS:
|
207
|
+
uv_process_fs_req(loop, (uv_fs_t*) req);
|
208
|
+
break;
|
209
|
+
|
210
|
+
case UV_WORK:
|
211
|
+
uv_process_work_req(loop, (uv_work_t*) req);
|
212
|
+
break;
|
213
|
+
|
214
|
+
case UV_FS_EVENT_REQ:
|
215
|
+
uv_process_fs_event_req(loop, req, (uv_fs_event_t*) req->data);
|
216
|
+
break;
|
217
|
+
|
218
|
+
default:
|
219
|
+
assert(0);
|
220
|
+
}
|
221
|
+
}
|
222
|
+
}
|
223
|
+
|
224
|
+
#endif /* UV_WIN_REQ_INL_H_ */
|
@@ -0,0 +1,25 @@
|
|
1
|
+
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
2
|
+
*
|
3
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
* of this software and associated documentation files (the "Software"), to
|
5
|
+
* deal in the Software without restriction, including without limitation the
|
6
|
+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
7
|
+
* sell copies of the Software, and to permit persons to whom the Software is
|
8
|
+
* furnished to do so, subject to the following conditions:
|
9
|
+
*
|
10
|
+
* The above copyright notice and this permission notice shall be included in
|
11
|
+
* all copies or substantial portions of the Software.
|
12
|
+
*
|
13
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
18
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
19
|
+
* IN THE SOFTWARE.
|
20
|
+
*/
|
21
|
+
|
22
|
+
#include <assert.h>
|
23
|
+
|
24
|
+
#include "uv.h"
|
25
|
+
#include "internal.h"
|
@@ -0,0 +1,354 @@
|
|
1
|
+
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
2
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
3
|
+
* of this software and associated documentation files (the "Software"), to
|
4
|
+
* deal in the Software without restriction, including without limitation the
|
5
|
+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
6
|
+
* sell copies of the Software, and to permit persons to whom the Software is
|
7
|
+
* furnished to do so, subject to the following conditions:
|
8
|
+
*
|
9
|
+
* The above copyright notice and this permission notice shall be included in
|
10
|
+
* all copies or substantial portions of the Software.
|
11
|
+
*
|
12
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
13
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
14
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
15
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
16
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
17
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
18
|
+
* IN THE SOFTWARE.
|
19
|
+
*/
|
20
|
+
|
21
|
+
#include <assert.h>
|
22
|
+
#include <signal.h>
|
23
|
+
|
24
|
+
#include "uv.h"
|
25
|
+
#include "internal.h"
|
26
|
+
#include "handle-inl.h"
|
27
|
+
#include "req-inl.h"
|
28
|
+
|
29
|
+
|
30
|
+
RB_HEAD(uv_signal_tree_s, uv_signal_s);
|
31
|
+
|
32
|
+
static struct uv_signal_tree_s uv__signal_tree = RB_INITIALIZER(uv__signal_tree);
|
33
|
+
static ssize_t volatile uv__signal_control_handler_refs = 0;
|
34
|
+
static CRITICAL_SECTION uv__signal_lock;
|
35
|
+
|
36
|
+
|
37
|
+
void uv_signals_init() {
|
38
|
+
InitializeCriticalSection(&uv__signal_lock);
|
39
|
+
}
|
40
|
+
|
41
|
+
|
42
|
+
static int uv__signal_compare(uv_signal_t* w1, uv_signal_t* w2) {
|
43
|
+
/* Compare signums first so all watchers with the same signnum end up */
|
44
|
+
/* adjacent. */
|
45
|
+
if (w1->signum < w2->signum) return -1;
|
46
|
+
if (w1->signum > w2->signum) return 1;
|
47
|
+
|
48
|
+
/* Sort by loop pointer, so we can easily look up the first item after */
|
49
|
+
/* { .signum = x, .loop = NULL } */
|
50
|
+
if ((uintptr_t) w1->loop < (uintptr_t) w2->loop) return -1;
|
51
|
+
if ((uintptr_t) w1->loop > (uintptr_t) w2->loop) return 1;
|
52
|
+
|
53
|
+
if ((uintptr_t) w1 < (uintptr_t) w2) return -1;
|
54
|
+
if ((uintptr_t) w1 > (uintptr_t) w2) return 1;
|
55
|
+
|
56
|
+
return 0;
|
57
|
+
}
|
58
|
+
|
59
|
+
|
60
|
+
RB_GENERATE_STATIC(uv_signal_tree_s, uv_signal_s, tree_entry, uv__signal_compare);
|
61
|
+
|
62
|
+
|
63
|
+
/*
|
64
|
+
* Dispatches signal {signum} to all active uv_signal_t watchers in all loops.
|
65
|
+
* Returns 1 if the signal was dispatched to any watcher, or 0 if there were
|
66
|
+
* no active signal watchers observing this signal.
|
67
|
+
*/
|
68
|
+
int uv__signal_dispatch(int signum) {
|
69
|
+
uv_signal_t lookup;
|
70
|
+
uv_signal_t* handle;
|
71
|
+
int dispatched = 0;
|
72
|
+
|
73
|
+
EnterCriticalSection(&uv__signal_lock);
|
74
|
+
|
75
|
+
lookup.signum = signum;
|
76
|
+
lookup.loop = NULL;
|
77
|
+
|
78
|
+
for (handle = RB_NFIND(uv_signal_tree_s, &uv__signal_tree, &lookup);
|
79
|
+
handle != NULL && handle->signum == signum;
|
80
|
+
handle = RB_NEXT(uv_signal_tree_s, &uv__signal_tree, handle)) {
|
81
|
+
unsigned long previous = InterlockedExchange(&handle->pending_signum, signum);
|
82
|
+
|
83
|
+
if (!previous) {
|
84
|
+
POST_COMPLETION_FOR_REQ(handle->loop, &handle->signal_req);
|
85
|
+
}
|
86
|
+
|
87
|
+
dispatched = 1;
|
88
|
+
}
|
89
|
+
|
90
|
+
LeaveCriticalSection(&uv__signal_lock);
|
91
|
+
|
92
|
+
return dispatched;
|
93
|
+
}
|
94
|
+
|
95
|
+
|
96
|
+
static BOOL WINAPI uv__signal_control_handler(DWORD type) {
|
97
|
+
switch (type) {
|
98
|
+
case CTRL_C_EVENT:
|
99
|
+
return uv__signal_dispatch(SIGINT);
|
100
|
+
|
101
|
+
case CTRL_BREAK_EVENT:
|
102
|
+
return uv__signal_dispatch(SIGBREAK);
|
103
|
+
|
104
|
+
case CTRL_CLOSE_EVENT:
|
105
|
+
if (uv__signal_dispatch(SIGHUP)) {
|
106
|
+
/* Windows will terminate the process after the control handler */
|
107
|
+
/* returns. After that it will just terminate our process. Therefore */
|
108
|
+
/* block the signal handler so the main loop has some time to pick */
|
109
|
+
/* up the signal and do something for a few seconds. */
|
110
|
+
Sleep(INFINITE);
|
111
|
+
return TRUE;
|
112
|
+
}
|
113
|
+
return FALSE;
|
114
|
+
|
115
|
+
case CTRL_LOGOFF_EVENT:
|
116
|
+
case CTRL_SHUTDOWN_EVENT:
|
117
|
+
/* These signals are only sent to services. Services have their own */
|
118
|
+
/* notification mechanism, so there's no point in handling these. */
|
119
|
+
|
120
|
+
default:
|
121
|
+
/* We don't handle these. */
|
122
|
+
return FALSE;
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
126
|
+
|
127
|
+
static uv_err_t uv__signal_register_control_handler() {
|
128
|
+
/* When this function is called, the uv__signal_lock must be held. */
|
129
|
+
|
130
|
+
/* If the console control handler has already been hooked, just add a */
|
131
|
+
/* reference. */
|
132
|
+
if (uv__signal_control_handler_refs > 0)
|
133
|
+
return uv_ok_;
|
134
|
+
|
135
|
+
if (!SetConsoleCtrlHandler(uv__signal_control_handler, TRUE))
|
136
|
+
return uv__new_sys_error(GetLastError());
|
137
|
+
|
138
|
+
uv__signal_control_handler_refs++;
|
139
|
+
|
140
|
+
return uv_ok_;
|
141
|
+
}
|
142
|
+
|
143
|
+
|
144
|
+
static void uv__signal_unregister_control_handler() {
|
145
|
+
/* When this function is called, the uv__signal_lock must be held. */
|
146
|
+
BOOL r;
|
147
|
+
|
148
|
+
/* Don't unregister if the number of console control handlers exceeds one. */
|
149
|
+
/* Just remove a reference in that case. */
|
150
|
+
if (uv__signal_control_handler_refs > 1) {
|
151
|
+
uv__signal_control_handler_refs--;
|
152
|
+
return;
|
153
|
+
}
|
154
|
+
|
155
|
+
assert(uv__signal_control_handler_refs == 1);
|
156
|
+
|
157
|
+
r = SetConsoleCtrlHandler(uv__signal_control_handler, FALSE);
|
158
|
+
/* This should never fail; if it does it is probably a bug in libuv. */
|
159
|
+
assert(r);
|
160
|
+
|
161
|
+
uv__signal_control_handler_refs--;
|
162
|
+
}
|
163
|
+
|
164
|
+
|
165
|
+
static uv_err_t uv__signal_register(int signum) {
|
166
|
+
switch (signum) {
|
167
|
+
case SIGINT:
|
168
|
+
case SIGBREAK:
|
169
|
+
case SIGHUP:
|
170
|
+
return uv__signal_register_control_handler();
|
171
|
+
|
172
|
+
case SIGWINCH:
|
173
|
+
/* SIGWINCH is generated in tty.c. No need to register anything. */
|
174
|
+
return uv_ok_;
|
175
|
+
|
176
|
+
case SIGILL:
|
177
|
+
case SIGABRT_COMPAT:
|
178
|
+
case SIGFPE:
|
179
|
+
case SIGSEGV:
|
180
|
+
case SIGTERM:
|
181
|
+
case SIGABRT:
|
182
|
+
/* Signal is never raised. */
|
183
|
+
return uv_ok_;
|
184
|
+
|
185
|
+
default:
|
186
|
+
/* Invalid signal. */
|
187
|
+
return uv__new_artificial_error(UV_EINVAL);
|
188
|
+
}
|
189
|
+
}
|
190
|
+
|
191
|
+
|
192
|
+
static void uv__signal_unregister(int signum) {
|
193
|
+
switch (signum) {
|
194
|
+
case SIGINT:
|
195
|
+
case SIGBREAK:
|
196
|
+
case SIGHUP:
|
197
|
+
uv__signal_unregister_control_handler();
|
198
|
+
return;
|
199
|
+
|
200
|
+
case SIGWINCH:
|
201
|
+
/* SIGWINCH is generated in tty.c. No need to unregister anything. */
|
202
|
+
return;
|
203
|
+
|
204
|
+
case SIGILL:
|
205
|
+
case SIGABRT_COMPAT:
|
206
|
+
case SIGFPE:
|
207
|
+
case SIGSEGV:
|
208
|
+
case SIGTERM:
|
209
|
+
case SIGABRT:
|
210
|
+
/* Nothing is registered for this signal. */
|
211
|
+
return;
|
212
|
+
|
213
|
+
default:
|
214
|
+
/* Libuv bug. */
|
215
|
+
assert(0 && "Invalid signum");
|
216
|
+
return;
|
217
|
+
}
|
218
|
+
}
|
219
|
+
|
220
|
+
|
221
|
+
int uv_signal_init(uv_loop_t* loop, uv_signal_t* handle) {
|
222
|
+
uv_req_t* req;
|
223
|
+
|
224
|
+
uv__handle_init(loop, (uv_handle_t*) handle, UV_SIGNAL);
|
225
|
+
handle->pending_signum = 0;
|
226
|
+
handle->signum = 0;
|
227
|
+
handle->signal_cb = NULL;
|
228
|
+
|
229
|
+
req = &handle->signal_req;
|
230
|
+
uv_req_init(loop, req);
|
231
|
+
req->type = UV_SIGNAL_REQ;
|
232
|
+
req->data = handle;
|
233
|
+
|
234
|
+
return 0;
|
235
|
+
}
|
236
|
+
|
237
|
+
|
238
|
+
int uv_signal_stop(uv_signal_t* handle) {
|
239
|
+
uv_signal_t* removed_handle;
|
240
|
+
|
241
|
+
/* If the watcher wasn't started, this is a no-op. */
|
242
|
+
if (handle->signum == 0)
|
243
|
+
return 0;
|
244
|
+
|
245
|
+
EnterCriticalSection(&uv__signal_lock);
|
246
|
+
|
247
|
+
uv__signal_unregister(handle->signum);
|
248
|
+
|
249
|
+
removed_handle = RB_REMOVE(uv_signal_tree_s, &uv__signal_tree, handle);
|
250
|
+
assert(removed_handle == handle);
|
251
|
+
|
252
|
+
LeaveCriticalSection(&uv__signal_lock);
|
253
|
+
|
254
|
+
handle->signum = 0;
|
255
|
+
uv__handle_stop(handle);
|
256
|
+
|
257
|
+
return 0;
|
258
|
+
}
|
259
|
+
|
260
|
+
|
261
|
+
int uv_signal_start(uv_signal_t* handle, uv_signal_cb signal_cb, int signum) {
|
262
|
+
uv_err_t err;
|
263
|
+
|
264
|
+
/* If the user supplies signum == 0, then return an error already. If the */
|
265
|
+
/* signum is otherwise invalid then uv__signal_register will find out */
|
266
|
+
/* eventually. */
|
267
|
+
if (signum == 0) {
|
268
|
+
uv__set_artificial_error(handle->loop, UV_EINVAL);
|
269
|
+
return -1;
|
270
|
+
}
|
271
|
+
|
272
|
+
/* Short circuit: if the signal watcher is already watching {signum} don't */
|
273
|
+
/* go through the process of deregistering and registering the handler. */
|
274
|
+
/* Additionally, this avoids pending signals getting lost in the (small) */
|
275
|
+
/* time frame that handle->signum == 0. */
|
276
|
+
if (signum == handle->signum) {
|
277
|
+
handle->signal_cb = signal_cb;
|
278
|
+
return 0;
|
279
|
+
}
|
280
|
+
|
281
|
+
/* If the signal handler was already active, stop it first. */
|
282
|
+
if (handle->signum != 0) {
|
283
|
+
int r = uv_signal_stop(handle);
|
284
|
+
/* uv_signal_stop is infallible. */
|
285
|
+
assert(r == 0);
|
286
|
+
}
|
287
|
+
|
288
|
+
EnterCriticalSection(&uv__signal_lock);
|
289
|
+
|
290
|
+
err = uv__signal_register(signum);
|
291
|
+
if (err.code != UV_OK) {
|
292
|
+
/* Uh-oh, didn't work. */
|
293
|
+
handle->loop->last_err = err;
|
294
|
+
LeaveCriticalSection(&uv__signal_lock);
|
295
|
+
return -1;
|
296
|
+
}
|
297
|
+
|
298
|
+
handle->signum = signum;
|
299
|
+
RB_INSERT(uv_signal_tree_s, &uv__signal_tree, handle);
|
300
|
+
|
301
|
+
LeaveCriticalSection(&uv__signal_lock);
|
302
|
+
|
303
|
+
handle->signal_cb = signal_cb;
|
304
|
+
uv__handle_start(handle);
|
305
|
+
|
306
|
+
return 0;
|
307
|
+
}
|
308
|
+
|
309
|
+
|
310
|
+
void uv_process_signal_req(uv_loop_t* loop, uv_signal_t* handle,
|
311
|
+
uv_req_t* req) {
|
312
|
+
unsigned long dispatched_signum;
|
313
|
+
|
314
|
+
assert(handle->type == UV_SIGNAL);
|
315
|
+
assert(req->type == UV_SIGNAL_REQ);
|
316
|
+
|
317
|
+
dispatched_signum = InterlockedExchange(&handle->pending_signum, 0);
|
318
|
+
assert(dispatched_signum != 0);
|
319
|
+
|
320
|
+
/* Check if the pending signal equals the signum that we are watching for. */
|
321
|
+
/* These can get out of sync when the handler is stopped and restarted */
|
322
|
+
/* while the signal_req is pending. */
|
323
|
+
if (dispatched_signum == handle->signum)
|
324
|
+
handle->signal_cb(handle, dispatched_signum);
|
325
|
+
|
326
|
+
if (handle->flags & UV__HANDLE_CLOSING) {
|
327
|
+
/* When it is closing, it must be stopped at this point. */
|
328
|
+
assert(handle->signum == 0);
|
329
|
+
uv_want_endgame(loop, (uv_handle_t*) handle);
|
330
|
+
}
|
331
|
+
}
|
332
|
+
|
333
|
+
|
334
|
+
void uv_signal_close(uv_loop_t* loop, uv_signal_t* handle) {
|
335
|
+
uv_signal_stop(handle);
|
336
|
+
uv__handle_closing(handle);
|
337
|
+
|
338
|
+
if (handle->pending_signum == 0) {
|
339
|
+
uv_want_endgame(loop, (uv_handle_t*) handle);
|
340
|
+
}
|
341
|
+
}
|
342
|
+
|
343
|
+
|
344
|
+
void uv_signal_endgame(uv_loop_t* loop, uv_signal_t* handle) {
|
345
|
+
assert(handle->flags & UV__HANDLE_CLOSING);
|
346
|
+
assert(!(handle->flags & UV_HANDLE_CLOSED));
|
347
|
+
|
348
|
+
assert(handle->signum == 0);
|
349
|
+
assert(handle->pending_signum == 0);
|
350
|
+
|
351
|
+
handle->flags |= UV_HANDLE_CLOSED;
|
352
|
+
|
353
|
+
uv__handle_close(handle);
|
354
|
+
}
|
@@ -0,0 +1,67 @@
|
|
1
|
+
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
2
|
+
*
|
3
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
* of this software and associated documentation files (the "Software"), to
|
5
|
+
* deal in the Software without restriction, including without limitation the
|
6
|
+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
7
|
+
* sell copies of the Software, and to permit persons to whom the Software is
|
8
|
+
* furnished to do so, subject to the following conditions:
|
9
|
+
*
|
10
|
+
* The above copyright notice and this permission notice shall be included in
|
11
|
+
* all copies or substantial portions of the Software.
|
12
|
+
*
|
13
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
18
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
19
|
+
* IN THE SOFTWARE.
|
20
|
+
*/
|
21
|
+
|
22
|
+
#ifndef UV_WIN_STREAM_INL_H_
|
23
|
+
#define UV_WIN_STREAM_INL_H_
|
24
|
+
|
25
|
+
#include <assert.h>
|
26
|
+
|
27
|
+
#include "uv.h"
|
28
|
+
#include "internal.h"
|
29
|
+
#include "handle-inl.h"
|
30
|
+
#include "req-inl.h"
|
31
|
+
|
32
|
+
|
33
|
+
INLINE static void uv_stream_init(uv_loop_t* loop,
|
34
|
+
uv_stream_t* handle,
|
35
|
+
uv_handle_type type) {
|
36
|
+
uv__handle_init(loop, (uv_handle_t*) handle, type);
|
37
|
+
handle->write_queue_size = 0;
|
38
|
+
handle->activecnt = 0;
|
39
|
+
}
|
40
|
+
|
41
|
+
|
42
|
+
INLINE static void uv_connection_init(uv_stream_t* handle) {
|
43
|
+
handle->flags |= UV_HANDLE_CONNECTION;
|
44
|
+
handle->write_reqs_pending = 0;
|
45
|
+
|
46
|
+
uv_req_init(handle->loop, (uv_req_t*) &(handle->read_req));
|
47
|
+
handle->read_req.event_handle = NULL;
|
48
|
+
handle->read_req.wait_handle = INVALID_HANDLE_VALUE;
|
49
|
+
handle->read_req.type = UV_READ;
|
50
|
+
handle->read_req.data = handle;
|
51
|
+
|
52
|
+
handle->shutdown_req = NULL;
|
53
|
+
}
|
54
|
+
|
55
|
+
|
56
|
+
INLINE static size_t uv_count_bufs(uv_buf_t bufs[], int count) {
|
57
|
+
size_t bytes = 0;
|
58
|
+
int i;
|
59
|
+
|
60
|
+
for (i = 0; i < count; i++) {
|
61
|
+
bytes += (size_t)bufs[i].len;
|
62
|
+
}
|
63
|
+
|
64
|
+
return bytes;
|
65
|
+
}
|
66
|
+
|
67
|
+
#endif /* UV_WIN_STREAM_INL_H_ */
|