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,188 @@
|
|
1
|
+
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
2
|
+
*
|
3
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
* of this software and associated documentation files (the "Software"), to
|
5
|
+
* deal in the Software without restriction, including without limitation the
|
6
|
+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
7
|
+
* sell copies of the Software, and to permit persons to whom the Software is
|
8
|
+
* furnished to do so, subject to the following conditions:
|
9
|
+
*
|
10
|
+
* The above copyright notice and this permission notice shall be included in
|
11
|
+
* all copies or substantial portions of the Software.
|
12
|
+
*
|
13
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
18
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
19
|
+
* IN THE SOFTWARE.
|
20
|
+
*/
|
21
|
+
|
22
|
+
#ifndef UV_UNIX_INTERNAL_H_
|
23
|
+
#define UV_UNIX_INTERNAL_H_
|
24
|
+
|
25
|
+
#include "uv-common.h"
|
26
|
+
#include "uv-eio.h"
|
27
|
+
|
28
|
+
#include <assert.h>
|
29
|
+
#include <stdlib.h> /* abort */
|
30
|
+
|
31
|
+
#if __STRICT_ANSI__
|
32
|
+
# define inline __inline
|
33
|
+
#endif
|
34
|
+
|
35
|
+
#undef HAVE_FUTIMES
|
36
|
+
#undef HAVE_KQUEUE
|
37
|
+
#undef HAVE_PORTS_FS
|
38
|
+
|
39
|
+
#if __linux__
|
40
|
+
# include "linux/syscalls.h"
|
41
|
+
# define HAVE_FUTIMES 1 /* emulated with utimesat() */
|
42
|
+
#endif /* __linux__ */
|
43
|
+
|
44
|
+
#if defined(__sun)
|
45
|
+
# include <sys/port.h>
|
46
|
+
# include <port.h>
|
47
|
+
# ifdef PORT_SOURCE_FILE
|
48
|
+
# define HAVE_PORTS_FS 1
|
49
|
+
# endif
|
50
|
+
# define HAVE_FUTIMES 1
|
51
|
+
# define futimes(fd, tv) futimesat(fd, (void*)0, tv)
|
52
|
+
#endif /* __sun */
|
53
|
+
|
54
|
+
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun)
|
55
|
+
# define HAVE_FUTIMES 1
|
56
|
+
#endif
|
57
|
+
|
58
|
+
/* FIXME exact copy of the #ifdef guard in uv-unix.h */
|
59
|
+
#if defined(__APPLE__) \
|
60
|
+
|| defined(__FreeBSD__) \
|
61
|
+
|| defined(__OpenBSD__) \
|
62
|
+
|| defined(__NetBSD__)
|
63
|
+
# define HAVE_KQUEUE 1
|
64
|
+
#endif
|
65
|
+
|
66
|
+
#define UNREACHABLE() \
|
67
|
+
do { \
|
68
|
+
assert(0 && "unreachable code"); \
|
69
|
+
abort(); \
|
70
|
+
} \
|
71
|
+
while (0)
|
72
|
+
|
73
|
+
#define SAVE_ERRNO(block) \
|
74
|
+
do { \
|
75
|
+
int _saved_errno = errno; \
|
76
|
+
do { block; } while (0); \
|
77
|
+
errno = _saved_errno; \
|
78
|
+
} \
|
79
|
+
while (0)
|
80
|
+
|
81
|
+
#define UV__IO_READ EV_READ
|
82
|
+
#define UV__IO_WRITE EV_WRITE
|
83
|
+
#define UV__IO_ERROR EV_ERROR
|
84
|
+
|
85
|
+
/* handle flags */
|
86
|
+
enum {
|
87
|
+
UV_CLOSING = 0x01, /* uv_close() called but not finished. */
|
88
|
+
UV_CLOSED = 0x02, /* close(2) finished. */
|
89
|
+
UV_STREAM_READING = 0x04, /* uv_read_start() called. */
|
90
|
+
UV_STREAM_SHUTTING = 0x08, /* uv_shutdown() called but not complete. */
|
91
|
+
UV_STREAM_SHUT = 0x10, /* Write side closed. */
|
92
|
+
UV_STREAM_READABLE = 0x20, /* The stream is readable */
|
93
|
+
UV_STREAM_WRITABLE = 0x40, /* The stream is writable */
|
94
|
+
UV_STREAM_BLOCKING = 0x80, /* Synchronous writes. */
|
95
|
+
UV_TCP_NODELAY = 0x100, /* Disable Nagle. */
|
96
|
+
UV_TCP_KEEPALIVE = 0x200, /* Turn on keep-alive. */
|
97
|
+
UV_TCP_SINGLE_ACCEPT = 0x400 /* Only accept() when idle. */
|
98
|
+
};
|
99
|
+
|
100
|
+
/* loop flags */
|
101
|
+
enum {
|
102
|
+
UV_LOOP_EIO_INITIALIZED = 1
|
103
|
+
};
|
104
|
+
|
105
|
+
inline static void uv__req_init(uv_loop_t* loop,
|
106
|
+
uv_req_t* req,
|
107
|
+
uv_req_type type) {
|
108
|
+
req->type = type;
|
109
|
+
uv__req_register(loop, req);
|
110
|
+
}
|
111
|
+
#define uv__req_init(loop, req, type) \
|
112
|
+
uv__req_init((loop), (uv_req_t*)(req), (type))
|
113
|
+
|
114
|
+
/* core */
|
115
|
+
void uv__handle_init(uv_loop_t* loop, uv_handle_t* handle, uv_handle_type type);
|
116
|
+
int uv__nonblock(int fd, int set);
|
117
|
+
int uv__cloexec(int fd, int set);
|
118
|
+
int uv__socket(int domain, int type, int protocol);
|
119
|
+
int uv__dup(int fd);
|
120
|
+
int uv_async_stop(uv_async_t* handle);
|
121
|
+
|
122
|
+
void uv__io_init(uv__io_t* handle, uv__io_cb cb, int fd, int events);
|
123
|
+
void uv__io_set(uv__io_t* handle, uv__io_cb cb, int fd, int events);
|
124
|
+
void uv__io_start(uv_loop_t* loop, uv__io_t* handle);
|
125
|
+
void uv__io_stop(uv_loop_t* loop, uv__io_t* handle);
|
126
|
+
void uv__io_feed(uv_loop_t* loop, uv__io_t* handle, int event);
|
127
|
+
int uv__io_active(uv__io_t* handle);
|
128
|
+
|
129
|
+
/* loop */
|
130
|
+
int uv__loop_init(uv_loop_t* loop, int default_loop);
|
131
|
+
void uv__loop_delete(uv_loop_t* loop);
|
132
|
+
void uv__run_idle(uv_loop_t* loop);
|
133
|
+
void uv__run_check(uv_loop_t* loop);
|
134
|
+
void uv__run_prepare(uv_loop_t* loop);
|
135
|
+
|
136
|
+
/* error */
|
137
|
+
uv_err_code uv_translate_sys_error(int sys_errno);
|
138
|
+
void uv_fatal_error(const int errorno, const char* syscall);
|
139
|
+
|
140
|
+
/* stream */
|
141
|
+
void uv__stream_init(uv_loop_t* loop, uv_stream_t* stream,
|
142
|
+
uv_handle_type type);
|
143
|
+
int uv__stream_open(uv_stream_t*, int fd, int flags);
|
144
|
+
void uv__stream_destroy(uv_stream_t* stream);
|
145
|
+
void uv__server_io(uv_loop_t* loop, uv__io_t* watcher, int events);
|
146
|
+
int uv__accept(int sockfd);
|
147
|
+
|
148
|
+
/* tcp */
|
149
|
+
int uv_tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb);
|
150
|
+
int uv__tcp_nodelay(uv_tcp_t* handle, int enable);
|
151
|
+
int uv__tcp_keepalive(uv_tcp_t* handle, int enable, unsigned int delay);
|
152
|
+
|
153
|
+
/* pipe */
|
154
|
+
int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb);
|
155
|
+
|
156
|
+
/* timer */
|
157
|
+
void uv__run_timers(uv_loop_t* loop);
|
158
|
+
unsigned int uv__next_timeout(uv_loop_t* loop);
|
159
|
+
|
160
|
+
/* signal */
|
161
|
+
void uv__signal_close(uv_signal_t* handle);
|
162
|
+
void uv__signal_unregister(uv_loop_t* loop);
|
163
|
+
|
164
|
+
/* various */
|
165
|
+
void uv__async_close(uv_async_t* handle);
|
166
|
+
void uv__check_close(uv_check_t* handle);
|
167
|
+
void uv__fs_event_close(uv_fs_event_t* handle);
|
168
|
+
void uv__idle_close(uv_idle_t* handle);
|
169
|
+
void uv__pipe_close(uv_pipe_t* handle);
|
170
|
+
void uv__poll_close(uv_poll_t* handle);
|
171
|
+
void uv__prepare_close(uv_prepare_t* handle);
|
172
|
+
void uv__process_close(uv_process_t* handle);
|
173
|
+
void uv__stream_close(uv_stream_t* handle);
|
174
|
+
void uv__tcp_close(uv_tcp_t* handle);
|
175
|
+
void uv__timer_close(uv_timer_t* handle);
|
176
|
+
void uv__udp_close(uv_udp_t* handle);
|
177
|
+
void uv__udp_finish_close(uv_udp_t* handle);
|
178
|
+
|
179
|
+
#ifdef UV__O_NONBLOCK
|
180
|
+
# define UV__F_NONBLOCK UV__O_NONBLOCK
|
181
|
+
#else
|
182
|
+
# define UV__F_NONBLOCK 1
|
183
|
+
#endif
|
184
|
+
|
185
|
+
int uv__make_socketpair(int fds[2], int flags);
|
186
|
+
int uv__make_pipe(int fds[2], int flags);
|
187
|
+
|
188
|
+
#endif /* UV_UNIX_INTERNAL_H_ */
|
@@ -0,0 +1,120 @@
|
|
1
|
+
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
2
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
3
|
+
* of this software and associated documentation files (the "Software"), to
|
4
|
+
* deal in the Software without restriction, including without limitation the
|
5
|
+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
6
|
+
* sell copies of the Software, and to permit persons to whom the Software is
|
7
|
+
* furnished to do so, subject to the following conditions:
|
8
|
+
*
|
9
|
+
* The above copyright notice and this permission notice shall be included in
|
10
|
+
* all copies or substantial portions of the Software.
|
11
|
+
*
|
12
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
13
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
14
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
15
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
16
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
17
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
18
|
+
* IN THE SOFTWARE.
|
19
|
+
*/
|
20
|
+
|
21
|
+
#include "uv.h"
|
22
|
+
#include "internal.h"
|
23
|
+
|
24
|
+
#include <assert.h>
|
25
|
+
#include <stdlib.h>
|
26
|
+
#include <string.h>
|
27
|
+
#include <errno.h>
|
28
|
+
|
29
|
+
#include <sys/sysctl.h>
|
30
|
+
#include <sys/types.h>
|
31
|
+
#include <sys/event.h>
|
32
|
+
#include <unistd.h>
|
33
|
+
#include <fcntl.h>
|
34
|
+
#include <time.h>
|
35
|
+
|
36
|
+
static void uv__fs_event(EV_P_ ev_io* w, int revents);
|
37
|
+
|
38
|
+
|
39
|
+
static void uv__fs_event_start(uv_fs_event_t* handle) {
|
40
|
+
ev_io_init(&handle->event_watcher,
|
41
|
+
uv__fs_event,
|
42
|
+
handle->fd,
|
43
|
+
EV_LIBUV_KQUEUE_HACK);
|
44
|
+
ev_io_start(handle->loop->ev, &handle->event_watcher);
|
45
|
+
}
|
46
|
+
|
47
|
+
|
48
|
+
static void uv__fs_event_stop(uv_fs_event_t* handle) {
|
49
|
+
ev_io_stop(handle->loop->ev, &handle->event_watcher);
|
50
|
+
}
|
51
|
+
|
52
|
+
|
53
|
+
static void uv__fs_event(EV_P_ ev_io* w, int revents) {
|
54
|
+
uv_fs_event_t* handle;
|
55
|
+
int events;
|
56
|
+
|
57
|
+
assert(revents == EV_LIBUV_KQUEUE_HACK);
|
58
|
+
|
59
|
+
handle = container_of(w, uv_fs_event_t, event_watcher);
|
60
|
+
|
61
|
+
if (handle->fflags & (NOTE_ATTRIB | NOTE_EXTEND))
|
62
|
+
events = UV_CHANGE;
|
63
|
+
else
|
64
|
+
events = UV_RENAME;
|
65
|
+
|
66
|
+
handle->cb(handle, NULL, events, 0);
|
67
|
+
|
68
|
+
if (handle->fd == -1)
|
69
|
+
return;
|
70
|
+
|
71
|
+
/* File watcher operates in one-shot mode, re-arm it. */
|
72
|
+
uv__fs_event_stop(handle);
|
73
|
+
uv__fs_event_start(handle);
|
74
|
+
}
|
75
|
+
|
76
|
+
|
77
|
+
/* Called by libev, don't touch. */
|
78
|
+
void uv__kqueue_hack(EV_P_ int fflags, ev_io *w) {
|
79
|
+
uv_fs_event_t* handle;
|
80
|
+
|
81
|
+
handle = container_of(w, uv_fs_event_t, event_watcher);
|
82
|
+
handle->fflags = fflags;
|
83
|
+
}
|
84
|
+
|
85
|
+
|
86
|
+
int uv_fs_event_init(uv_loop_t* loop,
|
87
|
+
uv_fs_event_t* handle,
|
88
|
+
const char* filename,
|
89
|
+
uv_fs_event_cb cb,
|
90
|
+
int flags) {
|
91
|
+
int fd;
|
92
|
+
|
93
|
+
/* We don't support any flags yet. */
|
94
|
+
assert(!flags);
|
95
|
+
|
96
|
+
/* TODO open asynchronously - but how do we report back errors? */
|
97
|
+
if ((fd = open(filename, O_RDONLY)) == -1) {
|
98
|
+
uv__set_sys_error(loop, errno);
|
99
|
+
return -1;
|
100
|
+
}
|
101
|
+
|
102
|
+
uv__handle_init(loop, (uv_handle_t*)handle, UV_FS_EVENT);
|
103
|
+
uv__handle_start(handle); /* FIXME shouldn't start automatically */
|
104
|
+
handle->filename = strdup(filename);
|
105
|
+
handle->fflags = 0;
|
106
|
+
handle->cb = cb;
|
107
|
+
handle->fd = fd;
|
108
|
+
uv__fs_event_start(handle);
|
109
|
+
|
110
|
+
return 0;
|
111
|
+
}
|
112
|
+
|
113
|
+
|
114
|
+
void uv__fs_event_close(uv_fs_event_t* handle) {
|
115
|
+
uv__fs_event_stop(handle);
|
116
|
+
uv__handle_stop(handle);
|
117
|
+
free(handle->filename);
|
118
|
+
close(handle->fd);
|
119
|
+
handle->fd = -1;
|
120
|
+
}
|
@@ -0,0 +1,239 @@
|
|
1
|
+
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
2
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
3
|
+
* of this software and associated documentation files (the "Software"), to
|
4
|
+
* deal in the Software without restriction, including without limitation the
|
5
|
+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
6
|
+
* sell copies of the Software, and to permit persons to whom the Software is
|
7
|
+
* furnished to do so, subject to the following conditions:
|
8
|
+
*
|
9
|
+
* The above copyright notice and this permission notice shall be included in
|
10
|
+
* all copies or substantial portions of the Software.
|
11
|
+
*
|
12
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
13
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
14
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
15
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
16
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
17
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
18
|
+
* IN THE SOFTWARE.
|
19
|
+
*/
|
20
|
+
|
21
|
+
#include "uv.h"
|
22
|
+
#include "tree.h"
|
23
|
+
#include "../internal.h"
|
24
|
+
#include "syscalls.h"
|
25
|
+
|
26
|
+
#include <stdint.h>
|
27
|
+
#include <stdio.h>
|
28
|
+
#include <stdlib.h>
|
29
|
+
#include <string.h>
|
30
|
+
#include <assert.h>
|
31
|
+
#include <errno.h>
|
32
|
+
|
33
|
+
#include <sys/types.h>
|
34
|
+
#include <unistd.h>
|
35
|
+
|
36
|
+
struct watcher_list {
|
37
|
+
RB_ENTRY(watcher_list) entry;
|
38
|
+
ngx_queue_t watchers;
|
39
|
+
char* path;
|
40
|
+
int wd;
|
41
|
+
};
|
42
|
+
|
43
|
+
struct watcher_root {
|
44
|
+
struct watcher_list* rbh_root;
|
45
|
+
};
|
46
|
+
#define CAST(p) ((struct watcher_root*)(p))
|
47
|
+
|
48
|
+
|
49
|
+
/* Don't look aghast, this is exactly how glibc's basename() works. */
|
50
|
+
static char* basename_r(const char* path) {
|
51
|
+
char* s = strrchr(path, '/');
|
52
|
+
return s ? (s + 1) : (char*)path;
|
53
|
+
}
|
54
|
+
|
55
|
+
|
56
|
+
static int compare_watchers(const struct watcher_list* a,
|
57
|
+
const struct watcher_list* b) {
|
58
|
+
if (a->wd < b->wd) return -1;
|
59
|
+
if (a->wd > b->wd) return 1;
|
60
|
+
return 0;
|
61
|
+
}
|
62
|
+
|
63
|
+
|
64
|
+
RB_GENERATE_STATIC(watcher_root, watcher_list, entry, compare_watchers)
|
65
|
+
|
66
|
+
|
67
|
+
static void uv__inotify_read(uv_loop_t* loop, uv__io_t* w, int revents);
|
68
|
+
|
69
|
+
|
70
|
+
static int new_inotify_fd(void) {
|
71
|
+
int fd;
|
72
|
+
|
73
|
+
fd = uv__inotify_init1(UV__IN_NONBLOCK | UV__IN_CLOEXEC);
|
74
|
+
if (fd != -1)
|
75
|
+
return fd;
|
76
|
+
if (errno != ENOSYS)
|
77
|
+
return -1;
|
78
|
+
|
79
|
+
if ((fd = uv__inotify_init()) == -1)
|
80
|
+
return -1;
|
81
|
+
|
82
|
+
if (uv__cloexec(fd, 1) || uv__nonblock(fd, 1)) {
|
83
|
+
SAVE_ERRNO(close(fd));
|
84
|
+
return -1;
|
85
|
+
}
|
86
|
+
|
87
|
+
return fd;
|
88
|
+
}
|
89
|
+
|
90
|
+
|
91
|
+
static int init_inotify(uv_loop_t* loop) {
|
92
|
+
if (loop->inotify_fd != -1)
|
93
|
+
return 0;
|
94
|
+
|
95
|
+
loop->inotify_fd = new_inotify_fd();
|
96
|
+
if (loop->inotify_fd == -1) {
|
97
|
+
uv__set_sys_error(loop, errno);
|
98
|
+
return -1;
|
99
|
+
}
|
100
|
+
|
101
|
+
uv__io_init(&loop->inotify_read_watcher,
|
102
|
+
uv__inotify_read,
|
103
|
+
loop->inotify_fd,
|
104
|
+
UV__IO_READ);
|
105
|
+
uv__io_start(loop, &loop->inotify_read_watcher);
|
106
|
+
|
107
|
+
return 0;
|
108
|
+
}
|
109
|
+
|
110
|
+
|
111
|
+
static struct watcher_list* find_watcher(uv_loop_t* loop, int wd) {
|
112
|
+
struct watcher_list w;
|
113
|
+
w.wd = wd;
|
114
|
+
return RB_FIND(watcher_root, CAST(&loop->inotify_watchers), &w);
|
115
|
+
}
|
116
|
+
|
117
|
+
|
118
|
+
static void uv__inotify_read(uv_loop_t* loop, uv__io_t* dummy, int events) {
|
119
|
+
const struct uv__inotify_event* e;
|
120
|
+
struct watcher_list* w;
|
121
|
+
uv_fs_event_t* h;
|
122
|
+
ngx_queue_t* q;
|
123
|
+
const char* path;
|
124
|
+
ssize_t size;
|
125
|
+
const char *p;
|
126
|
+
/* needs to be large enough for sizeof(inotify_event) + strlen(filename) */
|
127
|
+
char buf[4096];
|
128
|
+
|
129
|
+
while (1) {
|
130
|
+
do
|
131
|
+
size = read(loop->inotify_fd, buf, sizeof(buf));
|
132
|
+
while (size == -1 && errno == EINTR);
|
133
|
+
|
134
|
+
if (size == -1) {
|
135
|
+
assert(errno == EAGAIN || errno == EWOULDBLOCK);
|
136
|
+
break;
|
137
|
+
}
|
138
|
+
|
139
|
+
assert(size > 0); /* pre-2.6.21 thing, size=0 == read buffer too small */
|
140
|
+
|
141
|
+
/* Now we have one or more inotify_event structs. */
|
142
|
+
for (p = buf; p < buf + size; p += sizeof(*e) + e->len) {
|
143
|
+
e = (const struct uv__inotify_event*)p;
|
144
|
+
|
145
|
+
events = 0;
|
146
|
+
if (e->mask & (UV__IN_ATTRIB|UV__IN_MODIFY))
|
147
|
+
events |= UV_CHANGE;
|
148
|
+
if (e->mask & ~(UV__IN_ATTRIB|UV__IN_MODIFY))
|
149
|
+
events |= UV_RENAME;
|
150
|
+
|
151
|
+
w = find_watcher(loop, e->wd);
|
152
|
+
if (w == NULL)
|
153
|
+
continue; /* Stale event, no watchers left. */
|
154
|
+
|
155
|
+
/* inotify does not return the filename when monitoring a single file
|
156
|
+
* for modifications. Repurpose the filename for API compatibility.
|
157
|
+
* I'm not convinced this is a good thing, maybe it should go.
|
158
|
+
*/
|
159
|
+
path = e->len ? (const char*) (e + 1) : basename_r(w->path);
|
160
|
+
|
161
|
+
ngx_queue_foreach(q, &w->watchers) {
|
162
|
+
h = ngx_queue_data(q, uv_fs_event_t, watchers);
|
163
|
+
h->cb(h, path, events, 0);
|
164
|
+
}
|
165
|
+
}
|
166
|
+
}
|
167
|
+
}
|
168
|
+
|
169
|
+
|
170
|
+
int uv_fs_event_init(uv_loop_t* loop,
|
171
|
+
uv_fs_event_t* handle,
|
172
|
+
const char* path,
|
173
|
+
uv_fs_event_cb cb,
|
174
|
+
int flags) {
|
175
|
+
struct watcher_list* w;
|
176
|
+
int events;
|
177
|
+
int wd;
|
178
|
+
|
179
|
+
/* We don't support any flags yet. */
|
180
|
+
assert(!flags);
|
181
|
+
|
182
|
+
if (init_inotify(loop)) return -1;
|
183
|
+
|
184
|
+
events = UV__IN_ATTRIB
|
185
|
+
| UV__IN_CREATE
|
186
|
+
| UV__IN_MODIFY
|
187
|
+
| UV__IN_DELETE
|
188
|
+
| UV__IN_DELETE_SELF
|
189
|
+
| UV__IN_MOVE_SELF
|
190
|
+
| UV__IN_MOVED_FROM
|
191
|
+
| UV__IN_MOVED_TO;
|
192
|
+
|
193
|
+
wd = uv__inotify_add_watch(loop->inotify_fd, path, events);
|
194
|
+
if (wd == -1)
|
195
|
+
return uv__set_sys_error(loop, errno);
|
196
|
+
|
197
|
+
w = find_watcher(loop, wd);
|
198
|
+
if (w)
|
199
|
+
goto no_insert;
|
200
|
+
|
201
|
+
w = malloc(sizeof(*w) + strlen(path) + 1);
|
202
|
+
if (w == NULL)
|
203
|
+
return uv__set_sys_error(loop, ENOMEM);
|
204
|
+
|
205
|
+
w->wd = wd;
|
206
|
+
w->path = strcpy((char*)(w + 1), path);
|
207
|
+
ngx_queue_init(&w->watchers);
|
208
|
+
RB_INSERT(watcher_root, CAST(&loop->inotify_watchers), w);
|
209
|
+
|
210
|
+
no_insert:
|
211
|
+
uv__handle_init(loop, (uv_handle_t*)handle, UV_FS_EVENT);
|
212
|
+
uv__handle_start(handle); /* FIXME shouldn't start automatically */
|
213
|
+
ngx_queue_insert_tail(&w->watchers, &handle->watchers);
|
214
|
+
handle->filename = w->path;
|
215
|
+
handle->cb = cb;
|
216
|
+
handle->wd = wd;
|
217
|
+
|
218
|
+
return 0;
|
219
|
+
}
|
220
|
+
|
221
|
+
|
222
|
+
void uv__fs_event_close(uv_fs_event_t* handle) {
|
223
|
+
struct watcher_list* w;
|
224
|
+
|
225
|
+
w = find_watcher(handle->loop, handle->wd);
|
226
|
+
assert(w != NULL);
|
227
|
+
|
228
|
+
handle->wd = -1;
|
229
|
+
handle->filename = NULL;
|
230
|
+
uv__handle_stop(handle);
|
231
|
+
ngx_queue_remove(&handle->watchers);
|
232
|
+
|
233
|
+
if (ngx_queue_empty(&w->watchers)) {
|
234
|
+
/* No watchers left for this path. Clean up. */
|
235
|
+
RB_REMOVE(watcher_root, CAST(&handle->loop->inotify_watchers), w);
|
236
|
+
uv__inotify_rm_watch(handle->loop->inotify_fd, w->wd);
|
237
|
+
free(w);
|
238
|
+
}
|
239
|
+
}
|