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,250 @@
|
|
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 <stdlib.h>
|
26
|
+
#include <stdio.h>
|
27
|
+
|
28
|
+
static int completed_pingers = 0;
|
29
|
+
|
30
|
+
#define NUM_PINGS 1000
|
31
|
+
|
32
|
+
/* 64 bytes is enough for a pinger */
|
33
|
+
#define BUFSIZE 10240
|
34
|
+
|
35
|
+
static char PING[] = "PING\n";
|
36
|
+
static int pinger_on_connect_count;
|
37
|
+
|
38
|
+
|
39
|
+
typedef struct {
|
40
|
+
int pongs;
|
41
|
+
int state;
|
42
|
+
union {
|
43
|
+
uv_tcp_t tcp;
|
44
|
+
uv_pipe_t pipe;
|
45
|
+
} stream;
|
46
|
+
uv_connect_t connect_req;
|
47
|
+
char read_buffer[BUFSIZE];
|
48
|
+
} pinger_t;
|
49
|
+
|
50
|
+
|
51
|
+
static uv_buf_t alloc_cb(uv_handle_t* handle, size_t size) {
|
52
|
+
return uv_buf_init(malloc(size), size);
|
53
|
+
}
|
54
|
+
|
55
|
+
|
56
|
+
static void pinger_on_close(uv_handle_t* handle) {
|
57
|
+
pinger_t* pinger = (pinger_t*)handle->data;
|
58
|
+
|
59
|
+
ASSERT(NUM_PINGS == pinger->pongs);
|
60
|
+
|
61
|
+
free(pinger);
|
62
|
+
|
63
|
+
completed_pingers++;
|
64
|
+
}
|
65
|
+
|
66
|
+
|
67
|
+
static void pinger_after_write(uv_write_t *req, int status) {
|
68
|
+
ASSERT(status == 0);
|
69
|
+
free(req);
|
70
|
+
}
|
71
|
+
|
72
|
+
|
73
|
+
static void pinger_write_ping(pinger_t* pinger) {
|
74
|
+
uv_write_t *req;
|
75
|
+
uv_buf_t buf;
|
76
|
+
|
77
|
+
buf = uv_buf_init(PING, sizeof(PING) - 1);
|
78
|
+
|
79
|
+
req = malloc(sizeof(*req));
|
80
|
+
if (uv_write(req, (uv_stream_t*)&pinger->stream.tcp, &buf, 1, pinger_after_write)) {
|
81
|
+
FATAL("uv_write failed");
|
82
|
+
}
|
83
|
+
|
84
|
+
puts("PING");
|
85
|
+
}
|
86
|
+
|
87
|
+
|
88
|
+
static void pinger_read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf) {
|
89
|
+
ssize_t i;
|
90
|
+
pinger_t* pinger;
|
91
|
+
|
92
|
+
pinger = (pinger_t*)stream->data;
|
93
|
+
|
94
|
+
if (nread < 0) {
|
95
|
+
ASSERT(uv_last_error(uv_default_loop()).code == UV_EOF);
|
96
|
+
|
97
|
+
puts("got EOF");
|
98
|
+
free(buf.base);
|
99
|
+
|
100
|
+
uv_close((uv_handle_t*)(&pinger->stream.tcp), pinger_on_close);
|
101
|
+
|
102
|
+
return;
|
103
|
+
}
|
104
|
+
|
105
|
+
/* Now we count the pings */
|
106
|
+
for (i = 0; i < nread; i++) {
|
107
|
+
ASSERT(buf.base[i] == PING[pinger->state]);
|
108
|
+
pinger->state = (pinger->state + 1) % (sizeof(PING) - 1);
|
109
|
+
|
110
|
+
if (pinger->state != 0)
|
111
|
+
continue;
|
112
|
+
|
113
|
+
printf("PONG %d\n", pinger->pongs);
|
114
|
+
pinger->pongs++;
|
115
|
+
|
116
|
+
if (pinger->pongs < NUM_PINGS) {
|
117
|
+
pinger_write_ping(pinger);
|
118
|
+
} else {
|
119
|
+
uv_close((uv_handle_t*)(&pinger->stream.tcp), pinger_on_close);
|
120
|
+
break;
|
121
|
+
}
|
122
|
+
}
|
123
|
+
|
124
|
+
free(buf.base);
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
static void pinger_on_connect(uv_connect_t *req, int status) {
|
129
|
+
pinger_t *pinger = (pinger_t*)req->handle->data;
|
130
|
+
|
131
|
+
pinger_on_connect_count++;
|
132
|
+
|
133
|
+
ASSERT(status == 0);
|
134
|
+
|
135
|
+
ASSERT(uv_is_readable(req->handle));
|
136
|
+
ASSERT(uv_is_writable(req->handle));
|
137
|
+
ASSERT(!uv_is_closing((uv_handle_t *)req->handle));
|
138
|
+
|
139
|
+
pinger_write_ping(pinger);
|
140
|
+
|
141
|
+
uv_read_start((uv_stream_t*)(req->handle), alloc_cb, pinger_read_cb);
|
142
|
+
}
|
143
|
+
|
144
|
+
|
145
|
+
/* same ping-pong test, but using IPv6 connection */
|
146
|
+
static void tcp_pinger_v6_new(void) {
|
147
|
+
int r;
|
148
|
+
struct sockaddr_in6 server_addr = uv_ip6_addr("::1", TEST_PORT);
|
149
|
+
pinger_t *pinger;
|
150
|
+
|
151
|
+
pinger = (pinger_t*)malloc(sizeof(*pinger));
|
152
|
+
pinger->state = 0;
|
153
|
+
pinger->pongs = 0;
|
154
|
+
|
155
|
+
/* Try to connect to the server and do NUM_PINGS ping-pongs. */
|
156
|
+
r = uv_tcp_init(uv_default_loop(), &pinger->stream.tcp);
|
157
|
+
pinger->stream.tcp.data = pinger;
|
158
|
+
ASSERT(!r);
|
159
|
+
|
160
|
+
/* We are never doing multiple reads/connects at a time anyway. */
|
161
|
+
/* so these handles can be pre-initialized. */
|
162
|
+
r = uv_tcp_connect6(&pinger->connect_req, &pinger->stream.tcp, server_addr,
|
163
|
+
pinger_on_connect);
|
164
|
+
ASSERT(!r);
|
165
|
+
|
166
|
+
/* Synchronous connect callbacks are not allowed. */
|
167
|
+
ASSERT(pinger_on_connect_count == 0);
|
168
|
+
}
|
169
|
+
|
170
|
+
|
171
|
+
static void tcp_pinger_new(void) {
|
172
|
+
int r;
|
173
|
+
struct sockaddr_in server_addr = uv_ip4_addr("127.0.0.1", TEST_PORT);
|
174
|
+
pinger_t *pinger;
|
175
|
+
|
176
|
+
pinger = (pinger_t*)malloc(sizeof(*pinger));
|
177
|
+
pinger->state = 0;
|
178
|
+
pinger->pongs = 0;
|
179
|
+
|
180
|
+
/* Try to connect to the server and do NUM_PINGS ping-pongs. */
|
181
|
+
r = uv_tcp_init(uv_default_loop(), &pinger->stream.tcp);
|
182
|
+
pinger->stream.tcp.data = pinger;
|
183
|
+
ASSERT(!r);
|
184
|
+
|
185
|
+
/* We are never doing multiple reads/connects at a time anyway. */
|
186
|
+
/* so these handles can be pre-initialized. */
|
187
|
+
r = uv_tcp_connect(&pinger->connect_req, &pinger->stream.tcp, server_addr,
|
188
|
+
pinger_on_connect);
|
189
|
+
ASSERT(!r);
|
190
|
+
|
191
|
+
/* Synchronous connect callbacks are not allowed. */
|
192
|
+
ASSERT(pinger_on_connect_count == 0);
|
193
|
+
}
|
194
|
+
|
195
|
+
|
196
|
+
static void pipe_pinger_new(void) {
|
197
|
+
int r;
|
198
|
+
pinger_t *pinger;
|
199
|
+
|
200
|
+
pinger = (pinger_t*)malloc(sizeof(*pinger));
|
201
|
+
pinger->state = 0;
|
202
|
+
pinger->pongs = 0;
|
203
|
+
|
204
|
+
/* Try to connect to the server and do NUM_PINGS ping-pongs. */
|
205
|
+
r = uv_pipe_init(uv_default_loop(), &pinger->stream.pipe, 0);
|
206
|
+
pinger->stream.pipe.data = pinger;
|
207
|
+
ASSERT(!r);
|
208
|
+
|
209
|
+
/* We are never doing multiple reads/connects at a time anyway. */
|
210
|
+
/* so these handles can be pre-initialized. */
|
211
|
+
|
212
|
+
uv_pipe_connect(&pinger->connect_req, &pinger->stream.pipe, TEST_PIPENAME,
|
213
|
+
pinger_on_connect);
|
214
|
+
|
215
|
+
/* Synchronous connect callbacks are not allowed. */
|
216
|
+
ASSERT(pinger_on_connect_count == 0);
|
217
|
+
}
|
218
|
+
|
219
|
+
|
220
|
+
TEST_IMPL(tcp_ping_pong) {
|
221
|
+
tcp_pinger_new();
|
222
|
+
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
223
|
+
|
224
|
+
ASSERT(completed_pingers == 1);
|
225
|
+
|
226
|
+
MAKE_VALGRIND_HAPPY();
|
227
|
+
return 0;
|
228
|
+
}
|
229
|
+
|
230
|
+
|
231
|
+
TEST_IMPL(tcp_ping_pong_v6) {
|
232
|
+
tcp_pinger_v6_new();
|
233
|
+
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
234
|
+
|
235
|
+
ASSERT(completed_pingers == 1);
|
236
|
+
|
237
|
+
MAKE_VALGRIND_HAPPY();
|
238
|
+
return 0;
|
239
|
+
}
|
240
|
+
|
241
|
+
|
242
|
+
TEST_IMPL(pipe_ping_pong) {
|
243
|
+
pipe_pinger_new();
|
244
|
+
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
245
|
+
|
246
|
+
ASSERT(completed_pingers == 1);
|
247
|
+
|
248
|
+
MAKE_VALGRIND_HAPPY();
|
249
|
+
return 0;
|
250
|
+
}
|
@@ -0,0 +1,144 @@
|
|
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
|
+
#include <stdio.h>
|
25
|
+
#include <stdlib.h>
|
26
|
+
|
27
|
+
|
28
|
+
#ifdef _WIN32
|
29
|
+
# define BAD_PIPENAME "bad-pipe"
|
30
|
+
#else
|
31
|
+
# define BAD_PIPENAME "/path/to/unix/socket/that/really/should/not/be/there"
|
32
|
+
#endif
|
33
|
+
|
34
|
+
|
35
|
+
static int close_cb_called = 0;
|
36
|
+
|
37
|
+
|
38
|
+
static void close_cb(uv_handle_t* handle) {
|
39
|
+
ASSERT(handle != NULL);
|
40
|
+
close_cb_called++;
|
41
|
+
}
|
42
|
+
|
43
|
+
|
44
|
+
TEST_IMPL(pipe_bind_error_addrinuse) {
|
45
|
+
uv_pipe_t server1, server2;
|
46
|
+
int r;
|
47
|
+
|
48
|
+
r = uv_pipe_init(uv_default_loop(), &server1, 0);
|
49
|
+
ASSERT(r == 0);
|
50
|
+
r = uv_pipe_bind(&server1, TEST_PIPENAME);
|
51
|
+
ASSERT(r == 0);
|
52
|
+
|
53
|
+
r = uv_pipe_init(uv_default_loop(), &server2, 0);
|
54
|
+
ASSERT(r == 0);
|
55
|
+
r = uv_pipe_bind(&server2, TEST_PIPENAME);
|
56
|
+
ASSERT(r == -1);
|
57
|
+
|
58
|
+
ASSERT(uv_last_error(uv_default_loop()).code == UV_EADDRINUSE);
|
59
|
+
|
60
|
+
r = uv_listen((uv_stream_t*)&server1, SOMAXCONN, NULL);
|
61
|
+
ASSERT(r == 0);
|
62
|
+
r = uv_listen((uv_stream_t*)&server2, SOMAXCONN, NULL);
|
63
|
+
ASSERT(r == -1);
|
64
|
+
|
65
|
+
ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL);
|
66
|
+
|
67
|
+
uv_close((uv_handle_t*)&server1, close_cb);
|
68
|
+
uv_close((uv_handle_t*)&server2, close_cb);
|
69
|
+
|
70
|
+
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
71
|
+
|
72
|
+
ASSERT(close_cb_called == 2);
|
73
|
+
|
74
|
+
MAKE_VALGRIND_HAPPY();
|
75
|
+
return 0;
|
76
|
+
}
|
77
|
+
|
78
|
+
|
79
|
+
TEST_IMPL(pipe_bind_error_addrnotavail) {
|
80
|
+
uv_pipe_t server;
|
81
|
+
int r;
|
82
|
+
|
83
|
+
r = uv_pipe_init(uv_default_loop(), &server, 0);
|
84
|
+
ASSERT(r == 0);
|
85
|
+
r = uv_pipe_bind(&server, BAD_PIPENAME);
|
86
|
+
|
87
|
+
ASSERT(r == -1);
|
88
|
+
ASSERT(uv_last_error(uv_default_loop()).code == UV_EACCES);
|
89
|
+
|
90
|
+
uv_close((uv_handle_t*)&server, close_cb);
|
91
|
+
|
92
|
+
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
93
|
+
|
94
|
+
ASSERT(close_cb_called == 1);
|
95
|
+
|
96
|
+
MAKE_VALGRIND_HAPPY();
|
97
|
+
return 0;
|
98
|
+
}
|
99
|
+
|
100
|
+
|
101
|
+
TEST_IMPL(pipe_bind_error_inval) {
|
102
|
+
uv_pipe_t server;
|
103
|
+
int r;
|
104
|
+
|
105
|
+
r = uv_pipe_init(uv_default_loop(), &server, 0);
|
106
|
+
ASSERT(r == 0);
|
107
|
+
r = uv_pipe_bind(&server, TEST_PIPENAME);
|
108
|
+
ASSERT(r == 0);
|
109
|
+
r = uv_pipe_bind(&server, TEST_PIPENAME_2);
|
110
|
+
ASSERT(r == -1);
|
111
|
+
|
112
|
+
ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL);
|
113
|
+
|
114
|
+
uv_close((uv_handle_t*)&server, close_cb);
|
115
|
+
|
116
|
+
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
117
|
+
|
118
|
+
ASSERT(close_cb_called == 1);
|
119
|
+
|
120
|
+
MAKE_VALGRIND_HAPPY();
|
121
|
+
return 0;
|
122
|
+
}
|
123
|
+
|
124
|
+
|
125
|
+
TEST_IMPL(pipe_listen_without_bind) {
|
126
|
+
uv_pipe_t server;
|
127
|
+
int r;
|
128
|
+
|
129
|
+
r = uv_pipe_init(uv_default_loop(), &server, 0);
|
130
|
+
ASSERT(r == 0);
|
131
|
+
r = uv_listen((uv_stream_t*)&server, SOMAXCONN, NULL);
|
132
|
+
ASSERT(r == -1);
|
133
|
+
|
134
|
+
ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL);
|
135
|
+
|
136
|
+
uv_close((uv_handle_t*)&server, close_cb);
|
137
|
+
|
138
|
+
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
139
|
+
|
140
|
+
ASSERT(close_cb_called == 1);
|
141
|
+
|
142
|
+
MAKE_VALGRIND_HAPPY();
|
143
|
+
return 0;
|
144
|
+
}
|
@@ -0,0 +1,98 @@
|
|
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
|
+
#include <stdio.h>
|
25
|
+
#include <stdlib.h>
|
26
|
+
|
27
|
+
|
28
|
+
#ifdef _WIN32
|
29
|
+
# define BAD_PIPENAME "bad-pipe"
|
30
|
+
#else
|
31
|
+
# define BAD_PIPENAME "/path/to/unix/socket/that/really/should/not/be/there"
|
32
|
+
#endif
|
33
|
+
|
34
|
+
|
35
|
+
static int close_cb_called = 0;
|
36
|
+
static int connect_cb_called = 0;
|
37
|
+
|
38
|
+
|
39
|
+
static void close_cb(uv_handle_t* handle) {
|
40
|
+
ASSERT(handle != NULL);
|
41
|
+
close_cb_called++;
|
42
|
+
}
|
43
|
+
|
44
|
+
|
45
|
+
static void connect_cb(uv_connect_t* connect_req, int status) {
|
46
|
+
ASSERT(status == -1);
|
47
|
+
ASSERT(uv_last_error(uv_default_loop()).code == UV_ENOENT);
|
48
|
+
uv_close((uv_handle_t*)connect_req->handle, close_cb);
|
49
|
+
connect_cb_called++;
|
50
|
+
}
|
51
|
+
|
52
|
+
|
53
|
+
static void connect_cb_file(uv_connect_t* connect_req, int status) {
|
54
|
+
ASSERT(status == -1);
|
55
|
+
ASSERT(uv_last_error(uv_default_loop()).code == UV_ENOTSOCK ||
|
56
|
+
uv_last_error(uv_default_loop()).code == UV_ECONNREFUSED);
|
57
|
+
uv_close((uv_handle_t*)connect_req->handle, close_cb);
|
58
|
+
connect_cb_called++;
|
59
|
+
}
|
60
|
+
|
61
|
+
|
62
|
+
TEST_IMPL(pipe_connect_bad_name) {
|
63
|
+
uv_pipe_t client;
|
64
|
+
uv_connect_t req;
|
65
|
+
int r;
|
66
|
+
|
67
|
+
r = uv_pipe_init(uv_default_loop(), &client, 0);
|
68
|
+
ASSERT(r == 0);
|
69
|
+
uv_pipe_connect(&req, &client, BAD_PIPENAME, connect_cb);
|
70
|
+
|
71
|
+
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
72
|
+
|
73
|
+
ASSERT(close_cb_called == 1);
|
74
|
+
ASSERT(connect_cb_called == 1);
|
75
|
+
|
76
|
+
MAKE_VALGRIND_HAPPY();
|
77
|
+
return 0;
|
78
|
+
}
|
79
|
+
|
80
|
+
|
81
|
+
TEST_IMPL(pipe_connect_to_file) {
|
82
|
+
const char* path = "test/fixtures/empty_file";
|
83
|
+
uv_pipe_t client;
|
84
|
+
uv_connect_t req;
|
85
|
+
int r;
|
86
|
+
|
87
|
+
r = uv_pipe_init(uv_default_loop(), &client, 0);
|
88
|
+
ASSERT(r == 0);
|
89
|
+
uv_pipe_connect(&req, &client, path, connect_cb_file);
|
90
|
+
|
91
|
+
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
92
|
+
|
93
|
+
ASSERT(close_cb_called == 1);
|
94
|
+
ASSERT(connect_cb_called == 1);
|
95
|
+
|
96
|
+
MAKE_VALGRIND_HAPPY();
|
97
|
+
return 0;
|
98
|
+
}
|
@@ -0,0 +1,87 @@
|
|
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
|
+
#include <string.h>
|
25
|
+
|
26
|
+
|
27
|
+
TEST_IMPL(platform_output) {
|
28
|
+
char buffer[512];
|
29
|
+
size_t rss;
|
30
|
+
double uptime;
|
31
|
+
uv_cpu_info_t* cpus;
|
32
|
+
uv_interface_address_t* interfaces;
|
33
|
+
int count;
|
34
|
+
int i;
|
35
|
+
uv_err_t err;
|
36
|
+
|
37
|
+
err = uv_get_process_title(buffer, sizeof(buffer));
|
38
|
+
ASSERT(UV_OK == err.code);
|
39
|
+
printf("uv_get_process_title: %s\n", buffer);
|
40
|
+
|
41
|
+
err = uv_resident_set_memory(&rss);
|
42
|
+
ASSERT(UV_OK == err.code);
|
43
|
+
printf("uv_resident_set_memory: %llu\n", (unsigned long long) rss);
|
44
|
+
|
45
|
+
err = uv_uptime(&uptime);
|
46
|
+
ASSERT(UV_OK == err.code);
|
47
|
+
ASSERT(uptime > 0);
|
48
|
+
printf("uv_uptime: %f\n", uptime);
|
49
|
+
|
50
|
+
err = uv_cpu_info(&cpus, &count);
|
51
|
+
ASSERT(UV_OK == err.code);
|
52
|
+
|
53
|
+
printf("uv_cpu_info:\n");
|
54
|
+
for (i = 0; i < count; i++) {
|
55
|
+
printf(" model: %s\n", cpus[i].model);
|
56
|
+
printf(" speed: %d\n", cpus[i].speed);
|
57
|
+
printf(" times.sys: %llu\n", (unsigned long long) cpus[i].cpu_times.sys);
|
58
|
+
printf(" times.user: %llu\n",
|
59
|
+
(unsigned long long) cpus[i].cpu_times.user);
|
60
|
+
printf(" times.idle: %llu\n",
|
61
|
+
(unsigned long long) cpus[i].cpu_times.idle);
|
62
|
+
printf(" times.irq: %llu\n", (unsigned long long) cpus[i].cpu_times.irq);
|
63
|
+
printf(" times.nice: %llu\n",
|
64
|
+
(unsigned long long) cpus[i].cpu_times.nice);
|
65
|
+
}
|
66
|
+
uv_free_cpu_info(cpus, count);
|
67
|
+
|
68
|
+
err = uv_interface_addresses(&interfaces, &count);
|
69
|
+
ASSERT(UV_OK == err.code);
|
70
|
+
|
71
|
+
printf("uv_interface_addresses:\n");
|
72
|
+
for (i = 0; i < count; i++) {
|
73
|
+
printf(" name: %s\n", interfaces[i].name);
|
74
|
+
printf(" internal: %d\n", interfaces[i].is_internal);
|
75
|
+
|
76
|
+
if (interfaces[i].address.address4.sin_family == AF_INET) {
|
77
|
+
uv_ip4_name(&interfaces[i].address.address4, buffer, sizeof(buffer));
|
78
|
+
} else if (interfaces[i].address.address4.sin_family == AF_INET6) {
|
79
|
+
uv_ip6_name(&interfaces[i].address.address6, buffer, sizeof(buffer));
|
80
|
+
}
|
81
|
+
|
82
|
+
printf(" address: %s\n", buffer);
|
83
|
+
}
|
84
|
+
uv_free_interface_addresses(interfaces, count);
|
85
|
+
|
86
|
+
return 0;
|
87
|
+
}
|
@@ -0,0 +1,73 @@
|
|
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 <errno.h>
|
23
|
+
|
24
|
+
#ifndef _WIN32
|
25
|
+
# include <fcntl.h>
|
26
|
+
# include <sys/socket.h>
|
27
|
+
# include <unistd.h>
|
28
|
+
#endif
|
29
|
+
|
30
|
+
#include "uv.h"
|
31
|
+
#include "task.h"
|
32
|
+
|
33
|
+
#define NUM_SOCKETS 64
|
34
|
+
|
35
|
+
|
36
|
+
static int close_cb_called = 0;
|
37
|
+
|
38
|
+
|
39
|
+
static void close_cb(uv_handle_t* handle) {
|
40
|
+
close_cb_called++;
|
41
|
+
}
|
42
|
+
|
43
|
+
|
44
|
+
TEST_IMPL(poll_close) {
|
45
|
+
uv_os_sock_t sockets[NUM_SOCKETS];
|
46
|
+
uv_poll_t poll_handles[NUM_SOCKETS];
|
47
|
+
int i;
|
48
|
+
|
49
|
+
#ifdef _WIN32
|
50
|
+
{
|
51
|
+
struct WSAData wsa_data;
|
52
|
+
int r = WSAStartup(MAKEWORD(2, 2), &wsa_data);
|
53
|
+
ASSERT(r == 0);
|
54
|
+
}
|
55
|
+
#endif
|
56
|
+
|
57
|
+
for (i = 0; i < NUM_SOCKETS; i++) {
|
58
|
+
sockets[i] = socket(AF_INET, SOCK_STREAM, 0);
|
59
|
+
uv_poll_init_socket(uv_default_loop(), &poll_handles[i], sockets[i]);
|
60
|
+
uv_poll_start(&poll_handles[i], UV_READABLE | UV_WRITABLE, NULL);
|
61
|
+
}
|
62
|
+
|
63
|
+
for (i = 0; i < NUM_SOCKETS; i++) {
|
64
|
+
uv_close((uv_handle_t*) &poll_handles[i], close_cb);
|
65
|
+
}
|
66
|
+
|
67
|
+
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
68
|
+
|
69
|
+
ASSERT(close_cb_called == NUM_SOCKETS);
|
70
|
+
|
71
|
+
MAKE_VALGRIND_HAPPY();
|
72
|
+
return 0;
|
73
|
+
}
|