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,99 @@
|
|
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"
|
26
|
+
#include "atomicops-inl.h"
|
27
|
+
#include "handle-inl.h"
|
28
|
+
#include "req-inl.h"
|
29
|
+
|
30
|
+
|
31
|
+
void uv_async_endgame(uv_loop_t* loop, uv_async_t* handle) {
|
32
|
+
if (handle->flags & UV__HANDLE_CLOSING &&
|
33
|
+
!handle->async_sent) {
|
34
|
+
assert(!(handle->flags & UV_HANDLE_CLOSED));
|
35
|
+
uv__handle_close(handle);
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
|
40
|
+
int uv_async_init(uv_loop_t* loop, uv_async_t* handle, uv_async_cb async_cb) {
|
41
|
+
uv_req_t* req;
|
42
|
+
|
43
|
+
uv__handle_init(loop, (uv_handle_t*) handle, UV_ASYNC);
|
44
|
+
handle->async_sent = 0;
|
45
|
+
handle->async_cb = async_cb;
|
46
|
+
|
47
|
+
req = &handle->async_req;
|
48
|
+
uv_req_init(loop, req);
|
49
|
+
req->type = UV_WAKEUP;
|
50
|
+
req->data = handle;
|
51
|
+
|
52
|
+
uv__handle_start(handle);
|
53
|
+
|
54
|
+
return 0;
|
55
|
+
}
|
56
|
+
|
57
|
+
|
58
|
+
void uv_async_close(uv_loop_t* loop, uv_async_t* handle) {
|
59
|
+
if (!((uv_async_t*)handle)->async_sent) {
|
60
|
+
uv_want_endgame(loop, (uv_handle_t*) handle);
|
61
|
+
}
|
62
|
+
|
63
|
+
uv__handle_closing(handle);
|
64
|
+
}
|
65
|
+
|
66
|
+
|
67
|
+
int uv_async_send(uv_async_t* handle) {
|
68
|
+
uv_loop_t* loop = handle->loop;
|
69
|
+
|
70
|
+
if (handle->type != UV_ASYNC) {
|
71
|
+
/* Can't set errno because that's not thread-safe. */
|
72
|
+
return -1;
|
73
|
+
}
|
74
|
+
|
75
|
+
/* The user should make sure never to call uv_async_send to a closing */
|
76
|
+
/* or closed handle. */
|
77
|
+
assert(!(handle->flags & UV__HANDLE_CLOSING));
|
78
|
+
|
79
|
+
if (!uv__atomic_exchange_set(&handle->async_sent)) {
|
80
|
+
POST_COMPLETION_FOR_REQ(loop, &handle->async_req);
|
81
|
+
}
|
82
|
+
|
83
|
+
return 0;
|
84
|
+
}
|
85
|
+
|
86
|
+
|
87
|
+
void uv_process_async_wakeup_req(uv_loop_t* loop, uv_async_t* handle,
|
88
|
+
uv_req_t* req) {
|
89
|
+
assert(handle->type == UV_ASYNC);
|
90
|
+
assert(req->type == UV_WAKEUP);
|
91
|
+
|
92
|
+
handle->async_sent = 0;
|
93
|
+
|
94
|
+
if (!(handle->flags & UV__HANDLE_CLOSING)) {
|
95
|
+
handle->async_cb((uv_async_t*) handle, 0);
|
96
|
+
} else {
|
97
|
+
uv_want_endgame(loop, (uv_handle_t*)handle);
|
98
|
+
}
|
99
|
+
}
|
@@ -0,0 +1,56 @@
|
|
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_ATOMICOPS_INL_H_
|
23
|
+
#define UV_WIN_ATOMICOPS_INL_H_
|
24
|
+
|
25
|
+
#include "uv.h"
|
26
|
+
|
27
|
+
|
28
|
+
/* Atomic set operation on char */
|
29
|
+
#ifdef _MSC_VER /* MSVC */
|
30
|
+
|
31
|
+
/* _InterlockedOr8 is supported by MSVC on x32 and x64. It is slightly less */
|
32
|
+
/* efficient than InterlockedExchange, but InterlockedExchange8 does not */
|
33
|
+
/* exist, and interlocked operations on larger targets might require the */
|
34
|
+
/* target to be aligned. */
|
35
|
+
#pragma intrinsic(_InterlockedOr8)
|
36
|
+
|
37
|
+
static char __declspec(inline) uv__atomic_exchange_set(char volatile* target) {
|
38
|
+
return _InterlockedOr8(target, 1);
|
39
|
+
}
|
40
|
+
|
41
|
+
#else /* GCC */
|
42
|
+
|
43
|
+
/* Mingw-32 version, hopefully this works for 64-bit gcc as well. */
|
44
|
+
static inline char uv__atomic_exchange_set(char volatile* target) {
|
45
|
+
const char one = 1;
|
46
|
+
char old_value;
|
47
|
+
__asm__ __volatile__ ("lock xchgb %0, %1\n\t"
|
48
|
+
: "=r"(old_value), "=m"(*target)
|
49
|
+
: "0"(one), "m"(*target)
|
50
|
+
: "memory");
|
51
|
+
return old_value;
|
52
|
+
}
|
53
|
+
|
54
|
+
#endif
|
55
|
+
|
56
|
+
#endif /* UV_WIN_ATOMICOPS_INL_H_ */
|
@@ -0,0 +1,310 @@
|
|
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
|
+
#include <errno.h>
|
24
|
+
#include <limits.h>
|
25
|
+
#include <malloc.h>
|
26
|
+
#include <stdio.h>
|
27
|
+
#include <stdlib.h>
|
28
|
+
#include <string.h>
|
29
|
+
|
30
|
+
#include "uv.h"
|
31
|
+
#include "internal.h"
|
32
|
+
#include "handle-inl.h"
|
33
|
+
#include "req-inl.h"
|
34
|
+
|
35
|
+
|
36
|
+
/* The only event loop we support right now */
|
37
|
+
static uv_loop_t uv_default_loop_;
|
38
|
+
|
39
|
+
/* uv_once intialization guards */
|
40
|
+
static uv_once_t uv_init_guard_ = UV_ONCE_INIT;
|
41
|
+
static uv_once_t uv_default_loop_init_guard_ = UV_ONCE_INIT;
|
42
|
+
|
43
|
+
|
44
|
+
static void uv__crt_invalid_parameter_handler(const wchar_t* expression,
|
45
|
+
const wchar_t* function, const wchar_t * file, unsigned int line,
|
46
|
+
uintptr_t reserved) {
|
47
|
+
/* No-op. */
|
48
|
+
}
|
49
|
+
|
50
|
+
|
51
|
+
static void uv_init(void) {
|
52
|
+
/* Tell Windows that we will handle critical errors. */
|
53
|
+
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX |
|
54
|
+
SEM_NOOPENFILEERRORBOX);
|
55
|
+
|
56
|
+
/* Tell the CRT to not exit the application when an invalid parameter is */
|
57
|
+
/* passed. The main issue is that invalid FDs will trigger this behavior. */
|
58
|
+
#ifdef _WRITE_ABORT_MSG
|
59
|
+
_set_invalid_parameter_handler(uv__crt_invalid_parameter_handler);
|
60
|
+
#endif
|
61
|
+
|
62
|
+
/* Fetch winapi function pointers. This must be done first because other */
|
63
|
+
/* intialization code might need these function pointers to be loaded. */
|
64
|
+
uv_winapi_init();
|
65
|
+
|
66
|
+
/* Initialize winsock */
|
67
|
+
uv_winsock_init();
|
68
|
+
|
69
|
+
/* Initialize FS */
|
70
|
+
uv_fs_init();
|
71
|
+
|
72
|
+
/* Initialize signal stuff */
|
73
|
+
uv_signals_init();
|
74
|
+
|
75
|
+
/* Initialize console */
|
76
|
+
uv_console_init();
|
77
|
+
|
78
|
+
/* Initialize utilities */
|
79
|
+
uv__util_init();
|
80
|
+
}
|
81
|
+
|
82
|
+
|
83
|
+
static void uv_loop_init(uv_loop_t* loop) {
|
84
|
+
/* Create an I/O completion port */
|
85
|
+
loop->iocp = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 1);
|
86
|
+
if (loop->iocp == NULL) {
|
87
|
+
uv_fatal_error(GetLastError(), "CreateIoCompletionPort");
|
88
|
+
}
|
89
|
+
|
90
|
+
/* To prevent uninitialized memory access, loop->time must be intialized */
|
91
|
+
/* to zero before calling uv_update_time for the first time. */
|
92
|
+
loop->time = 0;
|
93
|
+
uv_update_time(loop);
|
94
|
+
|
95
|
+
ngx_queue_init(&loop->handle_queue);
|
96
|
+
ngx_queue_init(&loop->active_reqs);
|
97
|
+
loop->active_handles = 0;
|
98
|
+
|
99
|
+
loop->pending_reqs_tail = NULL;
|
100
|
+
|
101
|
+
loop->endgame_handles = NULL;
|
102
|
+
|
103
|
+
RB_INIT(&loop->timers);
|
104
|
+
|
105
|
+
loop->check_handles = NULL;
|
106
|
+
loop->prepare_handles = NULL;
|
107
|
+
loop->idle_handles = NULL;
|
108
|
+
|
109
|
+
loop->next_prepare_handle = NULL;
|
110
|
+
loop->next_check_handle = NULL;
|
111
|
+
loop->next_idle_handle = NULL;
|
112
|
+
|
113
|
+
memset(&loop->poll_peer_sockets, 0, sizeof loop->poll_peer_sockets);
|
114
|
+
|
115
|
+
loop->active_tcp_streams = 0;
|
116
|
+
loop->active_udp_streams = 0;
|
117
|
+
|
118
|
+
loop->timer_counter = 0;
|
119
|
+
loop->stop_flag = 0;
|
120
|
+
|
121
|
+
loop->last_err = uv_ok_;
|
122
|
+
}
|
123
|
+
|
124
|
+
|
125
|
+
static void uv_default_loop_init(void) {
|
126
|
+
/* Initialize libuv itself first */
|
127
|
+
uv__once_init();
|
128
|
+
|
129
|
+
/* Initialize the main loop */
|
130
|
+
uv_loop_init(&uv_default_loop_);
|
131
|
+
}
|
132
|
+
|
133
|
+
|
134
|
+
void uv__once_init(void) {
|
135
|
+
uv_once(&uv_init_guard_, uv_init);
|
136
|
+
}
|
137
|
+
|
138
|
+
|
139
|
+
uv_loop_t* uv_default_loop(void) {
|
140
|
+
uv_once(&uv_default_loop_init_guard_, uv_default_loop_init);
|
141
|
+
return &uv_default_loop_;
|
142
|
+
}
|
143
|
+
|
144
|
+
|
145
|
+
uv_loop_t* uv_loop_new(void) {
|
146
|
+
uv_loop_t* loop;
|
147
|
+
|
148
|
+
/* Initialize libuv itself first */
|
149
|
+
uv__once_init();
|
150
|
+
|
151
|
+
loop = (uv_loop_t*)malloc(sizeof(uv_loop_t));
|
152
|
+
|
153
|
+
if (!loop) {
|
154
|
+
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
|
155
|
+
}
|
156
|
+
|
157
|
+
uv_loop_init(loop);
|
158
|
+
return loop;
|
159
|
+
}
|
160
|
+
|
161
|
+
|
162
|
+
void uv_loop_delete(uv_loop_t* loop) {
|
163
|
+
if (loop != &uv_default_loop_) {
|
164
|
+
int i;
|
165
|
+
for (i = 0; i < ARRAY_SIZE(loop->poll_peer_sockets); i++) {
|
166
|
+
SOCKET sock = loop->poll_peer_sockets[i];
|
167
|
+
if (sock != 0 && sock != INVALID_SOCKET) {
|
168
|
+
closesocket(sock);
|
169
|
+
}
|
170
|
+
}
|
171
|
+
|
172
|
+
free(loop);
|
173
|
+
}
|
174
|
+
}
|
175
|
+
|
176
|
+
|
177
|
+
int uv_backend_fd(const uv_loop_t* loop) {
|
178
|
+
return -1;
|
179
|
+
}
|
180
|
+
|
181
|
+
|
182
|
+
int uv_backend_timeout(const uv_loop_t* loop) {
|
183
|
+
return 0;
|
184
|
+
}
|
185
|
+
|
186
|
+
|
187
|
+
static void uv_poll(uv_loop_t* loop, int block) {
|
188
|
+
BOOL success;
|
189
|
+
DWORD bytes, timeout;
|
190
|
+
ULONG_PTR key;
|
191
|
+
OVERLAPPED* overlapped;
|
192
|
+
uv_req_t* req;
|
193
|
+
|
194
|
+
if (block) {
|
195
|
+
timeout = uv_get_poll_timeout(loop);
|
196
|
+
} else {
|
197
|
+
timeout = 0;
|
198
|
+
}
|
199
|
+
|
200
|
+
success = GetQueuedCompletionStatus(loop->iocp,
|
201
|
+
&bytes,
|
202
|
+
&key,
|
203
|
+
&overlapped,
|
204
|
+
timeout);
|
205
|
+
|
206
|
+
if (overlapped) {
|
207
|
+
/* Package was dequeued */
|
208
|
+
req = uv_overlapped_to_req(overlapped);
|
209
|
+
|
210
|
+
uv_insert_pending_req(loop, req);
|
211
|
+
|
212
|
+
} else if (GetLastError() != WAIT_TIMEOUT) {
|
213
|
+
/* Serious error */
|
214
|
+
uv_fatal_error(GetLastError(), "GetQueuedCompletionStatus");
|
215
|
+
}
|
216
|
+
}
|
217
|
+
|
218
|
+
|
219
|
+
static void uv_poll_ex(uv_loop_t* loop, int block) {
|
220
|
+
BOOL success;
|
221
|
+
DWORD timeout;
|
222
|
+
uv_req_t* req;
|
223
|
+
OVERLAPPED_ENTRY overlappeds[128];
|
224
|
+
ULONG count;
|
225
|
+
ULONG i;
|
226
|
+
|
227
|
+
if (block) {
|
228
|
+
timeout = uv_get_poll_timeout(loop);
|
229
|
+
} else {
|
230
|
+
timeout = 0;
|
231
|
+
}
|
232
|
+
|
233
|
+
assert(pGetQueuedCompletionStatusEx);
|
234
|
+
|
235
|
+
success = pGetQueuedCompletionStatusEx(loop->iocp,
|
236
|
+
overlappeds,
|
237
|
+
ARRAY_SIZE(overlappeds),
|
238
|
+
&count,
|
239
|
+
timeout,
|
240
|
+
FALSE);
|
241
|
+
if (success) {
|
242
|
+
for (i = 0; i < count; i++) {
|
243
|
+
/* Package was dequeued */
|
244
|
+
req = uv_overlapped_to_req(overlappeds[i].lpOverlapped);
|
245
|
+
uv_insert_pending_req(loop, req);
|
246
|
+
}
|
247
|
+
} else if (GetLastError() != WAIT_TIMEOUT) {
|
248
|
+
/* Serious error */
|
249
|
+
uv_fatal_error(GetLastError(), "GetQueuedCompletionStatusEx");
|
250
|
+
}
|
251
|
+
}
|
252
|
+
|
253
|
+
|
254
|
+
static int uv__loop_alive(uv_loop_t* loop) {
|
255
|
+
return loop->active_handles > 0 ||
|
256
|
+
!ngx_queue_empty(&loop->active_reqs) ||
|
257
|
+
loop->endgame_handles != NULL;
|
258
|
+
}
|
259
|
+
|
260
|
+
|
261
|
+
int uv_run(uv_loop_t *loop, uv_run_mode mode) {
|
262
|
+
int r;
|
263
|
+
void (*poll)(uv_loop_t* loop, int block);
|
264
|
+
|
265
|
+
if (pGetQueuedCompletionStatusEx)
|
266
|
+
poll = &uv_poll_ex;
|
267
|
+
else
|
268
|
+
poll = &uv_poll;
|
269
|
+
|
270
|
+
if (!uv__loop_alive(loop))
|
271
|
+
return 0;
|
272
|
+
|
273
|
+
r = uv__loop_alive(loop);
|
274
|
+
while (r != 0 && loop->stop_flag == 0) {
|
275
|
+
uv_update_time(loop);
|
276
|
+
uv_process_timers(loop);
|
277
|
+
|
278
|
+
/* Call idle callbacks if nothing to do. */
|
279
|
+
if (loop->pending_reqs_tail == NULL &&
|
280
|
+
loop->endgame_handles == NULL) {
|
281
|
+
uv_idle_invoke(loop);
|
282
|
+
}
|
283
|
+
|
284
|
+
uv_process_reqs(loop);
|
285
|
+
uv_process_endgames(loop);
|
286
|
+
|
287
|
+
uv_prepare_invoke(loop);
|
288
|
+
|
289
|
+
(*poll)(loop, loop->idle_handles == NULL &&
|
290
|
+
loop->pending_reqs_tail == NULL &&
|
291
|
+
loop->endgame_handles == NULL &&
|
292
|
+
!loop->stop_flag &&
|
293
|
+
(loop->active_handles > 0 ||
|
294
|
+
!ngx_queue_empty(&loop->active_reqs)) &&
|
295
|
+
!(mode & UV_RUN_NOWAIT));
|
296
|
+
|
297
|
+
uv_check_invoke(loop);
|
298
|
+
r = uv__loop_alive(loop);
|
299
|
+
if (mode & (UV_RUN_ONCE | UV_RUN_NOWAIT))
|
300
|
+
break;
|
301
|
+
}
|
302
|
+
|
303
|
+
/* The if statement lets the compiler compile it to a conditional store.
|
304
|
+
* Avoids dirtying a cache line.
|
305
|
+
*/
|
306
|
+
if (loop->stop_flag != 0)
|
307
|
+
loop->stop_flag = 0;
|
308
|
+
|
309
|
+
return r;
|
310
|
+
}
|
@@ -0,0 +1,86 @@
|
|
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 "uv.h"
|
23
|
+
#include "internal.h"
|
24
|
+
|
25
|
+
static int uv__dlerror(uv_lib_t* lib, int errorno);
|
26
|
+
|
27
|
+
|
28
|
+
int uv_dlopen(const char* filename, uv_lib_t* lib) {
|
29
|
+
WCHAR filename_w[32768];
|
30
|
+
|
31
|
+
lib->handle = NULL;
|
32
|
+
lib->errmsg = NULL;
|
33
|
+
|
34
|
+
if (!uv_utf8_to_utf16(filename, filename_w, ARRAY_SIZE(filename_w))) {
|
35
|
+
return uv__dlerror(lib, GetLastError());
|
36
|
+
}
|
37
|
+
|
38
|
+
lib->handle = LoadLibraryExW(filename_w, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
|
39
|
+
if (lib->handle == NULL) {
|
40
|
+
return uv__dlerror(lib, GetLastError());
|
41
|
+
}
|
42
|
+
|
43
|
+
return 0;
|
44
|
+
}
|
45
|
+
|
46
|
+
|
47
|
+
void uv_dlclose(uv_lib_t* lib) {
|
48
|
+
if (lib->errmsg) {
|
49
|
+
LocalFree((void*)lib->errmsg);
|
50
|
+
lib->errmsg = NULL;
|
51
|
+
}
|
52
|
+
|
53
|
+
if (lib->handle) {
|
54
|
+
/* Ignore errors. No good way to signal them without leaking memory. */
|
55
|
+
FreeLibrary(lib->handle);
|
56
|
+
lib->handle = NULL;
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
|
61
|
+
int uv_dlsym(uv_lib_t* lib, const char* name, void** ptr) {
|
62
|
+
*ptr = (void*) GetProcAddress(lib->handle, name);
|
63
|
+
return uv__dlerror(lib, *ptr ? 0 : GetLastError());
|
64
|
+
}
|
65
|
+
|
66
|
+
|
67
|
+
const char* uv_dlerror(uv_lib_t* lib) {
|
68
|
+
return lib->errmsg ? lib->errmsg : "no error";
|
69
|
+
}
|
70
|
+
|
71
|
+
|
72
|
+
static int uv__dlerror(uv_lib_t* lib, int errorno) {
|
73
|
+
if (lib->errmsg) {
|
74
|
+
LocalFree((void*)lib->errmsg);
|
75
|
+
lib->errmsg = NULL;
|
76
|
+
}
|
77
|
+
|
78
|
+
if (errorno) {
|
79
|
+
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
|
80
|
+
FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errorno,
|
81
|
+
MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
|
82
|
+
(LPSTR)&lib->errmsg, 0, NULL);
|
83
|
+
}
|
84
|
+
|
85
|
+
return errorno ? -1 : 0;
|
86
|
+
}
|