passenger 5.0.8 → 5.0.9
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of passenger might be problematic. Click here for more details.
- checksums.yaml +8 -8
- checksums.yaml.gz.asc +7 -7
- data.tar.gz.asc +7 -7
- data/.editorconfig +20 -0
- data/CHANGELOG +21 -0
- data/bin/passenger-install-apache2-module +3 -1
- data/build/agents.rb +7 -5
- data/build/basics.rb +3 -3
- data/build/common_library.rb +52 -30
- data/build/cxx_tests.rb +20 -13
- data/build/misc.rb +5 -5
- data/doc/Design and Architecture.html +1 -1
- data/doc/Design and Architecture.txt +1 -1
- data/doc/Packaging.html +4 -4
- data/doc/Packaging.txt.md +4 -4
- data/doc/Users guide Apache.html +22 -9
- data/doc/Users guide Apache.idmap.txt +4 -2
- data/doc/Users guide Apache.txt +2 -0
- data/doc/Users guide Nginx.html +22 -9
- data/doc/Users guide Nginx.idmap.txt +4 -2
- data/doc/Users guide Nginx.txt +2 -0
- data/doc/Users guide Standalone.html +14 -9
- data/doc/Users guide Standalone.idmap.txt +4 -2
- data/doc/users_guide_snippets/installation.txt +10 -6
- data/ext/apache2/Hooks.cpp +13 -2
- data/ext/common/ApplicationPool2/Pool/Inspection.h +8 -3
- data/ext/common/BackgroundEventLoop.cpp +249 -67
- data/ext/common/BackgroundEventLoop.h +5 -5
- data/ext/common/Constants.h +1 -1
- data/ext/common/InstanceDirectory.h +8 -6
- data/ext/common/ServerKit/Context.h +8 -2
- data/ext/common/ServerKit/FileBufferedChannel.h +262 -226
- data/ext/common/ServerKit/HeaderTable.h +28 -3
- data/ext/common/ServerKit/HttpHeaderParser.h +37 -13
- data/ext/common/ServerKit/HttpServer.h +17 -1
- data/ext/common/ServerKit/Implementation.cpp +2 -0
- data/ext/common/ServerKit/Server.h +25 -28
- data/ext/common/Utils/IOUtils.cpp +11 -0
- data/ext/common/Utils/ProcessMetricsCollector.h +4 -0
- data/ext/common/Utils/StrIntUtils.cpp +11 -7
- data/ext/common/Utils/StrIntUtils.h +1 -1
- data/ext/common/Utils/StrIntUtilsNoStrictAliasing.cpp +21 -16
- data/ext/common/agents/Base.cpp +6 -0
- data/ext/common/agents/Base.h +2 -0
- data/ext/common/agents/HelperAgent/AdminServer.h +25 -25
- data/ext/common/agents/HelperAgent/Main.cpp +37 -12
- data/ext/common/agents/HelperAgent/RequestHandler.h +18 -20
- data/ext/common/agents/HelperAgent/RequestHandler/AppResponse.h +4 -0
- data/ext/common/agents/HelperAgent/RequestHandler/ForwardResponse.cpp +10 -6
- data/ext/common/agents/HelperAgent/RequestHandler/Hooks.cpp +2 -0
- data/ext/common/agents/HelperAgent/RequestHandler/InitRequest.cpp +1 -1
- data/ext/common/agents/HelperAgent/RequestHandler/SendRequest.cpp +1 -1
- data/ext/common/agents/HelperAgent/RequestHandler/Utils.cpp +9 -2
- data/ext/common/agents/HelperAgent/ResponseCache.h +11 -11
- data/ext/common/agents/LoggingAgent/AdminServer.h +8 -8
- data/ext/common/agents/LoggingAgent/Main.cpp +6 -5
- data/ext/common/agents/Watchdog/AdminServer.h +13 -13
- data/ext/common/agents/Watchdog/Main.cpp +8 -3
- data/ext/libuv/.gitignore +72 -0
- data/ext/libuv/AUTHORS +199 -0
- data/ext/libuv/ChangeLog +2023 -0
- data/ext/libuv/LICENSE +46 -0
- data/ext/libuv/Makefile.am +336 -0
- data/ext/libuv/README.md +197 -0
- data/ext/libuv/checksparse.sh +233 -0
- data/ext/libuv/common.gypi +210 -0
- data/ext/libuv/configure.ac +67 -0
- data/ext/libuv/gyp_uv.py +96 -0
- data/ext/libuv/include/android-ifaddrs.h +54 -0
- data/ext/libuv/include/pthread-fixes.h +72 -0
- data/ext/libuv/include/tree.h +768 -0
- data/ext/libuv/include/uv-aix.h +32 -0
- data/ext/libuv/include/uv-bsd.h +34 -0
- data/ext/libuv/include/uv-darwin.h +61 -0
- data/ext/libuv/include/uv-errno.h +418 -0
- data/ext/libuv/include/uv-linux.h +34 -0
- data/ext/libuv/include/uv-sunos.h +44 -0
- data/ext/libuv/include/uv-threadpool.h +37 -0
- data/ext/libuv/include/uv-unix.h +383 -0
- data/ext/libuv/include/uv-version.h +39 -0
- data/ext/libuv/include/uv.h +1455 -0
- data/ext/libuv/libuv.pc.in +11 -0
- data/ext/libuv/m4/.gitignore +4 -0
- data/ext/libuv/m4/as_case.m4 +21 -0
- data/ext/libuv/m4/libuv-check-flags.m4 +319 -0
- data/ext/libuv/src/fs-poll.c +255 -0
- data/ext/libuv/src/heap-inl.h +245 -0
- data/ext/libuv/src/inet.c +313 -0
- data/ext/libuv/src/queue.h +92 -0
- data/ext/libuv/src/threadpool.c +303 -0
- data/ext/libuv/src/unix/aix.c +1240 -0
- data/ext/libuv/src/unix/android-ifaddrs.c +703 -0
- data/ext/libuv/src/unix/async.c +284 -0
- data/ext/libuv/src/unix/atomic-ops.h +60 -0
- data/ext/libuv/src/unix/core.c +985 -0
- data/ext/libuv/src/unix/darwin-proctitle.c +206 -0
- data/ext/libuv/src/unix/darwin.c +331 -0
- data/ext/libuv/src/unix/dl.c +83 -0
- data/ext/libuv/src/unix/freebsd.c +435 -0
- data/ext/libuv/src/unix/fs.c +1189 -0
- data/ext/libuv/src/unix/fsevents.c +899 -0
- data/ext/libuv/src/unix/getaddrinfo.c +202 -0
- data/ext/libuv/src/unix/getnameinfo.c +120 -0
- data/ext/libuv/src/unix/internal.h +314 -0
- data/ext/libuv/src/unix/kqueue.c +418 -0
- data/ext/libuv/src/unix/linux-core.c +876 -0
- data/ext/libuv/src/unix/linux-inotify.c +257 -0
- data/ext/libuv/src/unix/linux-syscalls.c +471 -0
- data/ext/libuv/src/unix/linux-syscalls.h +158 -0
- data/ext/libuv/src/unix/loop-watcher.c +63 -0
- data/ext/libuv/src/unix/loop.c +135 -0
- data/ext/libuv/src/unix/netbsd.c +368 -0
- data/ext/libuv/src/unix/openbsd.c +384 -0
- data/ext/libuv/src/unix/pipe.c +288 -0
- data/ext/libuv/src/unix/poll.c +113 -0
- data/ext/libuv/src/unix/process.c +551 -0
- data/ext/libuv/src/unix/proctitle.c +102 -0
- data/ext/libuv/src/unix/pthread-fixes.c +103 -0
- data/ext/libuv/src/unix/signal.c +465 -0
- data/ext/libuv/src/unix/spinlock.h +53 -0
- data/ext/libuv/src/unix/stream.c +1598 -0
- data/ext/libuv/src/unix/sunos.c +763 -0
- data/ext/libuv/src/unix/tcp.c +327 -0
- data/ext/libuv/src/unix/thread.c +519 -0
- data/ext/libuv/src/unix/timer.c +172 -0
- data/ext/libuv/src/unix/tty.c +265 -0
- data/ext/libuv/src/unix/udp.c +833 -0
- data/ext/libuv/src/uv-common.c +544 -0
- data/ext/libuv/src/uv-common.h +214 -0
- data/ext/libuv/src/version.c +49 -0
- data/ext/libuv/uv.gyp +487 -0
- data/ext/nginx/ContentHandler.c +21 -10
- data/ext/nginx/ngx_http_passenger_module.c +7 -0
- data/ext/oxt/implementation.cpp +9 -2
- data/ext/oxt/initialize.hpp +5 -1
- data/lib/phusion_passenger.rb +3 -3
- data/lib/phusion_passenger/admin_tools/instance.rb +10 -6
- data/lib/phusion_passenger/admin_tools/instance_registry.rb +6 -2
- data/lib/phusion_passenger/packaging.rb +3 -4
- data/lib/phusion_passenger/platform_info.rb +13 -1
- data/lib/phusion_passenger/platform_info/apache.rb +15 -4
- data/lib/phusion_passenger/platform_info/apache_detector.rb +5 -1
- data/lib/phusion_passenger/rack/thread_handler_extension.rb +184 -99
- data/lib/phusion_passenger/request_handler/thread_handler.rb +13 -6
- data/lib/phusion_passenger/standalone/start_command.rb +2 -2
- data/resources/templates/apache2/apache_install_broken.txt.erb +2 -1
- metadata +99 -22
- metadata.gz.asc +7 -7
- data/ext/libeio/Changes +0 -76
- data/ext/libeio/LICENSE +0 -36
- data/ext/libeio/Makefile.am +0 -15
- data/ext/libeio/Makefile.in +0 -694
- data/ext/libeio/aclocal.m4 +0 -9418
- data/ext/libeio/autogen.sh +0 -3
- data/ext/libeio/config.guess +0 -1540
- data/ext/libeio/config.h.in +0 -136
- data/ext/libeio/config.sub +0 -1779
- data/ext/libeio/configure +0 -14822
- data/ext/libeio/configure.ac +0 -22
- data/ext/libeio/demo.c +0 -194
- data/ext/libeio/ecb.h +0 -714
- data/ext/libeio/eio.c +0 -2818
- data/ext/libeio/eio.h +0 -414
- data/ext/libeio/install-sh +0 -520
- data/ext/libeio/libeio.m4 +0 -195
- data/ext/libeio/ltmain.sh +0 -9636
- data/ext/libeio/missing +0 -376
- data/ext/libeio/xthread.h +0 -166
@@ -0,0 +1,544 @@
|
|
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 <stdio.h>
|
26
|
+
#include <assert.h>
|
27
|
+
#include <stdarg.h>
|
28
|
+
#include <stddef.h> /* NULL */
|
29
|
+
#include <stdlib.h> /* malloc */
|
30
|
+
#include <string.h> /* memset */
|
31
|
+
|
32
|
+
#if !defined(_WIN32)
|
33
|
+
# include <net/if.h> /* if_nametoindex */
|
34
|
+
#endif
|
35
|
+
|
36
|
+
#define XX(uc, lc) case UV_##uc: return sizeof(uv_##lc##_t);
|
37
|
+
|
38
|
+
size_t uv_handle_size(uv_handle_type type) {
|
39
|
+
switch (type) {
|
40
|
+
UV_HANDLE_TYPE_MAP(XX)
|
41
|
+
default:
|
42
|
+
return -1;
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
size_t uv_req_size(uv_req_type type) {
|
47
|
+
switch(type) {
|
48
|
+
UV_REQ_TYPE_MAP(XX)
|
49
|
+
default:
|
50
|
+
return -1;
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
#undef XX
|
55
|
+
|
56
|
+
|
57
|
+
size_t uv_loop_size(void) {
|
58
|
+
return sizeof(uv_loop_t);
|
59
|
+
}
|
60
|
+
|
61
|
+
|
62
|
+
uv_buf_t uv_buf_init(char* base, unsigned int len) {
|
63
|
+
uv_buf_t buf;
|
64
|
+
buf.base = base;
|
65
|
+
buf.len = len;
|
66
|
+
return buf;
|
67
|
+
}
|
68
|
+
|
69
|
+
|
70
|
+
#define UV_ERR_NAME_GEN(name, _) case UV_ ## name: return #name;
|
71
|
+
const char* uv_err_name(int err) {
|
72
|
+
switch (err) {
|
73
|
+
UV_ERRNO_MAP(UV_ERR_NAME_GEN)
|
74
|
+
default:
|
75
|
+
assert(0);
|
76
|
+
return NULL;
|
77
|
+
}
|
78
|
+
}
|
79
|
+
#undef UV_ERR_NAME_GEN
|
80
|
+
|
81
|
+
|
82
|
+
#define UV_STRERROR_GEN(name, msg) case UV_ ## name: return msg;
|
83
|
+
const char* uv_strerror(int err) {
|
84
|
+
switch (err) {
|
85
|
+
UV_ERRNO_MAP(UV_STRERROR_GEN)
|
86
|
+
default:
|
87
|
+
return "Unknown system error";
|
88
|
+
}
|
89
|
+
}
|
90
|
+
#undef UV_STRERROR_GEN
|
91
|
+
|
92
|
+
|
93
|
+
int uv_ip4_addr(const char* ip, int port, struct sockaddr_in* addr) {
|
94
|
+
memset(addr, 0, sizeof(*addr));
|
95
|
+
addr->sin_family = AF_INET;
|
96
|
+
addr->sin_port = htons(port);
|
97
|
+
return uv_inet_pton(AF_INET, ip, &(addr->sin_addr.s_addr));
|
98
|
+
}
|
99
|
+
|
100
|
+
|
101
|
+
int uv_ip6_addr(const char* ip, int port, struct sockaddr_in6* addr) {
|
102
|
+
char address_part[40];
|
103
|
+
size_t address_part_size;
|
104
|
+
const char* zone_index;
|
105
|
+
|
106
|
+
memset(addr, 0, sizeof(*addr));
|
107
|
+
addr->sin6_family = AF_INET6;
|
108
|
+
addr->sin6_port = htons(port);
|
109
|
+
|
110
|
+
zone_index = strchr(ip, '%');
|
111
|
+
if (zone_index != NULL) {
|
112
|
+
address_part_size = zone_index - ip;
|
113
|
+
if (address_part_size >= sizeof(address_part))
|
114
|
+
address_part_size = sizeof(address_part) - 1;
|
115
|
+
|
116
|
+
memcpy(address_part, ip, address_part_size);
|
117
|
+
address_part[address_part_size] = '\0';
|
118
|
+
ip = address_part;
|
119
|
+
|
120
|
+
zone_index++; /* skip '%' */
|
121
|
+
/* NOTE: unknown interface (id=0) is silently ignored */
|
122
|
+
#ifdef _WIN32
|
123
|
+
addr->sin6_scope_id = atoi(zone_index);
|
124
|
+
#else
|
125
|
+
addr->sin6_scope_id = if_nametoindex(zone_index);
|
126
|
+
#endif
|
127
|
+
}
|
128
|
+
|
129
|
+
return uv_inet_pton(AF_INET6, ip, &addr->sin6_addr);
|
130
|
+
}
|
131
|
+
|
132
|
+
|
133
|
+
int uv_ip4_name(const struct sockaddr_in* src, char* dst, size_t size) {
|
134
|
+
return uv_inet_ntop(AF_INET, &src->sin_addr, dst, size);
|
135
|
+
}
|
136
|
+
|
137
|
+
|
138
|
+
int uv_ip6_name(const struct sockaddr_in6* src, char* dst, size_t size) {
|
139
|
+
return uv_inet_ntop(AF_INET6, &src->sin6_addr, dst, size);
|
140
|
+
}
|
141
|
+
|
142
|
+
|
143
|
+
int uv_tcp_bind(uv_tcp_t* handle,
|
144
|
+
const struct sockaddr* addr,
|
145
|
+
unsigned int flags) {
|
146
|
+
unsigned int addrlen;
|
147
|
+
|
148
|
+
if (handle->type != UV_TCP)
|
149
|
+
return UV_EINVAL;
|
150
|
+
|
151
|
+
if (addr->sa_family == AF_INET)
|
152
|
+
addrlen = sizeof(struct sockaddr_in);
|
153
|
+
else if (addr->sa_family == AF_INET6)
|
154
|
+
addrlen = sizeof(struct sockaddr_in6);
|
155
|
+
else
|
156
|
+
return UV_EINVAL;
|
157
|
+
|
158
|
+
return uv__tcp_bind(handle, addr, addrlen, flags);
|
159
|
+
}
|
160
|
+
|
161
|
+
|
162
|
+
int uv_udp_bind(uv_udp_t* handle,
|
163
|
+
const struct sockaddr* addr,
|
164
|
+
unsigned int flags) {
|
165
|
+
unsigned int addrlen;
|
166
|
+
|
167
|
+
if (handle->type != UV_UDP)
|
168
|
+
return UV_EINVAL;
|
169
|
+
|
170
|
+
if (addr->sa_family == AF_INET)
|
171
|
+
addrlen = sizeof(struct sockaddr_in);
|
172
|
+
else if (addr->sa_family == AF_INET6)
|
173
|
+
addrlen = sizeof(struct sockaddr_in6);
|
174
|
+
else
|
175
|
+
return UV_EINVAL;
|
176
|
+
|
177
|
+
return uv__udp_bind(handle, addr, addrlen, flags);
|
178
|
+
}
|
179
|
+
|
180
|
+
|
181
|
+
int uv_tcp_connect(uv_connect_t* req,
|
182
|
+
uv_tcp_t* handle,
|
183
|
+
const struct sockaddr* addr,
|
184
|
+
uv_connect_cb cb) {
|
185
|
+
unsigned int addrlen;
|
186
|
+
|
187
|
+
if (handle->type != UV_TCP)
|
188
|
+
return UV_EINVAL;
|
189
|
+
|
190
|
+
if (addr->sa_family == AF_INET)
|
191
|
+
addrlen = sizeof(struct sockaddr_in);
|
192
|
+
else if (addr->sa_family == AF_INET6)
|
193
|
+
addrlen = sizeof(struct sockaddr_in6);
|
194
|
+
else
|
195
|
+
return UV_EINVAL;
|
196
|
+
|
197
|
+
return uv__tcp_connect(req, handle, addr, addrlen, cb);
|
198
|
+
}
|
199
|
+
|
200
|
+
|
201
|
+
int uv_udp_send(uv_udp_send_t* req,
|
202
|
+
uv_udp_t* handle,
|
203
|
+
const uv_buf_t bufs[],
|
204
|
+
unsigned int nbufs,
|
205
|
+
const struct sockaddr* addr,
|
206
|
+
uv_udp_send_cb send_cb) {
|
207
|
+
unsigned int addrlen;
|
208
|
+
|
209
|
+
if (handle->type != UV_UDP)
|
210
|
+
return UV_EINVAL;
|
211
|
+
|
212
|
+
if (addr->sa_family == AF_INET)
|
213
|
+
addrlen = sizeof(struct sockaddr_in);
|
214
|
+
else if (addr->sa_family == AF_INET6)
|
215
|
+
addrlen = sizeof(struct sockaddr_in6);
|
216
|
+
else
|
217
|
+
return UV_EINVAL;
|
218
|
+
|
219
|
+
return uv__udp_send(req, handle, bufs, nbufs, addr, addrlen, send_cb);
|
220
|
+
}
|
221
|
+
|
222
|
+
|
223
|
+
int uv_udp_try_send(uv_udp_t* handle,
|
224
|
+
const uv_buf_t bufs[],
|
225
|
+
unsigned int nbufs,
|
226
|
+
const struct sockaddr* addr) {
|
227
|
+
unsigned int addrlen;
|
228
|
+
|
229
|
+
if (handle->type != UV_UDP)
|
230
|
+
return UV_EINVAL;
|
231
|
+
|
232
|
+
if (addr->sa_family == AF_INET)
|
233
|
+
addrlen = sizeof(struct sockaddr_in);
|
234
|
+
else if (addr->sa_family == AF_INET6)
|
235
|
+
addrlen = sizeof(struct sockaddr_in6);
|
236
|
+
else
|
237
|
+
return UV_EINVAL;
|
238
|
+
|
239
|
+
return uv__udp_try_send(handle, bufs, nbufs, addr, addrlen);
|
240
|
+
}
|
241
|
+
|
242
|
+
|
243
|
+
int uv_udp_recv_start(uv_udp_t* handle,
|
244
|
+
uv_alloc_cb alloc_cb,
|
245
|
+
uv_udp_recv_cb recv_cb) {
|
246
|
+
if (handle->type != UV_UDP || alloc_cb == NULL || recv_cb == NULL)
|
247
|
+
return UV_EINVAL;
|
248
|
+
else
|
249
|
+
return uv__udp_recv_start(handle, alloc_cb, recv_cb);
|
250
|
+
}
|
251
|
+
|
252
|
+
|
253
|
+
int uv_udp_recv_stop(uv_udp_t* handle) {
|
254
|
+
if (handle->type != UV_UDP)
|
255
|
+
return UV_EINVAL;
|
256
|
+
else
|
257
|
+
return uv__udp_recv_stop(handle);
|
258
|
+
}
|
259
|
+
|
260
|
+
|
261
|
+
void uv_walk(uv_loop_t* loop, uv_walk_cb walk_cb, void* arg) {
|
262
|
+
QUEUE* q;
|
263
|
+
uv_handle_t* h;
|
264
|
+
|
265
|
+
QUEUE_FOREACH(q, &loop->handle_queue) {
|
266
|
+
h = QUEUE_DATA(q, uv_handle_t, handle_queue);
|
267
|
+
if (h->flags & UV__HANDLE_INTERNAL) continue;
|
268
|
+
walk_cb(h, arg);
|
269
|
+
}
|
270
|
+
}
|
271
|
+
|
272
|
+
|
273
|
+
#ifndef NDEBUG
|
274
|
+
static void uv__print_handles(uv_loop_t* loop, int only_active) {
|
275
|
+
const char* type;
|
276
|
+
QUEUE* q;
|
277
|
+
uv_handle_t* h;
|
278
|
+
|
279
|
+
if (loop == NULL)
|
280
|
+
loop = uv_default_loop();
|
281
|
+
|
282
|
+
QUEUE_FOREACH(q, &loop->handle_queue) {
|
283
|
+
h = QUEUE_DATA(q, uv_handle_t, handle_queue);
|
284
|
+
|
285
|
+
if (only_active && !uv__is_active(h))
|
286
|
+
continue;
|
287
|
+
|
288
|
+
switch (h->type) {
|
289
|
+
#define X(uc, lc) case UV_##uc: type = #lc; break;
|
290
|
+
UV_HANDLE_TYPE_MAP(X)
|
291
|
+
#undef X
|
292
|
+
default: type = "<unknown>";
|
293
|
+
}
|
294
|
+
|
295
|
+
fprintf(stderr,
|
296
|
+
"[%c%c%c] %-8s %p\n",
|
297
|
+
"R-"[!(h->flags & UV__HANDLE_REF)],
|
298
|
+
"A-"[!(h->flags & UV__HANDLE_ACTIVE)],
|
299
|
+
"I-"[!(h->flags & UV__HANDLE_INTERNAL)],
|
300
|
+
type,
|
301
|
+
(void*)h);
|
302
|
+
}
|
303
|
+
}
|
304
|
+
|
305
|
+
|
306
|
+
void uv_print_all_handles(uv_loop_t* loop) {
|
307
|
+
uv__print_handles(loop, 0);
|
308
|
+
}
|
309
|
+
|
310
|
+
|
311
|
+
void uv_print_active_handles(uv_loop_t* loop) {
|
312
|
+
uv__print_handles(loop, 1);
|
313
|
+
}
|
314
|
+
#endif
|
315
|
+
|
316
|
+
|
317
|
+
void uv_ref(uv_handle_t* handle) {
|
318
|
+
uv__handle_ref(handle);
|
319
|
+
}
|
320
|
+
|
321
|
+
|
322
|
+
void uv_unref(uv_handle_t* handle) {
|
323
|
+
uv__handle_unref(handle);
|
324
|
+
}
|
325
|
+
|
326
|
+
|
327
|
+
int uv_has_ref(const uv_handle_t* handle) {
|
328
|
+
return uv__has_ref(handle);
|
329
|
+
}
|
330
|
+
|
331
|
+
|
332
|
+
void uv_stop(uv_loop_t* loop) {
|
333
|
+
loop->stop_flag = 1;
|
334
|
+
}
|
335
|
+
|
336
|
+
|
337
|
+
uint64_t uv_now(const uv_loop_t* loop) {
|
338
|
+
return loop->time;
|
339
|
+
}
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
size_t uv__count_bufs(const uv_buf_t bufs[], unsigned int nbufs) {
|
344
|
+
unsigned int i;
|
345
|
+
size_t bytes;
|
346
|
+
|
347
|
+
bytes = 0;
|
348
|
+
for (i = 0; i < nbufs; i++)
|
349
|
+
bytes += (size_t) bufs[i].len;
|
350
|
+
|
351
|
+
return bytes;
|
352
|
+
}
|
353
|
+
|
354
|
+
int uv_recv_buffer_size(uv_handle_t* handle, int* value) {
|
355
|
+
return uv__socket_sockopt(handle, SO_RCVBUF, value);
|
356
|
+
}
|
357
|
+
|
358
|
+
int uv_send_buffer_size(uv_handle_t* handle, int *value) {
|
359
|
+
return uv__socket_sockopt(handle, SO_SNDBUF, value);
|
360
|
+
}
|
361
|
+
|
362
|
+
int uv_fs_event_getpath(uv_fs_event_t* handle, char* buffer, size_t* size) {
|
363
|
+
size_t required_len;
|
364
|
+
|
365
|
+
if (!uv__is_active(handle)) {
|
366
|
+
*size = 0;
|
367
|
+
return UV_EINVAL;
|
368
|
+
}
|
369
|
+
|
370
|
+
required_len = strlen(handle->path);
|
371
|
+
if (required_len > *size) {
|
372
|
+
*size = required_len;
|
373
|
+
return UV_ENOBUFS;
|
374
|
+
}
|
375
|
+
|
376
|
+
memcpy(buffer, handle->path, required_len);
|
377
|
+
*size = required_len;
|
378
|
+
|
379
|
+
return 0;
|
380
|
+
}
|
381
|
+
|
382
|
+
/* The windows implementation does not have the same structure layout as
|
383
|
+
* the unix implementation (nbufs is not directly inside req but is
|
384
|
+
* contained in a nested union/struct) so this function locates it.
|
385
|
+
*/
|
386
|
+
static unsigned int* uv__get_nbufs(uv_fs_t* req) {
|
387
|
+
#ifdef _WIN32
|
388
|
+
return &req->fs.info.nbufs;
|
389
|
+
#else
|
390
|
+
return &req->nbufs;
|
391
|
+
#endif
|
392
|
+
}
|
393
|
+
|
394
|
+
void uv__fs_scandir_cleanup(uv_fs_t* req) {
|
395
|
+
uv__dirent_t** dents;
|
396
|
+
|
397
|
+
unsigned int* nbufs = uv__get_nbufs(req);
|
398
|
+
|
399
|
+
dents = req->ptr;
|
400
|
+
if (*nbufs > 0 && *nbufs != (unsigned int) req->result)
|
401
|
+
(*nbufs)--;
|
402
|
+
for (; *nbufs < (unsigned int) req->result; (*nbufs)++)
|
403
|
+
free(dents[*nbufs]);
|
404
|
+
}
|
405
|
+
|
406
|
+
|
407
|
+
int uv_fs_scandir_next(uv_fs_t* req, uv_dirent_t* ent) {
|
408
|
+
uv__dirent_t** dents;
|
409
|
+
uv__dirent_t* dent;
|
410
|
+
|
411
|
+
unsigned int* nbufs = uv__get_nbufs(req);
|
412
|
+
|
413
|
+
dents = req->ptr;
|
414
|
+
|
415
|
+
/* Free previous entity */
|
416
|
+
if (*nbufs > 0)
|
417
|
+
free(dents[*nbufs - 1]);
|
418
|
+
|
419
|
+
/* End was already reached */
|
420
|
+
if (*nbufs == (unsigned int) req->result) {
|
421
|
+
free(dents);
|
422
|
+
req->ptr = NULL;
|
423
|
+
return UV_EOF;
|
424
|
+
}
|
425
|
+
|
426
|
+
dent = dents[(*nbufs)++];
|
427
|
+
|
428
|
+
ent->name = dent->d_name;
|
429
|
+
#ifdef HAVE_DIRENT_TYPES
|
430
|
+
switch (dent->d_type) {
|
431
|
+
case UV__DT_DIR:
|
432
|
+
ent->type = UV_DIRENT_DIR;
|
433
|
+
break;
|
434
|
+
case UV__DT_FILE:
|
435
|
+
ent->type = UV_DIRENT_FILE;
|
436
|
+
break;
|
437
|
+
case UV__DT_LINK:
|
438
|
+
ent->type = UV_DIRENT_LINK;
|
439
|
+
break;
|
440
|
+
case UV__DT_FIFO:
|
441
|
+
ent->type = UV_DIRENT_FIFO;
|
442
|
+
break;
|
443
|
+
case UV__DT_SOCKET:
|
444
|
+
ent->type = UV_DIRENT_SOCKET;
|
445
|
+
break;
|
446
|
+
case UV__DT_CHAR:
|
447
|
+
ent->type = UV_DIRENT_CHAR;
|
448
|
+
break;
|
449
|
+
case UV__DT_BLOCK:
|
450
|
+
ent->type = UV_DIRENT_BLOCK;
|
451
|
+
break;
|
452
|
+
default:
|
453
|
+
ent->type = UV_DIRENT_UNKNOWN;
|
454
|
+
}
|
455
|
+
#else
|
456
|
+
ent->type = UV_DIRENT_UNKNOWN;
|
457
|
+
#endif
|
458
|
+
|
459
|
+
return 0;
|
460
|
+
}
|
461
|
+
|
462
|
+
|
463
|
+
int uv_loop_configure(uv_loop_t* loop, uv_loop_option option, ...) {
|
464
|
+
va_list ap;
|
465
|
+
int err;
|
466
|
+
|
467
|
+
va_start(ap, option);
|
468
|
+
/* Any platform-agnostic options should be handled here. */
|
469
|
+
err = uv__loop_configure(loop, option, ap);
|
470
|
+
va_end(ap);
|
471
|
+
|
472
|
+
return err;
|
473
|
+
}
|
474
|
+
|
475
|
+
|
476
|
+
static uv_loop_t default_loop_struct;
|
477
|
+
static uv_loop_t* default_loop_ptr;
|
478
|
+
|
479
|
+
|
480
|
+
uv_loop_t* uv_default_loop(void) {
|
481
|
+
if (default_loop_ptr != NULL)
|
482
|
+
return default_loop_ptr;
|
483
|
+
|
484
|
+
if (uv_loop_init(&default_loop_struct))
|
485
|
+
return NULL;
|
486
|
+
|
487
|
+
default_loop_ptr = &default_loop_struct;
|
488
|
+
return default_loop_ptr;
|
489
|
+
}
|
490
|
+
|
491
|
+
|
492
|
+
uv_loop_t* uv_loop_new(void) {
|
493
|
+
uv_loop_t* loop;
|
494
|
+
|
495
|
+
loop = malloc(sizeof(*loop));
|
496
|
+
if (loop == NULL)
|
497
|
+
return NULL;
|
498
|
+
|
499
|
+
if (uv_loop_init(loop)) {
|
500
|
+
free(loop);
|
501
|
+
return NULL;
|
502
|
+
}
|
503
|
+
|
504
|
+
return loop;
|
505
|
+
}
|
506
|
+
|
507
|
+
|
508
|
+
int uv_loop_close(uv_loop_t* loop) {
|
509
|
+
QUEUE* q;
|
510
|
+
uv_handle_t* h;
|
511
|
+
|
512
|
+
if (!QUEUE_EMPTY(&(loop)->active_reqs))
|
513
|
+
return UV_EBUSY;
|
514
|
+
|
515
|
+
QUEUE_FOREACH(q, &loop->handle_queue) {
|
516
|
+
h = QUEUE_DATA(q, uv_handle_t, handle_queue);
|
517
|
+
if (!(h->flags & UV__HANDLE_INTERNAL))
|
518
|
+
return UV_EBUSY;
|
519
|
+
}
|
520
|
+
|
521
|
+
uv__loop_close(loop);
|
522
|
+
|
523
|
+
#ifndef NDEBUG
|
524
|
+
memset(loop, -1, sizeof(*loop));
|
525
|
+
#endif
|
526
|
+
if (loop == default_loop_ptr)
|
527
|
+
default_loop_ptr = NULL;
|
528
|
+
|
529
|
+
return 0;
|
530
|
+
}
|
531
|
+
|
532
|
+
|
533
|
+
void uv_loop_delete(uv_loop_t* loop) {
|
534
|
+
uv_loop_t* default_loop;
|
535
|
+
int err;
|
536
|
+
|
537
|
+
default_loop = default_loop_ptr;
|
538
|
+
|
539
|
+
err = uv_loop_close(loop);
|
540
|
+
(void) err; /* Squelch compiler warnings. */
|
541
|
+
assert(err == 0);
|
542
|
+
if (loop != default_loop)
|
543
|
+
free(loop);
|
544
|
+
}
|