foolio 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +21 -0
- data/examples/timer.rb +20 -0
- data/ext/foolio/extconf.rb +34 -0
- data/ext/foolio/foolio_ext.c +921 -0
- data/ext/foolio/gen.rb +50 -0
- data/ext/foolio/make_table.rb +12 -0
- data/ext/foolio/templ +243 -0
- data/ext/libuv/.gitignore +33 -0
- data/ext/libuv/.mailmap +13 -0
- data/ext/libuv/.travis.yml +9 -0
- data/ext/libuv/AUTHORS +61 -0
- data/ext/libuv/LICENSE +44 -0
- data/ext/libuv/Makefile +71 -0
- data/ext/libuv/README.md +90 -0
- data/ext/libuv/common.gypi +178 -0
- data/ext/libuv/gyp_uv +73 -0
- data/ext/libuv/include/uv-private/eio.h +403 -0
- data/ext/libuv/include/uv-private/ev.h +838 -0
- data/ext/libuv/include/uv-private/ngx-queue.h +108 -0
- data/ext/libuv/include/uv-private/tree.h +768 -0
- data/ext/libuv/include/uv-private/uv-unix.h +324 -0
- data/ext/libuv/include/uv-private/uv-win.h +517 -0
- data/ext/libuv/include/uv.h +1838 -0
- data/ext/libuv/src/fs-poll.c +235 -0
- data/ext/libuv/src/inet.c +293 -0
- data/ext/libuv/src/unix/async.c +148 -0
- data/ext/libuv/src/unix/core.c +696 -0
- data/ext/libuv/src/unix/cygwin.c +83 -0
- data/ext/libuv/src/unix/darwin.c +342 -0
- data/ext/libuv/src/unix/dl.c +83 -0
- data/ext/libuv/src/unix/eio/Changes +63 -0
- data/ext/libuv/src/unix/eio/LICENSE +36 -0
- data/ext/libuv/src/unix/eio/Makefile.am +15 -0
- data/ext/libuv/src/unix/eio/aclocal.m4 +8957 -0
- data/ext/libuv/src/unix/eio/autogen.sh +3 -0
- data/ext/libuv/src/unix/eio/config.h.in +86 -0
- data/ext/libuv/src/unix/eio/config_cygwin.h +80 -0
- data/ext/libuv/src/unix/eio/config_darwin.h +141 -0
- data/ext/libuv/src/unix/eio/config_freebsd.h +81 -0
- data/ext/libuv/src/unix/eio/config_linux.h +94 -0
- data/ext/libuv/src/unix/eio/config_netbsd.h +81 -0
- data/ext/libuv/src/unix/eio/config_openbsd.h +137 -0
- data/ext/libuv/src/unix/eio/config_sunos.h +84 -0
- data/ext/libuv/src/unix/eio/configure.ac +22 -0
- data/ext/libuv/src/unix/eio/demo.c +194 -0
- data/ext/libuv/src/unix/eio/ecb.h +370 -0
- data/ext/libuv/src/unix/eio/eio.3 +3428 -0
- data/ext/libuv/src/unix/eio/eio.c +2593 -0
- data/ext/libuv/src/unix/eio/eio.pod +969 -0
- data/ext/libuv/src/unix/eio/libeio.m4 +195 -0
- data/ext/libuv/src/unix/eio/xthread.h +164 -0
- data/ext/libuv/src/unix/error.c +105 -0
- data/ext/libuv/src/unix/ev/Changes +388 -0
- data/ext/libuv/src/unix/ev/LICENSE +36 -0
- data/ext/libuv/src/unix/ev/Makefile.am +18 -0
- data/ext/libuv/src/unix/ev/Makefile.in +771 -0
- data/ext/libuv/src/unix/ev/README +58 -0
- data/ext/libuv/src/unix/ev/aclocal.m4 +8957 -0
- data/ext/libuv/src/unix/ev/autogen.sh +6 -0
- data/ext/libuv/src/unix/ev/config.guess +1526 -0
- data/ext/libuv/src/unix/ev/config.h.in +125 -0
- data/ext/libuv/src/unix/ev/config.sub +1658 -0
- data/ext/libuv/src/unix/ev/config_cygwin.h +123 -0
- data/ext/libuv/src/unix/ev/config_darwin.h +122 -0
- data/ext/libuv/src/unix/ev/config_freebsd.h +120 -0
- data/ext/libuv/src/unix/ev/config_linux.h +141 -0
- data/ext/libuv/src/unix/ev/config_netbsd.h +120 -0
- data/ext/libuv/src/unix/ev/config_openbsd.h +126 -0
- data/ext/libuv/src/unix/ev/config_sunos.h +122 -0
- data/ext/libuv/src/unix/ev/configure +13037 -0
- data/ext/libuv/src/unix/ev/configure.ac +18 -0
- data/ext/libuv/src/unix/ev/depcomp +630 -0
- data/ext/libuv/src/unix/ev/ev++.h +816 -0
- data/ext/libuv/src/unix/ev/ev.3 +5311 -0
- data/ext/libuv/src/unix/ev/ev.c +3925 -0
- data/ext/libuv/src/unix/ev/ev.pod +5243 -0
- data/ext/libuv/src/unix/ev/ev_epoll.c +266 -0
- data/ext/libuv/src/unix/ev/ev_kqueue.c +235 -0
- data/ext/libuv/src/unix/ev/ev_poll.c +148 -0
- data/ext/libuv/src/unix/ev/ev_port.c +179 -0
- data/ext/libuv/src/unix/ev/ev_select.c +310 -0
- data/ext/libuv/src/unix/ev/ev_vars.h +203 -0
- data/ext/libuv/src/unix/ev/ev_win32.c +153 -0
- data/ext/libuv/src/unix/ev/ev_wrap.h +196 -0
- data/ext/libuv/src/unix/ev/event.c +402 -0
- data/ext/libuv/src/unix/ev/event.h +170 -0
- data/ext/libuv/src/unix/ev/install-sh +294 -0
- data/ext/libuv/src/unix/ev/libev.m4 +39 -0
- data/ext/libuv/src/unix/ev/ltmain.sh +8413 -0
- data/ext/libuv/src/unix/ev/missing +336 -0
- data/ext/libuv/src/unix/ev/mkinstalldirs +111 -0
- data/ext/libuv/src/unix/freebsd.c +326 -0
- data/ext/libuv/src/unix/fs.c +739 -0
- data/ext/libuv/src/unix/internal.h +188 -0
- data/ext/libuv/src/unix/kqueue.c +120 -0
- data/ext/libuv/src/unix/linux/inotify.c +239 -0
- data/ext/libuv/src/unix/linux/linux-core.c +557 -0
- data/ext/libuv/src/unix/linux/syscalls.c +388 -0
- data/ext/libuv/src/unix/linux/syscalls.h +124 -0
- data/ext/libuv/src/unix/loop-watcher.c +62 -0
- data/ext/libuv/src/unix/loop.c +94 -0
- data/ext/libuv/src/unix/netbsd.c +108 -0
- data/ext/libuv/src/unix/openbsd.c +295 -0
- data/ext/libuv/src/unix/pipe.c +259 -0
- data/ext/libuv/src/unix/poll.c +114 -0
- data/ext/libuv/src/unix/process.c +495 -0
- data/ext/libuv/src/unix/signal.c +269 -0
- data/ext/libuv/src/unix/stream.c +990 -0
- data/ext/libuv/src/unix/sunos.c +481 -0
- data/ext/libuv/src/unix/tcp.c +393 -0
- data/ext/libuv/src/unix/thread.c +251 -0
- data/ext/libuv/src/unix/timer.c +136 -0
- data/ext/libuv/src/unix/tty.c +145 -0
- data/ext/libuv/src/unix/udp.c +659 -0
- data/ext/libuv/src/unix/uv-eio.c +107 -0
- data/ext/libuv/src/unix/uv-eio.h +13 -0
- data/ext/libuv/src/uv-common.c +380 -0
- data/ext/libuv/src/uv-common.h +170 -0
- data/ext/libuv/src/win/async.c +100 -0
- data/ext/libuv/src/win/atomicops-inl.h +56 -0
- data/ext/libuv/src/win/core.c +278 -0
- data/ext/libuv/src/win/dl.c +86 -0
- data/ext/libuv/src/win/error.c +155 -0
- data/ext/libuv/src/win/fs-event.c +510 -0
- data/ext/libuv/src/win/fs.c +1948 -0
- data/ext/libuv/src/win/getaddrinfo.c +365 -0
- data/ext/libuv/src/win/handle-inl.h +149 -0
- data/ext/libuv/src/win/handle.c +154 -0
- data/ext/libuv/src/win/internal.h +343 -0
- data/ext/libuv/src/win/loop-watcher.c +122 -0
- data/ext/libuv/src/win/pipe.c +1672 -0
- data/ext/libuv/src/win/poll.c +616 -0
- data/ext/libuv/src/win/process-stdio.c +500 -0
- data/ext/libuv/src/win/process.c +1013 -0
- data/ext/libuv/src/win/req-inl.h +220 -0
- data/ext/libuv/src/win/req.c +25 -0
- data/ext/libuv/src/win/signal.c +57 -0
- data/ext/libuv/src/win/stream-inl.h +67 -0
- data/ext/libuv/src/win/stream.c +167 -0
- data/ext/libuv/src/win/tcp.c +1394 -0
- data/ext/libuv/src/win/thread.c +372 -0
- data/ext/libuv/src/win/threadpool.c +74 -0
- data/ext/libuv/src/win/timer.c +224 -0
- data/ext/libuv/src/win/tty.c +1799 -0
- data/ext/libuv/src/win/udp.c +716 -0
- data/ext/libuv/src/win/util.c +864 -0
- data/ext/libuv/src/win/winapi.c +132 -0
- data/ext/libuv/src/win/winapi.h +4452 -0
- data/ext/libuv/src/win/winsock.c +557 -0
- data/ext/libuv/src/win/winsock.h +171 -0
- data/ext/libuv/test/benchmark-async-pummel.c +97 -0
- data/ext/libuv/test/benchmark-async.c +137 -0
- data/ext/libuv/test/benchmark-fs-stat.c +135 -0
- data/ext/libuv/test/benchmark-getaddrinfo.c +94 -0
- data/ext/libuv/test/benchmark-list.h +127 -0
- data/ext/libuv/test/benchmark-loop-count.c +88 -0
- data/ext/libuv/test/benchmark-million-timers.c +65 -0
- data/ext/libuv/test/benchmark-ping-pongs.c +213 -0
- data/ext/libuv/test/benchmark-pound.c +324 -0
- data/ext/libuv/test/benchmark-pump.c +462 -0
- data/ext/libuv/test/benchmark-sizes.c +44 -0
- data/ext/libuv/test/benchmark-spawn.c +162 -0
- data/ext/libuv/test/benchmark-tcp-write-batch.c +140 -0
- data/ext/libuv/test/benchmark-thread.c +64 -0
- data/ext/libuv/test/benchmark-udp-packet-storm.c +247 -0
- data/ext/libuv/test/blackhole-server.c +118 -0
- data/ext/libuv/test/dns-server.c +321 -0
- data/ext/libuv/test/echo-server.c +378 -0
- data/ext/libuv/test/fixtures/empty_file +0 -0
- data/ext/libuv/test/fixtures/load_error.node +1 -0
- data/ext/libuv/test/run-benchmarks.c +64 -0
- data/ext/libuv/test/run-tests.c +138 -0
- data/ext/libuv/test/runner-unix.c +295 -0
- data/ext/libuv/test/runner-unix.h +36 -0
- data/ext/libuv/test/runner-win.c +285 -0
- data/ext/libuv/test/runner-win.h +42 -0
- data/ext/libuv/test/runner.c +355 -0
- data/ext/libuv/test/runner.h +159 -0
- data/ext/libuv/test/task.h +112 -0
- data/ext/libuv/test/test-async.c +118 -0
- data/ext/libuv/test/test-callback-order.c +76 -0
- data/ext/libuv/test/test-callback-stack.c +203 -0
- data/ext/libuv/test/test-connection-fail.c +148 -0
- data/ext/libuv/test/test-cwd-and-chdir.c +64 -0
- data/ext/libuv/test/test-delayed-accept.c +188 -0
- data/ext/libuv/test/test-dlerror.c +58 -0
- data/ext/libuv/test/test-error.c +59 -0
- data/ext/libuv/test/test-fail-always.c +29 -0
- data/ext/libuv/test/test-fs-event.c +474 -0
- data/ext/libuv/test/test-fs-poll.c +146 -0
- data/ext/libuv/test/test-fs.c +1843 -0
- data/ext/libuv/test/test-get-currentexe.c +63 -0
- data/ext/libuv/test/test-get-loadavg.c +36 -0
- data/ext/libuv/test/test-get-memory.c +38 -0
- data/ext/libuv/test/test-getaddrinfo.c +122 -0
- data/ext/libuv/test/test-getsockname.c +342 -0
- data/ext/libuv/test/test-hrtime.c +54 -0
- data/ext/libuv/test/test-idle.c +81 -0
- data/ext/libuv/test/test-ipc-send-recv.c +209 -0
- data/ext/libuv/test/test-ipc.c +620 -0
- data/ext/libuv/test/test-list.h +427 -0
- data/ext/libuv/test/test-loop-handles.c +336 -0
- data/ext/libuv/test/test-multiple-listen.c +102 -0
- data/ext/libuv/test/test-mutexes.c +63 -0
- data/ext/libuv/test/test-pass-always.c +28 -0
- data/ext/libuv/test/test-ping-pong.c +253 -0
- data/ext/libuv/test/test-pipe-bind-error.c +140 -0
- data/ext/libuv/test/test-pipe-connect-error.c +96 -0
- data/ext/libuv/test/test-platform-output.c +87 -0
- data/ext/libuv/test/test-poll-close.c +72 -0
- data/ext/libuv/test/test-poll.c +573 -0
- data/ext/libuv/test/test-process-title.c +49 -0
- data/ext/libuv/test/test-ref.c +338 -0
- data/ext/libuv/test/test-run-once.c +48 -0
- data/ext/libuv/test/test-semaphore.c +111 -0
- data/ext/libuv/test/test-shutdown-close.c +103 -0
- data/ext/libuv/test/test-shutdown-eof.c +183 -0
- data/ext/libuv/test/test-signal.c +162 -0
- data/ext/libuv/test/test-spawn.c +863 -0
- data/ext/libuv/test/test-stdio-over-pipes.c +246 -0
- data/ext/libuv/test/test-tcp-bind-error.c +191 -0
- data/ext/libuv/test/test-tcp-bind6-error.c +154 -0
- data/ext/libuv/test/test-tcp-close-while-connecting.c +80 -0
- data/ext/libuv/test/test-tcp-close.c +129 -0
- data/ext/libuv/test/test-tcp-connect-error-after-write.c +95 -0
- data/ext/libuv/test/test-tcp-connect-error.c +70 -0
- data/ext/libuv/test/test-tcp-connect-timeout.c +85 -0
- data/ext/libuv/test/test-tcp-connect6-error.c +68 -0
- data/ext/libuv/test/test-tcp-flags.c +51 -0
- data/ext/libuv/test/test-tcp-shutdown-after-write.c +131 -0
- data/ext/libuv/test/test-tcp-unexpected-read.c +113 -0
- data/ext/libuv/test/test-tcp-write-error.c +168 -0
- data/ext/libuv/test/test-tcp-write-to-half-open-connection.c +135 -0
- data/ext/libuv/test/test-tcp-writealot.c +170 -0
- data/ext/libuv/test/test-thread.c +183 -0
- data/ext/libuv/test/test-threadpool.c +57 -0
- data/ext/libuv/test/test-timer-again.c +141 -0
- data/ext/libuv/test/test-timer.c +152 -0
- data/ext/libuv/test/test-tty.c +110 -0
- data/ext/libuv/test/test-udp-dgram-too-big.c +86 -0
- data/ext/libuv/test/test-udp-ipv6.c +156 -0
- data/ext/libuv/test/test-udp-multicast-join.c +139 -0
- data/ext/libuv/test/test-udp-multicast-ttl.c +86 -0
- data/ext/libuv/test/test-udp-options.c +86 -0
- data/ext/libuv/test/test-udp-send-and-recv.c +208 -0
- data/ext/libuv/test/test-util.c +97 -0
- data/ext/libuv/test/test-walk-handles.c +77 -0
- data/ext/libuv/uv.gyp +375 -0
- data/ext/libuv/vcbuild.bat +105 -0
- data/foolio.gemspec +18 -0
- data/lib/foolio.rb +9 -0
- data/lib/foolio/handle.rb +27 -0
- data/lib/foolio/listener.rb +26 -0
- data/lib/foolio/loop.rb +79 -0
- data/lib/foolio/stream.rb +109 -0
- data/lib/foolio/version.rb +3 -0
- metadata +309 -0
@@ -0,0 +1,235 @@
|
|
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 "uv-common.h"
|
24
|
+
|
25
|
+
#include <assert.h>
|
26
|
+
#include <stdlib.h>
|
27
|
+
#include <string.h>
|
28
|
+
|
29
|
+
static int statbuf_eq(const uv_statbuf_t* a, const uv_statbuf_t* b);
|
30
|
+
static void timer_cb(uv_timer_t* timer, int status);
|
31
|
+
static void poll_cb(uv_fs_t* req);
|
32
|
+
|
33
|
+
static uv_statbuf_t zero_statbuf;
|
34
|
+
|
35
|
+
|
36
|
+
int uv_fs_poll_init(uv_loop_t* loop, uv_fs_poll_t* handle) {
|
37
|
+
/* TODO(bnoordhuis) Mark fs_req internal. */
|
38
|
+
uv__handle_init(loop, (uv_handle_t*)handle, UV_FS_POLL);
|
39
|
+
if (uv_timer_init(loop, &handle->timer_handle))
|
40
|
+
return -1;
|
41
|
+
|
42
|
+
handle->timer_handle.flags |= UV__HANDLE_INTERNAL;
|
43
|
+
uv__handle_unref(&handle->timer_handle);
|
44
|
+
|
45
|
+
return 0;
|
46
|
+
}
|
47
|
+
|
48
|
+
|
49
|
+
int uv_fs_poll_start(uv_fs_poll_t* handle,
|
50
|
+
uv_fs_poll_cb cb,
|
51
|
+
const char* path,
|
52
|
+
unsigned int interval) {
|
53
|
+
uv_fs_t* req;
|
54
|
+
size_t len;
|
55
|
+
|
56
|
+
if (uv__is_active(handle))
|
57
|
+
return 0;
|
58
|
+
|
59
|
+
len = strlen(path) + 1;
|
60
|
+
req = malloc(sizeof(*req) + len);
|
61
|
+
|
62
|
+
if (req == NULL)
|
63
|
+
return uv__set_artificial_error(handle->loop, UV_ENOMEM);
|
64
|
+
|
65
|
+
req->data = handle;
|
66
|
+
handle->path = memcpy(req + 1, path, len);
|
67
|
+
handle->fs_req = req;
|
68
|
+
handle->poll_cb = cb;
|
69
|
+
handle->interval = interval ? interval : 1;
|
70
|
+
handle->start_time = uv_now(handle->loop);
|
71
|
+
handle->busy_polling = 0;
|
72
|
+
memset(&handle->statbuf, 0, sizeof(handle->statbuf));
|
73
|
+
|
74
|
+
if (uv_fs_stat(handle->loop, handle->fs_req, handle->path, poll_cb))
|
75
|
+
abort();
|
76
|
+
|
77
|
+
uv__handle_start(handle);
|
78
|
+
|
79
|
+
return 0;
|
80
|
+
}
|
81
|
+
|
82
|
+
|
83
|
+
int uv_fs_poll_stop(uv_fs_poll_t* handle) {
|
84
|
+
if (!uv__is_active(handle))
|
85
|
+
return 0;
|
86
|
+
|
87
|
+
/* Don't free the fs req if it's active. Signal poll_cb that it needs to free
|
88
|
+
* the req by removing the handle backlink.
|
89
|
+
*
|
90
|
+
* TODO(bnoordhuis) Have uv-unix postpone the close callback until the req
|
91
|
+
* finishes so we don't need this pointer / lifecycle hackery. The callback
|
92
|
+
* always runs on the next tick now.
|
93
|
+
*/
|
94
|
+
if (handle->fs_req->data)
|
95
|
+
handle->fs_req->data = NULL;
|
96
|
+
else
|
97
|
+
free(handle->fs_req);
|
98
|
+
|
99
|
+
handle->fs_req = NULL;
|
100
|
+
handle->path = NULL;
|
101
|
+
|
102
|
+
uv_timer_stop(&handle->timer_handle);
|
103
|
+
uv__handle_stop(handle);
|
104
|
+
|
105
|
+
return 0;
|
106
|
+
}
|
107
|
+
|
108
|
+
|
109
|
+
void uv__fs_poll_close(uv_fs_poll_t* handle) {
|
110
|
+
uv_fs_poll_stop(handle);
|
111
|
+
uv_close((uv_handle_t*)&handle->timer_handle, NULL);
|
112
|
+
}
|
113
|
+
|
114
|
+
|
115
|
+
static void timer_cb(uv_timer_t* timer, int status) {
|
116
|
+
uv_fs_poll_t* handle;
|
117
|
+
|
118
|
+
handle = container_of(timer, uv_fs_poll_t, timer_handle);
|
119
|
+
handle->start_time = uv_now(handle->loop);
|
120
|
+
handle->fs_req->data = handle;
|
121
|
+
|
122
|
+
if (uv_fs_stat(handle->loop, handle->fs_req, handle->path, poll_cb))
|
123
|
+
abort();
|
124
|
+
|
125
|
+
assert(uv__is_active(handle));
|
126
|
+
}
|
127
|
+
|
128
|
+
|
129
|
+
static void poll_cb(uv_fs_t* req) {
|
130
|
+
uv_statbuf_t* statbuf;
|
131
|
+
uv_fs_poll_t* handle;
|
132
|
+
uint64_t interval;
|
133
|
+
|
134
|
+
handle = req->data;
|
135
|
+
|
136
|
+
if (handle == NULL) /* Handle has been stopped or closed. */
|
137
|
+
goto out;
|
138
|
+
|
139
|
+
assert(req == handle->fs_req);
|
140
|
+
|
141
|
+
if (req->result != 0) {
|
142
|
+
if (handle->busy_polling != -req->errorno) {
|
143
|
+
uv__set_artificial_error(handle->loop, req->errorno);
|
144
|
+
handle->poll_cb(handle, -1, &handle->statbuf, &zero_statbuf);
|
145
|
+
handle->busy_polling = -req->errorno;
|
146
|
+
}
|
147
|
+
goto out;
|
148
|
+
}
|
149
|
+
|
150
|
+
statbuf = req->ptr;
|
151
|
+
|
152
|
+
if (handle->busy_polling != 0)
|
153
|
+
if (handle->busy_polling < 0 || !statbuf_eq(&handle->statbuf, statbuf))
|
154
|
+
handle->poll_cb(handle, 0, &handle->statbuf, statbuf);
|
155
|
+
|
156
|
+
handle->statbuf = *statbuf;
|
157
|
+
handle->busy_polling = 1;
|
158
|
+
|
159
|
+
out:
|
160
|
+
uv_fs_req_cleanup(req);
|
161
|
+
|
162
|
+
if (req->data == NULL) { /* Handle has been stopped or closed. */
|
163
|
+
free(req);
|
164
|
+
return;
|
165
|
+
}
|
166
|
+
|
167
|
+
req->data = NULL; /* Tell uv_fs_poll_stop() it's safe to free the req. */
|
168
|
+
|
169
|
+
/* Reschedule timer, subtract the delay from doing the stat(). */
|
170
|
+
interval = handle->interval;
|
171
|
+
interval -= (uv_now(handle->loop) - handle->start_time) % interval;
|
172
|
+
|
173
|
+
if (uv_timer_start(&handle->timer_handle, timer_cb, interval, 0))
|
174
|
+
abort();
|
175
|
+
}
|
176
|
+
|
177
|
+
|
178
|
+
static int statbuf_eq(const uv_statbuf_t* a, const uv_statbuf_t* b) {
|
179
|
+
#ifdef _WIN32
|
180
|
+
return a->st_mtime == b->st_mtime
|
181
|
+
&& a->st_size == b->st_size
|
182
|
+
&& a->st_mode == b->st_mode;
|
183
|
+
#else
|
184
|
+
|
185
|
+
/* Jump through a few hoops to get sub-second granularity on Linux. */
|
186
|
+
# if __linux__
|
187
|
+
# if __USE_MISC /* _BSD_SOURCE || _SVID_SOURCE */
|
188
|
+
if (a->st_ctim.tv_nsec != b->st_ctim.tv_nsec) return 0;
|
189
|
+
if (a->st_mtim.tv_nsec != b->st_mtim.tv_nsec) return 0;
|
190
|
+
# else
|
191
|
+
if (a->st_ctimensec != b->st_ctimensec) return 0;
|
192
|
+
if (a->st_mtimensec != b->st_mtimensec) return 0;
|
193
|
+
# endif
|
194
|
+
# endif
|
195
|
+
|
196
|
+
/* Jump through different hoops on OS X. */
|
197
|
+
# if __APPLE__
|
198
|
+
# if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
|
199
|
+
if (a->st_ctimespec.tv_nsec != b->st_ctimespec.tv_nsec) return 0;
|
200
|
+
if (a->st_mtimespec.tv_nsec != b->st_mtimespec.tv_nsec) return 0;
|
201
|
+
# else
|
202
|
+
if (a->st_ctimensec != b->st_ctimensec) return 0;
|
203
|
+
if (a->st_mtimensec != b->st_mtimensec) return 0;
|
204
|
+
# endif
|
205
|
+
# endif
|
206
|
+
|
207
|
+
/* TODO(bnoordhuis) Other Unices have st_ctim and friends too, provided
|
208
|
+
* the stars and compiler flags are right...
|
209
|
+
*/
|
210
|
+
|
211
|
+
return a->st_ctime == b->st_ctime
|
212
|
+
&& a->st_mtime == b->st_mtime
|
213
|
+
&& a->st_size == b->st_size
|
214
|
+
&& a->st_mode == b->st_mode
|
215
|
+
&& a->st_uid == b->st_uid
|
216
|
+
&& a->st_gid == b->st_gid
|
217
|
+
&& a->st_ino == b->st_ino
|
218
|
+
&& a->st_dev == b->st_dev;
|
219
|
+
#endif
|
220
|
+
}
|
221
|
+
|
222
|
+
|
223
|
+
#ifdef _WIN32
|
224
|
+
|
225
|
+
#include "win/internal.h"
|
226
|
+
#include "win/handle-inl.h"
|
227
|
+
|
228
|
+
void uv__fs_poll_endgame(uv_loop_t* loop, uv_fs_poll_t* handle) {
|
229
|
+
assert(handle->flags & UV_HANDLE_CLOSING);
|
230
|
+
assert(!(handle->flags & UV_HANDLE_CLOSED));
|
231
|
+
uv__handle_stop(handle);
|
232
|
+
uv__handle_close(handle);
|
233
|
+
}
|
234
|
+
|
235
|
+
#endif /* _WIN32 */
|
@@ -0,0 +1,293 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
|
3
|
+
* Copyright (c) 1996-1999 by Internet Software Consortium.
|
4
|
+
*
|
5
|
+
* Permission to use, copy, modify, and distribute this software for any
|
6
|
+
* purpose with or without fee is hereby granted, provided that the above
|
7
|
+
* copyright notice and this permission notice appear in all copies.
|
8
|
+
*
|
9
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
|
10
|
+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
11
|
+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
|
12
|
+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
13
|
+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
14
|
+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
15
|
+
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
16
|
+
*/
|
17
|
+
|
18
|
+
#include <stdio.h>
|
19
|
+
#include <stdint.h>
|
20
|
+
#include <string.h>
|
21
|
+
|
22
|
+
#include "uv.h"
|
23
|
+
#include "uv-common.h"
|
24
|
+
|
25
|
+
|
26
|
+
static const uv_err_t uv_eafnosupport_ = { UV_EAFNOSUPPORT, 0 };
|
27
|
+
static const uv_err_t uv_enospc_ = { UV_ENOSPC, 0 };
|
28
|
+
static const uv_err_t uv_einval_ = { UV_EINVAL, 0 };
|
29
|
+
|
30
|
+
static uv_err_t inet_ntop4(const unsigned char *src, char *dst, size_t size);
|
31
|
+
static uv_err_t inet_ntop6(const unsigned char *src, char *dst, size_t size);
|
32
|
+
static uv_err_t inet_pton4(const char *src, unsigned char *dst);
|
33
|
+
static uv_err_t inet_pton6(const char *src, unsigned char *dst);
|
34
|
+
|
35
|
+
|
36
|
+
uv_err_t uv_inet_ntop(int af, const void* src, char* dst, size_t size) {
|
37
|
+
switch (af) {
|
38
|
+
case AF_INET:
|
39
|
+
return (inet_ntop4(src, dst, size));
|
40
|
+
case AF_INET6:
|
41
|
+
return (inet_ntop6(src, dst, size));
|
42
|
+
default:
|
43
|
+
return uv_eafnosupport_;
|
44
|
+
}
|
45
|
+
/* NOTREACHED */
|
46
|
+
}
|
47
|
+
|
48
|
+
|
49
|
+
static uv_err_t inet_ntop4(const unsigned char *src, char *dst, size_t size) {
|
50
|
+
static const char fmt[] = "%u.%u.%u.%u";
|
51
|
+
char tmp[sizeof "255.255.255.255"];
|
52
|
+
size_t l;
|
53
|
+
|
54
|
+
#ifndef _WIN32
|
55
|
+
l = snprintf(tmp, sizeof(tmp), fmt, src[0], src[1], src[2], src[3]);
|
56
|
+
#else
|
57
|
+
l = _snprintf(tmp, sizeof(tmp), fmt, src[0], src[1], src[2], src[3]);
|
58
|
+
#endif
|
59
|
+
if (l <= 0 || l >= size) {
|
60
|
+
return uv_enospc_;
|
61
|
+
}
|
62
|
+
strncpy(dst, tmp, size);
|
63
|
+
dst[size - 1] = '\0';
|
64
|
+
return uv_ok_;
|
65
|
+
}
|
66
|
+
|
67
|
+
|
68
|
+
static uv_err_t inet_ntop6(const unsigned char *src, char *dst, size_t size) {
|
69
|
+
/*
|
70
|
+
* Note that int32_t and int16_t need only be "at least" large enough
|
71
|
+
* to contain a value of the specified size. On some systems, like
|
72
|
+
* Crays, there is no such thing as an integer variable with 16 bits.
|
73
|
+
* Keep this in mind if you think this function should have been coded
|
74
|
+
* to use pointer overlays. All the world's not a VAX.
|
75
|
+
*/
|
76
|
+
char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp;
|
77
|
+
struct { int base, len; } best, cur;
|
78
|
+
unsigned int words[sizeof(struct in6_addr) / sizeof(uint16_t)];
|
79
|
+
int i;
|
80
|
+
|
81
|
+
/*
|
82
|
+
* Preprocess:
|
83
|
+
* Copy the input (bytewise) array into a wordwise array.
|
84
|
+
* Find the longest run of 0x00's in src[] for :: shorthanding.
|
85
|
+
*/
|
86
|
+
memset(words, '\0', sizeof words);
|
87
|
+
for (i = 0; i < (int) sizeof(struct in6_addr); i++)
|
88
|
+
words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3));
|
89
|
+
best.base = -1;
|
90
|
+
best.len = 0;
|
91
|
+
cur.base = -1;
|
92
|
+
cur.len = 0;
|
93
|
+
for (i = 0; i < (int) ARRAY_SIZE(words); i++) {
|
94
|
+
if (words[i] == 0) {
|
95
|
+
if (cur.base == -1)
|
96
|
+
cur.base = i, cur.len = 1;
|
97
|
+
else
|
98
|
+
cur.len++;
|
99
|
+
} else {
|
100
|
+
if (cur.base != -1) {
|
101
|
+
if (best.base == -1 || cur.len > best.len)
|
102
|
+
best = cur;
|
103
|
+
cur.base = -1;
|
104
|
+
}
|
105
|
+
}
|
106
|
+
}
|
107
|
+
if (cur.base != -1) {
|
108
|
+
if (best.base == -1 || cur.len > best.len)
|
109
|
+
best = cur;
|
110
|
+
}
|
111
|
+
if (best.base != -1 && best.len < 2)
|
112
|
+
best.base = -1;
|
113
|
+
|
114
|
+
/*
|
115
|
+
* Format the result.
|
116
|
+
*/
|
117
|
+
tp = tmp;
|
118
|
+
for (i = 0; i < (int) ARRAY_SIZE(words); i++) {
|
119
|
+
/* Are we inside the best run of 0x00's? */
|
120
|
+
if (best.base != -1 && i >= best.base &&
|
121
|
+
i < (best.base + best.len)) {
|
122
|
+
if (i == best.base)
|
123
|
+
*tp++ = ':';
|
124
|
+
continue;
|
125
|
+
}
|
126
|
+
/* Are we following an initial run of 0x00s or any real hex? */
|
127
|
+
if (i != 0)
|
128
|
+
*tp++ = ':';
|
129
|
+
/* Is this address an encapsulated IPv4? */
|
130
|
+
if (i == 6 && best.base == 0 && (best.len == 6 ||
|
131
|
+
(best.len == 7 && words[7] != 0x0001) ||
|
132
|
+
(best.len == 5 && words[5] == 0xffff))) {
|
133
|
+
uv_err_t err = inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp));
|
134
|
+
if (err.code != UV_OK)
|
135
|
+
return err;
|
136
|
+
tp += strlen(tp);
|
137
|
+
break;
|
138
|
+
}
|
139
|
+
tp += sprintf(tp, "%x", words[i]);
|
140
|
+
}
|
141
|
+
/* Was it a trailing run of 0x00's? */
|
142
|
+
if (best.base != -1 && (best.base + best.len) == ARRAY_SIZE(words))
|
143
|
+
*tp++ = ':';
|
144
|
+
*tp++ = '\0';
|
145
|
+
|
146
|
+
/*
|
147
|
+
* Check for overflow, copy, and we're done.
|
148
|
+
*/
|
149
|
+
if ((size_t)(tp - tmp) > size) {
|
150
|
+
return uv_enospc_;
|
151
|
+
}
|
152
|
+
strcpy(dst, tmp);
|
153
|
+
return uv_ok_;
|
154
|
+
}
|
155
|
+
|
156
|
+
|
157
|
+
uv_err_t uv_inet_pton(int af, const char* src, void* dst) {
|
158
|
+
switch (af) {
|
159
|
+
case AF_INET:
|
160
|
+
return (inet_pton4(src, dst));
|
161
|
+
case AF_INET6:
|
162
|
+
return (inet_pton6(src, dst));
|
163
|
+
default:
|
164
|
+
return uv_eafnosupport_;
|
165
|
+
}
|
166
|
+
/* NOTREACHED */
|
167
|
+
}
|
168
|
+
|
169
|
+
|
170
|
+
static uv_err_t inet_pton4(const char *src, unsigned char *dst) {
|
171
|
+
static const char digits[] = "0123456789";
|
172
|
+
int saw_digit, octets, ch;
|
173
|
+
unsigned char tmp[sizeof(struct in_addr)], *tp;
|
174
|
+
|
175
|
+
saw_digit = 0;
|
176
|
+
octets = 0;
|
177
|
+
*(tp = tmp) = 0;
|
178
|
+
while ((ch = *src++) != '\0') {
|
179
|
+
const char *pch;
|
180
|
+
|
181
|
+
if ((pch = strchr(digits, ch)) != NULL) {
|
182
|
+
unsigned int nw = *tp * 10 + (pch - digits);
|
183
|
+
|
184
|
+
if (saw_digit && *tp == 0)
|
185
|
+
return uv_einval_;
|
186
|
+
if (nw > 255)
|
187
|
+
return uv_einval_;
|
188
|
+
*tp = nw;
|
189
|
+
if (!saw_digit) {
|
190
|
+
if (++octets > 4)
|
191
|
+
return uv_einval_;
|
192
|
+
saw_digit = 1;
|
193
|
+
}
|
194
|
+
} else if (ch == '.' && saw_digit) {
|
195
|
+
if (octets == 4)
|
196
|
+
return uv_einval_;
|
197
|
+
*++tp = 0;
|
198
|
+
saw_digit = 0;
|
199
|
+
} else
|
200
|
+
return uv_einval_;
|
201
|
+
}
|
202
|
+
if (octets < 4)
|
203
|
+
return uv_einval_;
|
204
|
+
memcpy(dst, tmp, sizeof(struct in_addr));
|
205
|
+
return uv_ok_;
|
206
|
+
}
|
207
|
+
|
208
|
+
|
209
|
+
static uv_err_t inet_pton6(const char *src, unsigned char *dst) {
|
210
|
+
static const char xdigits_l[] = "0123456789abcdef",
|
211
|
+
xdigits_u[] = "0123456789ABCDEF";
|
212
|
+
unsigned char tmp[sizeof(struct in6_addr)], *tp, *endp, *colonp;
|
213
|
+
const char *xdigits, *curtok;
|
214
|
+
int ch, seen_xdigits;
|
215
|
+
unsigned int val;
|
216
|
+
|
217
|
+
memset((tp = tmp), '\0', sizeof tmp);
|
218
|
+
endp = tp + sizeof tmp;
|
219
|
+
colonp = NULL;
|
220
|
+
/* Leading :: requires some special handling. */
|
221
|
+
if (*src == ':')
|
222
|
+
if (*++src != ':')
|
223
|
+
return uv_einval_;
|
224
|
+
curtok = src;
|
225
|
+
seen_xdigits = 0;
|
226
|
+
val = 0;
|
227
|
+
while ((ch = *src++) != '\0') {
|
228
|
+
const char *pch;
|
229
|
+
|
230
|
+
if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
|
231
|
+
pch = strchr((xdigits = xdigits_u), ch);
|
232
|
+
if (pch != NULL) {
|
233
|
+
val <<= 4;
|
234
|
+
val |= (pch - xdigits);
|
235
|
+
if (++seen_xdigits > 4)
|
236
|
+
return uv_einval_;
|
237
|
+
continue;
|
238
|
+
}
|
239
|
+
if (ch == ':') {
|
240
|
+
curtok = src;
|
241
|
+
if (!seen_xdigits) {
|
242
|
+
if (colonp)
|
243
|
+
return uv_einval_;
|
244
|
+
colonp = tp;
|
245
|
+
continue;
|
246
|
+
} else if (*src == '\0') {
|
247
|
+
return uv_einval_;
|
248
|
+
}
|
249
|
+
if (tp + sizeof(uint16_t) > endp)
|
250
|
+
return uv_einval_;
|
251
|
+
*tp++ = (unsigned char) (val >> 8) & 0xff;
|
252
|
+
*tp++ = (unsigned char) val & 0xff;
|
253
|
+
seen_xdigits = 0;
|
254
|
+
val = 0;
|
255
|
+
continue;
|
256
|
+
}
|
257
|
+
if (ch == '.' && ((tp + sizeof(struct in_addr)) <= endp)) {
|
258
|
+
uv_err_t err = inet_pton4(curtok, tp);
|
259
|
+
if (err.code == 0) {
|
260
|
+
tp += sizeof(struct in_addr);
|
261
|
+
seen_xdigits = 0;
|
262
|
+
break; /*%< '\\0' was seen by inet_pton4(). */
|
263
|
+
}
|
264
|
+
}
|
265
|
+
return uv_einval_;
|
266
|
+
}
|
267
|
+
if (seen_xdigits) {
|
268
|
+
if (tp + sizeof(uint16_t) > endp)
|
269
|
+
return uv_einval_;
|
270
|
+
*tp++ = (unsigned char) (val >> 8) & 0xff;
|
271
|
+
*tp++ = (unsigned char) val & 0xff;
|
272
|
+
}
|
273
|
+
if (colonp != NULL) {
|
274
|
+
/*
|
275
|
+
* Since some memmove()'s erroneously fail to handle
|
276
|
+
* overlapping regions, we'll do the shift by hand.
|
277
|
+
*/
|
278
|
+
const int n = tp - colonp;
|
279
|
+
int i;
|
280
|
+
|
281
|
+
if (tp == endp)
|
282
|
+
return uv_einval_;
|
283
|
+
for (i = 1; i <= n; i++) {
|
284
|
+
endp[- i] = colonp[n - i];
|
285
|
+
colonp[n - i] = 0;
|
286
|
+
}
|
287
|
+
tp = endp;
|
288
|
+
}
|
289
|
+
if (tp != endp)
|
290
|
+
return uv_einval_;
|
291
|
+
memcpy(dst, tmp, sizeof tmp);
|
292
|
+
return uv_ok_;
|
293
|
+
}
|