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,183 @@
|
|
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 "task.h"
|
24
|
+
|
25
|
+
#include <stdio.h>
|
26
|
+
#include <stdlib.h>
|
27
|
+
#include <string.h> /* memset */
|
28
|
+
|
29
|
+
struct getaddrinfo_req {
|
30
|
+
uv_thread_t thread_id;
|
31
|
+
unsigned int counter;
|
32
|
+
uv_loop_t* loop;
|
33
|
+
uv_getaddrinfo_t handle;
|
34
|
+
};
|
35
|
+
|
36
|
+
|
37
|
+
struct fs_req {
|
38
|
+
uv_thread_t thread_id;
|
39
|
+
unsigned int counter;
|
40
|
+
uv_loop_t* loop;
|
41
|
+
uv_fs_t handle;
|
42
|
+
};
|
43
|
+
|
44
|
+
|
45
|
+
struct test_thread {
|
46
|
+
uv_thread_t thread_id;
|
47
|
+
volatile int thread_called;
|
48
|
+
};
|
49
|
+
|
50
|
+
static void getaddrinfo_do(struct getaddrinfo_req* req);
|
51
|
+
static void getaddrinfo_cb(uv_getaddrinfo_t* handle,
|
52
|
+
int status,
|
53
|
+
struct addrinfo* res);
|
54
|
+
static void fs_do(struct fs_req* req);
|
55
|
+
static void fs_cb(uv_fs_t* handle);
|
56
|
+
|
57
|
+
static volatile int thread_called;
|
58
|
+
|
59
|
+
|
60
|
+
static void getaddrinfo_do(struct getaddrinfo_req* req) {
|
61
|
+
int r;
|
62
|
+
|
63
|
+
r = uv_getaddrinfo(req->loop,
|
64
|
+
&req->handle,
|
65
|
+
getaddrinfo_cb,
|
66
|
+
"localhost",
|
67
|
+
NULL,
|
68
|
+
NULL);
|
69
|
+
ASSERT(r == 0);
|
70
|
+
}
|
71
|
+
|
72
|
+
|
73
|
+
static void getaddrinfo_cb(uv_getaddrinfo_t* handle,
|
74
|
+
int status,
|
75
|
+
struct addrinfo* res) {
|
76
|
+
struct getaddrinfo_req* req;
|
77
|
+
|
78
|
+
ASSERT(status == 0);
|
79
|
+
|
80
|
+
req = container_of(handle, struct getaddrinfo_req, handle);
|
81
|
+
uv_freeaddrinfo(res);
|
82
|
+
|
83
|
+
if (--req->counter)
|
84
|
+
getaddrinfo_do(req);
|
85
|
+
}
|
86
|
+
|
87
|
+
|
88
|
+
static void fs_do(struct fs_req* req) {
|
89
|
+
int r;
|
90
|
+
|
91
|
+
r = uv_fs_stat(req->loop, &req->handle, ".", fs_cb);
|
92
|
+
ASSERT(r == 0);
|
93
|
+
}
|
94
|
+
|
95
|
+
|
96
|
+
static void fs_cb(uv_fs_t* handle) {
|
97
|
+
struct fs_req* req = container_of(handle, struct fs_req, handle);
|
98
|
+
|
99
|
+
uv_fs_req_cleanup(handle);
|
100
|
+
|
101
|
+
if (--req->counter)
|
102
|
+
fs_do(req);
|
103
|
+
}
|
104
|
+
|
105
|
+
|
106
|
+
static void do_work(void* arg) {
|
107
|
+
struct getaddrinfo_req getaddrinfo_reqs[16];
|
108
|
+
struct fs_req fs_reqs[16];
|
109
|
+
uv_loop_t* loop;
|
110
|
+
size_t i;
|
111
|
+
int r;
|
112
|
+
struct test_thread* thread = arg;
|
113
|
+
|
114
|
+
loop = uv_loop_new();
|
115
|
+
ASSERT(loop != NULL);
|
116
|
+
|
117
|
+
for (i = 0; i < ARRAY_SIZE(getaddrinfo_reqs); i++) {
|
118
|
+
struct getaddrinfo_req* req = getaddrinfo_reqs + i;
|
119
|
+
req->counter = 16;
|
120
|
+
req->loop = loop;
|
121
|
+
getaddrinfo_do(req);
|
122
|
+
}
|
123
|
+
|
124
|
+
for (i = 0; i < ARRAY_SIZE(fs_reqs); i++) {
|
125
|
+
struct fs_req* req = fs_reqs + i;
|
126
|
+
req->counter = 16;
|
127
|
+
req->loop = loop;
|
128
|
+
fs_do(req);
|
129
|
+
}
|
130
|
+
|
131
|
+
r = uv_run(loop, UV_RUN_DEFAULT);
|
132
|
+
ASSERT(r == 0);
|
133
|
+
|
134
|
+
uv_loop_delete(loop);
|
135
|
+
thread->thread_called = 1;
|
136
|
+
}
|
137
|
+
|
138
|
+
|
139
|
+
static void thread_entry(void* arg) {
|
140
|
+
ASSERT(arg == (void *) 42);
|
141
|
+
thread_called++;
|
142
|
+
}
|
143
|
+
|
144
|
+
|
145
|
+
TEST_IMPL(thread_create) {
|
146
|
+
uv_thread_t tid;
|
147
|
+
int r;
|
148
|
+
|
149
|
+
r = uv_thread_create(&tid, thread_entry, (void *) 42);
|
150
|
+
ASSERT(r == 0);
|
151
|
+
|
152
|
+
r = uv_thread_join(&tid);
|
153
|
+
ASSERT(r == 0);
|
154
|
+
|
155
|
+
ASSERT(thread_called == 1);
|
156
|
+
|
157
|
+
return 0;
|
158
|
+
}
|
159
|
+
|
160
|
+
|
161
|
+
/* Hilariously bad test name. Run a lot of tasks in the thread pool and verify
|
162
|
+
* that each "finished" callback is run in its originating thread.
|
163
|
+
*/
|
164
|
+
TEST_IMPL(threadpool_multiple_event_loops) {
|
165
|
+
struct test_thread threads[8];
|
166
|
+
size_t i;
|
167
|
+
int r;
|
168
|
+
|
169
|
+
memset(threads, 0, sizeof(threads));
|
170
|
+
|
171
|
+
for (i = 0; i < ARRAY_SIZE(threads); i++) {
|
172
|
+
r = uv_thread_create(&threads[i].thread_id, do_work, &threads[i]);
|
173
|
+
ASSERT(r == 0);
|
174
|
+
}
|
175
|
+
|
176
|
+
for (i = 0; i < ARRAY_SIZE(threads); i++) {
|
177
|
+
r = uv_thread_join(&threads[i].thread_id);
|
178
|
+
ASSERT(r == 0);
|
179
|
+
ASSERT(threads[i].thread_called);
|
180
|
+
}
|
181
|
+
|
182
|
+
return 0;
|
183
|
+
}
|
@@ -0,0 +1,311 @@
|
|
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 "task.h"
|
24
|
+
|
25
|
+
#define INIT_CANCEL_INFO(ci, what) \
|
26
|
+
do { \
|
27
|
+
(ci)->reqs = (what); \
|
28
|
+
(ci)->nreqs = ARRAY_SIZE(what); \
|
29
|
+
(ci)->stride = sizeof((what)[0]); \
|
30
|
+
} \
|
31
|
+
while (0)
|
32
|
+
|
33
|
+
struct cancel_info {
|
34
|
+
void* reqs;
|
35
|
+
unsigned nreqs;
|
36
|
+
unsigned stride;
|
37
|
+
uv_timer_t timer_handle;
|
38
|
+
};
|
39
|
+
|
40
|
+
static uv_cond_t signal_cond;
|
41
|
+
static uv_mutex_t signal_mutex;
|
42
|
+
static uv_mutex_t wait_mutex;
|
43
|
+
static unsigned num_threads;
|
44
|
+
static unsigned fs_cb_called;
|
45
|
+
static unsigned work_cb_called;
|
46
|
+
static unsigned done_cb_called;
|
47
|
+
static unsigned done2_cb_called;
|
48
|
+
static unsigned timer_cb_called;
|
49
|
+
static unsigned getaddrinfo_cb_called;
|
50
|
+
|
51
|
+
|
52
|
+
static void work_cb(uv_work_t* req) {
|
53
|
+
uv_mutex_lock(&signal_mutex);
|
54
|
+
uv_cond_signal(&signal_cond);
|
55
|
+
uv_mutex_unlock(&signal_mutex);
|
56
|
+
|
57
|
+
uv_mutex_lock(&wait_mutex);
|
58
|
+
uv_mutex_unlock(&wait_mutex);
|
59
|
+
|
60
|
+
work_cb_called++;
|
61
|
+
}
|
62
|
+
|
63
|
+
|
64
|
+
static void done_cb(uv_work_t* req, int status) {
|
65
|
+
done_cb_called++;
|
66
|
+
free(req);
|
67
|
+
}
|
68
|
+
|
69
|
+
|
70
|
+
static void saturate_threadpool(void) {
|
71
|
+
uv_work_t* req;
|
72
|
+
|
73
|
+
ASSERT(0 == uv_cond_init(&signal_cond));
|
74
|
+
ASSERT(0 == uv_mutex_init(&signal_mutex));
|
75
|
+
ASSERT(0 == uv_mutex_init(&wait_mutex));
|
76
|
+
|
77
|
+
uv_mutex_lock(&signal_mutex);
|
78
|
+
uv_mutex_lock(&wait_mutex);
|
79
|
+
|
80
|
+
for (num_threads = 0; /* empty */; num_threads++) {
|
81
|
+
req = malloc(sizeof(*req));
|
82
|
+
ASSERT(req != NULL);
|
83
|
+
ASSERT(0 == uv_queue_work(uv_default_loop(), req, work_cb, done_cb));
|
84
|
+
|
85
|
+
/* Expect to get signalled within 350 ms, otherwise assume that
|
86
|
+
* the thread pool is saturated. As with any timing dependent test,
|
87
|
+
* this is obviously not ideal.
|
88
|
+
*/
|
89
|
+
if (uv_cond_timedwait(&signal_cond, &signal_mutex, 350 * 1e6)) {
|
90
|
+
ASSERT(0 == uv_cancel((uv_req_t*) req));
|
91
|
+
break;
|
92
|
+
}
|
93
|
+
}
|
94
|
+
}
|
95
|
+
|
96
|
+
|
97
|
+
static void unblock_threadpool(void) {
|
98
|
+
uv_mutex_unlock(&signal_mutex);
|
99
|
+
uv_mutex_unlock(&wait_mutex);
|
100
|
+
}
|
101
|
+
|
102
|
+
|
103
|
+
static void cleanup_threadpool(void) {
|
104
|
+
ASSERT(done_cb_called == num_threads + 1); /* +1 == cancelled work req. */
|
105
|
+
ASSERT(work_cb_called == num_threads);
|
106
|
+
|
107
|
+
uv_cond_destroy(&signal_cond);
|
108
|
+
uv_mutex_destroy(&signal_mutex);
|
109
|
+
uv_mutex_destroy(&wait_mutex);
|
110
|
+
}
|
111
|
+
|
112
|
+
|
113
|
+
static void fs_cb(uv_fs_t* req) {
|
114
|
+
ASSERT(req->errorno == UV_ECANCELED);
|
115
|
+
uv_fs_req_cleanup(req);
|
116
|
+
fs_cb_called++;
|
117
|
+
}
|
118
|
+
|
119
|
+
|
120
|
+
static void getaddrinfo_cb(uv_getaddrinfo_t* req,
|
121
|
+
int status,
|
122
|
+
struct addrinfo* res) {
|
123
|
+
ASSERT(UV_ECANCELED == uv_last_error(req->loop).code);
|
124
|
+
ASSERT(UV_ECANCELED == status);
|
125
|
+
getaddrinfo_cb_called++;
|
126
|
+
}
|
127
|
+
|
128
|
+
|
129
|
+
static void work2_cb(uv_work_t* req) {
|
130
|
+
ASSERT(0 && "work2_cb called");
|
131
|
+
}
|
132
|
+
|
133
|
+
|
134
|
+
static void done2_cb(uv_work_t* req, int status) {
|
135
|
+
ASSERT(uv_last_error(req->loop).code == UV_ECANCELED);
|
136
|
+
ASSERT(status == -1);
|
137
|
+
done2_cb_called++;
|
138
|
+
}
|
139
|
+
|
140
|
+
|
141
|
+
static void timer_cb(uv_timer_t* handle, int status) {
|
142
|
+
struct cancel_info* ci;
|
143
|
+
uv_req_t* req;
|
144
|
+
unsigned i;
|
145
|
+
|
146
|
+
ci = container_of(handle, struct cancel_info, timer_handle);
|
147
|
+
|
148
|
+
for (i = 0; i < ci->nreqs; i++) {
|
149
|
+
req = (uv_req_t*) ((char*) ci->reqs + i * ci->stride);
|
150
|
+
ASSERT(0 == uv_cancel(req));
|
151
|
+
}
|
152
|
+
|
153
|
+
uv_close((uv_handle_t*) &ci->timer_handle, NULL);
|
154
|
+
unblock_threadpool();
|
155
|
+
timer_cb_called++;
|
156
|
+
}
|
157
|
+
|
158
|
+
|
159
|
+
static void nop_work_cb(uv_work_t* req) {
|
160
|
+
}
|
161
|
+
|
162
|
+
|
163
|
+
static void nop_done_cb(uv_work_t* req, int status) {
|
164
|
+
req->data = "OK";
|
165
|
+
}
|
166
|
+
|
167
|
+
|
168
|
+
TEST_IMPL(threadpool_cancel_getaddrinfo) {
|
169
|
+
uv_getaddrinfo_t reqs[4];
|
170
|
+
struct cancel_info ci;
|
171
|
+
struct addrinfo hints;
|
172
|
+
uv_loop_t* loop;
|
173
|
+
int r;
|
174
|
+
|
175
|
+
INIT_CANCEL_INFO(&ci, reqs);
|
176
|
+
loop = uv_default_loop();
|
177
|
+
saturate_threadpool();
|
178
|
+
|
179
|
+
r = uv_getaddrinfo(loop, reqs + 0, getaddrinfo_cb, "fail", NULL, NULL);
|
180
|
+
ASSERT(r == 0);
|
181
|
+
|
182
|
+
r = uv_getaddrinfo(loop, reqs + 1, getaddrinfo_cb, NULL, "fail", NULL);
|
183
|
+
ASSERT(r == 0);
|
184
|
+
|
185
|
+
r = uv_getaddrinfo(loop, reqs + 2, getaddrinfo_cb, "fail", "fail", NULL);
|
186
|
+
ASSERT(r == 0);
|
187
|
+
|
188
|
+
r = uv_getaddrinfo(loop, reqs + 3, getaddrinfo_cb, "fail", NULL, &hints);
|
189
|
+
ASSERT(r == 0);
|
190
|
+
|
191
|
+
ASSERT(0 == uv_timer_init(loop, &ci.timer_handle));
|
192
|
+
ASSERT(0 == uv_timer_start(&ci.timer_handle, timer_cb, 10, 0));
|
193
|
+
ASSERT(0 == uv_run(loop, UV_RUN_DEFAULT));
|
194
|
+
ASSERT(1 == timer_cb_called);
|
195
|
+
|
196
|
+
cleanup_threadpool();
|
197
|
+
|
198
|
+
MAKE_VALGRIND_HAPPY();
|
199
|
+
return 0;
|
200
|
+
}
|
201
|
+
|
202
|
+
|
203
|
+
TEST_IMPL(threadpool_cancel_work) {
|
204
|
+
struct cancel_info ci;
|
205
|
+
uv_work_t reqs[16];
|
206
|
+
uv_loop_t* loop;
|
207
|
+
unsigned i;
|
208
|
+
|
209
|
+
INIT_CANCEL_INFO(&ci, reqs);
|
210
|
+
loop = uv_default_loop();
|
211
|
+
saturate_threadpool();
|
212
|
+
|
213
|
+
for (i = 0; i < ARRAY_SIZE(reqs); i++)
|
214
|
+
ASSERT(0 == uv_queue_work(loop, reqs + i, work2_cb, done2_cb));
|
215
|
+
|
216
|
+
ASSERT(0 == uv_timer_init(loop, &ci.timer_handle));
|
217
|
+
ASSERT(0 == uv_timer_start(&ci.timer_handle, timer_cb, 10, 0));
|
218
|
+
ASSERT(0 == uv_run(loop, UV_RUN_DEFAULT));
|
219
|
+
ASSERT(1 == timer_cb_called);
|
220
|
+
ASSERT(ARRAY_SIZE(reqs) == done2_cb_called);
|
221
|
+
|
222
|
+
cleanup_threadpool();
|
223
|
+
|
224
|
+
MAKE_VALGRIND_HAPPY();
|
225
|
+
return 0;
|
226
|
+
}
|
227
|
+
|
228
|
+
|
229
|
+
TEST_IMPL(threadpool_cancel_fs) {
|
230
|
+
struct cancel_info ci;
|
231
|
+
uv_fs_t reqs[25];
|
232
|
+
uv_loop_t* loop;
|
233
|
+
unsigned n;
|
234
|
+
|
235
|
+
INIT_CANCEL_INFO(&ci, reqs);
|
236
|
+
loop = uv_default_loop();
|
237
|
+
saturate_threadpool();
|
238
|
+
|
239
|
+
/* Needs to match ARRAY_SIZE(fs_reqs). */
|
240
|
+
n = 0;
|
241
|
+
ASSERT(0 == uv_fs_chmod(loop, reqs + n++, "/", 0, fs_cb));
|
242
|
+
ASSERT(0 == uv_fs_chown(loop, reqs + n++, "/", 0, 0, fs_cb));
|
243
|
+
ASSERT(0 == uv_fs_close(loop, reqs + n++, 0, fs_cb));
|
244
|
+
ASSERT(0 == uv_fs_fchmod(loop, reqs + n++, 0, 0, fs_cb));
|
245
|
+
ASSERT(0 == uv_fs_fchown(loop, reqs + n++, 0, 0, 0, fs_cb));
|
246
|
+
ASSERT(0 == uv_fs_fdatasync(loop, reqs + n++, 0, fs_cb));
|
247
|
+
ASSERT(0 == uv_fs_fstat(loop, reqs + n++, 0, fs_cb));
|
248
|
+
ASSERT(0 == uv_fs_fsync(loop, reqs + n++, 0, fs_cb));
|
249
|
+
ASSERT(0 == uv_fs_ftruncate(loop, reqs + n++, 0, 0, fs_cb));
|
250
|
+
ASSERT(0 == uv_fs_futime(loop, reqs + n++, 0, 0, 0, fs_cb));
|
251
|
+
ASSERT(0 == uv_fs_link(loop, reqs + n++, "/", "/", fs_cb));
|
252
|
+
ASSERT(0 == uv_fs_lstat(loop, reqs + n++, "/", fs_cb));
|
253
|
+
ASSERT(0 == uv_fs_mkdir(loop, reqs + n++, "/", 0, fs_cb));
|
254
|
+
ASSERT(0 == uv_fs_open(loop, reqs + n++, "/", 0, 0, fs_cb));
|
255
|
+
ASSERT(0 == uv_fs_read(loop, reqs + n++, 0, NULL, 0, 0, fs_cb));
|
256
|
+
ASSERT(0 == uv_fs_readdir(loop, reqs + n++, "/", 0, fs_cb));
|
257
|
+
ASSERT(0 == uv_fs_readlink(loop, reqs + n++, "/", fs_cb));
|
258
|
+
ASSERT(0 == uv_fs_rename(loop, reqs + n++, "/", "/", fs_cb));
|
259
|
+
ASSERT(0 == uv_fs_mkdir(loop, reqs + n++, "/", 0, fs_cb));
|
260
|
+
ASSERT(0 == uv_fs_sendfile(loop, reqs + n++, 0, 0, 0, 0, fs_cb));
|
261
|
+
ASSERT(0 == uv_fs_stat(loop, reqs + n++, "/", fs_cb));
|
262
|
+
ASSERT(0 == uv_fs_symlink(loop, reqs + n++, "/", "/", 0, fs_cb));
|
263
|
+
ASSERT(0 == uv_fs_unlink(loop, reqs + n++, "/", fs_cb));
|
264
|
+
ASSERT(0 == uv_fs_utime(loop, reqs + n++, "/", 0, 0, fs_cb));
|
265
|
+
ASSERT(0 == uv_fs_write(loop, reqs + n++, 0, NULL, 0, 0, fs_cb));
|
266
|
+
ASSERT(n == ARRAY_SIZE(reqs));
|
267
|
+
|
268
|
+
ASSERT(0 == uv_timer_init(loop, &ci.timer_handle));
|
269
|
+
ASSERT(0 == uv_timer_start(&ci.timer_handle, timer_cb, 10, 0));
|
270
|
+
ASSERT(0 == uv_run(loop, UV_RUN_DEFAULT));
|
271
|
+
ASSERT(n == fs_cb_called);
|
272
|
+
ASSERT(1 == timer_cb_called);
|
273
|
+
|
274
|
+
cleanup_threadpool();
|
275
|
+
|
276
|
+
MAKE_VALGRIND_HAPPY();
|
277
|
+
return 0;
|
278
|
+
}
|
279
|
+
|
280
|
+
|
281
|
+
TEST_IMPL(threadpool_cancel_single) {
|
282
|
+
uv_loop_t* loop;
|
283
|
+
uv_work_t req;
|
284
|
+
int cancelled;
|
285
|
+
int i;
|
286
|
+
|
287
|
+
loop = uv_default_loop();
|
288
|
+
for (i = 0; i < 5000; i++) {
|
289
|
+
req.data = NULL;
|
290
|
+
ASSERT(0 == uv_queue_work(loop, &req, nop_work_cb, nop_done_cb));
|
291
|
+
|
292
|
+
cancelled = uv_cancel((uv_req_t*) &req);
|
293
|
+
if (cancelled == 0)
|
294
|
+
break;
|
295
|
+
|
296
|
+
ASSERT(0 == uv_run(loop, UV_RUN_DEFAULT));
|
297
|
+
}
|
298
|
+
|
299
|
+
if (cancelled != 0) {
|
300
|
+
fputs("Failed to cancel a work req in 5,000 iterations, giving up.\n",
|
301
|
+
stderr);
|
302
|
+
return 1;
|
303
|
+
}
|
304
|
+
|
305
|
+
ASSERT(req.data == NULL);
|
306
|
+
ASSERT(0 == uv_run(loop, UV_RUN_DEFAULT));
|
307
|
+
ASSERT(req.data != NULL); /* Should have been updated by nop_done_cb(). */
|
308
|
+
|
309
|
+
MAKE_VALGRIND_HAPPY();
|
310
|
+
return 0;
|
311
|
+
}
|
@@ -0,0 +1,77 @@
|
|
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 "task.h"
|
24
|
+
|
25
|
+
static int work_cb_count;
|
26
|
+
static int after_work_cb_count;
|
27
|
+
static uv_work_t work_req;
|
28
|
+
static char data;
|
29
|
+
|
30
|
+
|
31
|
+
static void work_cb(uv_work_t* req) {
|
32
|
+
ASSERT(req == &work_req);
|
33
|
+
ASSERT(req->data == &data);
|
34
|
+
work_cb_count++;
|
35
|
+
}
|
36
|
+
|
37
|
+
|
38
|
+
static void after_work_cb(uv_work_t* req, int status) {
|
39
|
+
ASSERT(status == 0);
|
40
|
+
ASSERT(req == &work_req);
|
41
|
+
ASSERT(req->data == &data);
|
42
|
+
after_work_cb_count++;
|
43
|
+
}
|
44
|
+
|
45
|
+
|
46
|
+
TEST_IMPL(threadpool_queue_work_simple) {
|
47
|
+
int r;
|
48
|
+
|
49
|
+
work_req.data = &data;
|
50
|
+
r = uv_queue_work(uv_default_loop(), &work_req, work_cb, after_work_cb);
|
51
|
+
ASSERT(r == 0);
|
52
|
+
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
53
|
+
|
54
|
+
ASSERT(work_cb_count == 1);
|
55
|
+
ASSERT(after_work_cb_count == 1);
|
56
|
+
|
57
|
+
MAKE_VALGRIND_HAPPY();
|
58
|
+
return 0;
|
59
|
+
}
|
60
|
+
|
61
|
+
|
62
|
+
TEST_IMPL(threadpool_queue_work_einval) {
|
63
|
+
int r;
|
64
|
+
|
65
|
+
work_req.data = &data;
|
66
|
+
r = uv_queue_work(uv_default_loop(), &work_req, NULL, after_work_cb);
|
67
|
+
ASSERT(r == -1);
|
68
|
+
|
69
|
+
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
70
|
+
ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL);
|
71
|
+
|
72
|
+
ASSERT(work_cb_count == 0);
|
73
|
+
ASSERT(after_work_cb_count == 0);
|
74
|
+
|
75
|
+
MAKE_VALGRIND_HAPPY();
|
76
|
+
return 0;
|
77
|
+
}
|
@@ -0,0 +1,142 @@
|
|
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 "task.h"
|
24
|
+
|
25
|
+
|
26
|
+
static int close_cb_called = 0;
|
27
|
+
static int repeat_1_cb_called = 0;
|
28
|
+
static int repeat_2_cb_called = 0;
|
29
|
+
|
30
|
+
static int repeat_2_cb_allowed = 0;
|
31
|
+
|
32
|
+
static uv_timer_t dummy, repeat_1, repeat_2;
|
33
|
+
|
34
|
+
static uint64_t start_time;
|
35
|
+
|
36
|
+
|
37
|
+
static void close_cb(uv_handle_t* handle) {
|
38
|
+
ASSERT(handle != NULL);
|
39
|
+
|
40
|
+
close_cb_called++;
|
41
|
+
}
|
42
|
+
|
43
|
+
|
44
|
+
static void repeat_1_cb(uv_timer_t* handle, int status) {
|
45
|
+
int r;
|
46
|
+
|
47
|
+
ASSERT(handle == &repeat_1);
|
48
|
+
ASSERT(status == 0);
|
49
|
+
|
50
|
+
ASSERT(uv_timer_get_repeat((uv_timer_t*)handle) == 50);
|
51
|
+
|
52
|
+
LOGF("repeat_1_cb called after %ld ms\n",
|
53
|
+
(long int)(uv_now(uv_default_loop()) - start_time));
|
54
|
+
|
55
|
+
repeat_1_cb_called++;
|
56
|
+
|
57
|
+
r = uv_timer_again(&repeat_2);
|
58
|
+
ASSERT(r == 0);
|
59
|
+
|
60
|
+
if (uv_now(uv_default_loop()) >= start_time + 500) {
|
61
|
+
uv_close((uv_handle_t*)handle, close_cb);
|
62
|
+
/* We're not calling uv_timer_again on repeat_2 any more, so after this */
|
63
|
+
/* timer_2_cb is expected. */
|
64
|
+
repeat_2_cb_allowed = 1;
|
65
|
+
return;
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
69
|
+
|
70
|
+
static void repeat_2_cb(uv_timer_t* handle, int status) {
|
71
|
+
ASSERT(handle == &repeat_2);
|
72
|
+
ASSERT(status == 0);
|
73
|
+
ASSERT(repeat_2_cb_allowed);
|
74
|
+
|
75
|
+
LOGF("repeat_2_cb called after %ld ms\n",
|
76
|
+
(long int)(uv_now(uv_default_loop()) - start_time));
|
77
|
+
|
78
|
+
repeat_2_cb_called++;
|
79
|
+
|
80
|
+
if (uv_timer_get_repeat(&repeat_2) == 0) {
|
81
|
+
ASSERT(!uv_is_active((uv_handle_t*)handle));
|
82
|
+
uv_close((uv_handle_t*)handle, close_cb);
|
83
|
+
return;
|
84
|
+
}
|
85
|
+
|
86
|
+
LOGF("uv_timer_get_repeat %ld ms\n",
|
87
|
+
(long int)uv_timer_get_repeat(&repeat_2));
|
88
|
+
ASSERT(uv_timer_get_repeat(&repeat_2) == 100);
|
89
|
+
|
90
|
+
/* This shouldn't take effect immediately. */
|
91
|
+
uv_timer_set_repeat(&repeat_2, 0);
|
92
|
+
}
|
93
|
+
|
94
|
+
|
95
|
+
TEST_IMPL(timer_again) {
|
96
|
+
int r;
|
97
|
+
|
98
|
+
start_time = uv_now(uv_default_loop());
|
99
|
+
ASSERT(0 < start_time);
|
100
|
+
|
101
|
+
/* Verify that it is not possible to uv_timer_again a never-started timer. */
|
102
|
+
r = uv_timer_init(uv_default_loop(), &dummy);
|
103
|
+
ASSERT(r == 0);
|
104
|
+
r = uv_timer_again(&dummy);
|
105
|
+
ASSERT(r == -1);
|
106
|
+
ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL);
|
107
|
+
uv_unref((uv_handle_t*)&dummy);
|
108
|
+
|
109
|
+
/* Start timer repeat_1. */
|
110
|
+
r = uv_timer_init(uv_default_loop(), &repeat_1);
|
111
|
+
ASSERT(r == 0);
|
112
|
+
r = uv_timer_start(&repeat_1, repeat_1_cb, 50, 0);
|
113
|
+
ASSERT(r == 0);
|
114
|
+
ASSERT(uv_timer_get_repeat(&repeat_1) == 0);
|
115
|
+
|
116
|
+
/* Actually make repeat_1 repeating. */
|
117
|
+
uv_timer_set_repeat(&repeat_1, 50);
|
118
|
+
ASSERT(uv_timer_get_repeat(&repeat_1) == 50);
|
119
|
+
|
120
|
+
/*
|
121
|
+
* Start another repeating timer. It'll be again()ed by the repeat_1 so
|
122
|
+
* it should not time out until repeat_1 stops.
|
123
|
+
*/
|
124
|
+
r = uv_timer_init(uv_default_loop(), &repeat_2);
|
125
|
+
ASSERT(r == 0);
|
126
|
+
r = uv_timer_start(&repeat_2, repeat_2_cb, 100, 100);
|
127
|
+
ASSERT(r == 0);
|
128
|
+
ASSERT(uv_timer_get_repeat(&repeat_2) == 100);
|
129
|
+
|
130
|
+
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
131
|
+
|
132
|
+
ASSERT(repeat_1_cb_called == 10);
|
133
|
+
ASSERT(repeat_2_cb_called == 2);
|
134
|
+
ASSERT(close_cb_called == 2);
|
135
|
+
|
136
|
+
LOGF("Test took %ld ms (expected ~700 ms)\n",
|
137
|
+
(long int)(uv_now(uv_default_loop()) - start_time));
|
138
|
+
ASSERT(700 <= uv_now(uv_default_loop()) - start_time);
|
139
|
+
|
140
|
+
MAKE_VALGRIND_HAPPY();
|
141
|
+
return 0;
|
142
|
+
}
|