asyncengine 0.0.1.testing1 → 0.0.2.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +3 -0
- data/Rakefile +38 -0
- data/asyncengine.gemspec +8 -4
- data/ext/asyncengine/ae_call_from_other_thread.c +106 -0
- data/ext/asyncengine/ae_call_from_other_thread.h +12 -0
- data/ext/asyncengine/ae_handle_common.c +193 -48
- data/ext/asyncengine/ae_handle_common.h +40 -13
- data/ext/asyncengine/ae_ip_utils.c +246 -0
- data/ext/asyncengine/ae_ip_utils.h +25 -0
- data/ext/asyncengine/ae_next_tick.c +81 -21
- data/ext/asyncengine/ae_next_tick.h +4 -2
- data/ext/asyncengine/ae_resolver.c +156 -0
- data/ext/asyncengine/ae_resolver.h +10 -0
- data/ext/asyncengine/ae_tcp.c +908 -0
- data/ext/asyncengine/ae_tcp.h +20 -0
- data/ext/asyncengine/ae_timer.c +355 -81
- data/ext/asyncengine/ae_timer.h +11 -4
- data/ext/asyncengine/ae_udp.c +579 -13
- data/ext/asyncengine/ae_udp.h +15 -2
- data/ext/asyncengine/ae_utils.c +192 -0
- data/ext/asyncengine/ae_utils.h +16 -0
- data/ext/asyncengine/asyncengine_ruby.c +469 -26
- data/ext/asyncengine/asyncengine_ruby.h +49 -11
- data/ext/asyncengine/debug.h +68 -0
- data/ext/asyncengine/extconf.rb +26 -2
- data/ext/asyncengine/ip_parser.c +5954 -0
- data/ext/asyncengine/ip_parser.h +16 -0
- data/ext/asyncengine/libuv/AUTHORS +16 -0
- data/ext/asyncengine/libuv/common.gypi +4 -4
- data/ext/asyncengine/libuv/config-mingw.mk +6 -6
- data/ext/asyncengine/libuv/config-unix.mk +13 -13
- data/ext/asyncengine/libuv/gyp_uv +5 -1
- data/ext/asyncengine/libuv/ibc_tests/exec_test.sh +8 -0
- data/ext/asyncengine/libuv/ibc_tests/uv_shutdown_write_issue.c +171 -0
- data/ext/asyncengine/libuv/ibc_tests/uv_tcp_close_while_connecting.c +102 -0
- data/ext/asyncengine/libuv/include/uv-private/ngx-queue.h +3 -1
- data/ext/asyncengine/libuv/include/uv-private/uv-unix.h +103 -50
- data/ext/asyncengine/libuv/include/uv-private/uv-win.h +76 -24
- data/ext/asyncengine/libuv/include/uv.h +353 -88
- data/ext/asyncengine/libuv/src/ares/ares__close_sockets.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares__get_hostent.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares__read_line.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares__timeval.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_cancel.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_data.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_destroy.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_expand_name.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_expand_string.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_fds.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_free_hostent.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_free_string.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_gethostbyaddr.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_gethostbyname.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_getnameinfo.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_getopt.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_getsock.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_init.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_library_init.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_llist.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_mkquery.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_nowarn.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_options.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_parse_a_reply.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_parse_aaaa_reply.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_parse_mx_reply.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_parse_ns_reply.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_parse_ptr_reply.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_parse_srv_reply.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_parse_txt_reply.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_process.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_query.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_search.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_send.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_strcasecmp.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_strdup.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_strerror.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_timeout.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_version.o +0 -0
- data/ext/asyncengine/libuv/src/ares/ares_writev.o +0 -0
- data/ext/asyncengine/libuv/src/ares/bitncmp.o +0 -0
- data/ext/asyncengine/libuv/src/ares/inet_net_pton.o +0 -0
- data/ext/asyncengine/libuv/src/ares/inet_ntop.o +0 -0
- data/ext/asyncengine/libuv/src/cares.c +225 -0
- data/ext/asyncengine/libuv/src/cares.o +0 -0
- data/ext/asyncengine/libuv/src/fs-poll.c +237 -0
- data/ext/asyncengine/libuv/src/fs-poll.o +0 -0
- data/ext/asyncengine/libuv/src/unix/async.c +78 -17
- data/ext/asyncengine/libuv/src/unix/async.o +0 -0
- data/ext/asyncengine/libuv/src/unix/core.c +305 -213
- data/ext/asyncengine/libuv/src/unix/core.o +0 -0
- data/ext/asyncengine/libuv/src/unix/cygwin.c +1 -1
- data/ext/asyncengine/libuv/src/unix/darwin.c +2 -1
- data/ext/asyncengine/libuv/src/unix/dl.c +36 -44
- data/ext/asyncengine/libuv/src/unix/dl.o +0 -0
- data/ext/asyncengine/libuv/src/unix/eio/eio.o +0 -0
- data/ext/asyncengine/libuv/src/unix/error.c +6 -0
- data/ext/asyncengine/libuv/src/unix/error.o +0 -0
- data/ext/asyncengine/libuv/src/unix/ev/ev.c +8 -4
- data/ext/asyncengine/libuv/src/unix/ev/ev.o +0 -0
- data/ext/asyncengine/libuv/src/unix/freebsd.c +1 -1
- data/ext/asyncengine/libuv/src/unix/fs.c +25 -33
- data/ext/asyncengine/libuv/src/unix/fs.o +0 -0
- data/ext/asyncengine/libuv/src/unix/internal.h +50 -31
- data/ext/asyncengine/libuv/src/unix/kqueue.c +2 -7
- data/ext/asyncengine/libuv/src/unix/linux/core.o +0 -0
- data/ext/asyncengine/libuv/src/unix/linux/inotify.c +12 -14
- data/ext/asyncengine/libuv/src/unix/linux/inotify.o +0 -0
- data/ext/asyncengine/libuv/src/unix/linux/{core.c → linux-core.c} +1 -1
- data/ext/asyncengine/libuv/src/unix/linux/linux-core.o +0 -0
- data/ext/asyncengine/libuv/src/unix/linux/syscalls.c +147 -1
- data/ext/asyncengine/libuv/src/unix/linux/syscalls.h +39 -2
- data/ext/asyncengine/libuv/src/unix/linux/syscalls.o +0 -0
- data/ext/asyncengine/libuv/src/unix/loop-watcher.c +63 -0
- data/ext/asyncengine/libuv/src/unix/loop-watcher.o +0 -0
- data/ext/asyncengine/libuv/src/unix/loop.c +29 -6
- data/ext/asyncengine/libuv/src/unix/loop.o +0 -0
- data/ext/asyncengine/libuv/src/unix/netbsd.c +1 -1
- data/ext/asyncengine/libuv/src/unix/openbsd.c +1 -1
- data/ext/asyncengine/libuv/src/unix/pipe.c +31 -36
- data/ext/asyncengine/libuv/src/unix/pipe.o +0 -0
- data/ext/asyncengine/libuv/src/unix/poll.c +116 -0
- data/ext/asyncengine/libuv/src/unix/poll.o +0 -0
- data/ext/asyncengine/libuv/src/unix/process.c +193 -115
- data/ext/asyncengine/libuv/src/unix/process.o +0 -0
- data/ext/asyncengine/libuv/src/unix/stream.c +146 -153
- data/ext/asyncengine/libuv/src/unix/stream.o +0 -0
- data/ext/asyncengine/libuv/src/unix/sunos.c +45 -36
- data/ext/asyncengine/libuv/src/unix/tcp.c +6 -5
- data/ext/asyncengine/libuv/src/unix/tcp.o +0 -0
- data/ext/asyncengine/libuv/src/unix/thread.c +82 -25
- data/ext/asyncengine/libuv/src/unix/thread.o +0 -0
- data/ext/asyncengine/libuv/src/unix/timer.c +69 -58
- data/ext/asyncengine/libuv/src/unix/timer.o +0 -0
- data/ext/asyncengine/libuv/src/unix/tty.c +3 -3
- data/ext/asyncengine/libuv/src/unix/tty.o +0 -0
- data/ext/asyncengine/libuv/src/unix/udp.c +57 -66
- data/ext/asyncengine/libuv/src/unix/udp.o +0 -0
- data/ext/asyncengine/libuv/src/unix/uv-eio.c +33 -50
- data/ext/asyncengine/libuv/src/unix/uv-eio.o +0 -0
- data/ext/asyncengine/libuv/src/uv-common.c +68 -38
- data/ext/asyncengine/libuv/src/uv-common.h +104 -20
- data/ext/asyncengine/libuv/src/uv-common.o +0 -0
- data/ext/asyncengine/libuv/src/win/async.c +20 -17
- data/ext/asyncengine/libuv/src/win/core.c +44 -31
- data/ext/asyncengine/libuv/src/win/dl.c +40 -36
- data/ext/asyncengine/libuv/src/win/error.c +21 -1
- data/ext/asyncengine/libuv/src/win/fs-event.c +19 -21
- data/ext/asyncengine/libuv/src/win/fs.c +541 -189
- data/ext/asyncengine/libuv/src/win/getaddrinfo.c +56 -63
- data/ext/asyncengine/libuv/src/win/handle-inl.h +145 -0
- data/ext/asyncengine/libuv/src/win/handle.c +26 -101
- data/ext/asyncengine/libuv/src/win/internal.h +92 -107
- data/ext/asyncengine/libuv/src/win/loop-watcher.c +6 -14
- data/ext/asyncengine/libuv/src/win/pipe.c +78 -64
- data/ext/asyncengine/libuv/src/win/poll.c +618 -0
- data/ext/asyncengine/libuv/src/win/process-stdio.c +479 -0
- data/ext/asyncengine/libuv/src/win/process.c +147 -274
- data/ext/asyncengine/libuv/src/win/req-inl.h +225 -0
- data/ext/asyncengine/libuv/src/win/req.c +0 -149
- data/ext/asyncengine/libuv/src/{unix/check.c → win/stream-inl.h} +31 -42
- data/ext/asyncengine/libuv/src/win/stream.c +9 -43
- data/ext/asyncengine/libuv/src/win/tcp.c +200 -82
- data/ext/asyncengine/libuv/src/win/thread.c +42 -2
- data/ext/asyncengine/libuv/src/win/threadpool.c +3 -2
- data/ext/asyncengine/libuv/src/win/timer.c +13 -63
- data/ext/asyncengine/libuv/src/win/tty.c +26 -20
- data/ext/asyncengine/libuv/src/win/udp.c +26 -17
- data/ext/asyncengine/libuv/src/win/util.c +312 -167
- data/ext/asyncengine/libuv/src/win/winapi.c +16 -1
- data/ext/asyncengine/libuv/src/win/winapi.h +33 -9
- data/ext/asyncengine/libuv/src/win/winsock.c +88 -1
- data/ext/asyncengine/libuv/src/win/winsock.h +36 -3
- data/ext/asyncengine/libuv/test/benchmark-ares.c +16 -17
- data/ext/asyncengine/libuv/test/benchmark-fs-stat.c +164 -0
- data/ext/asyncengine/libuv/test/benchmark-list.h +9 -0
- data/ext/asyncengine/libuv/{src/unix/prepare.c → test/benchmark-loop-count.c} +42 -33
- data/ext/asyncengine/libuv/test/benchmark-million-timers.c +65 -0
- data/ext/asyncengine/libuv/test/benchmark-pound.c +1 -1
- data/ext/asyncengine/libuv/test/benchmark-sizes.c +2 -0
- data/ext/asyncengine/libuv/test/benchmark-spawn.c +7 -1
- data/ext/asyncengine/libuv/test/benchmark-udp-packet-storm.c +1 -1
- data/ext/asyncengine/libuv/test/echo-server.c +8 -0
- data/ext/asyncengine/libuv/test/run-tests.c +30 -0
- data/ext/asyncengine/libuv/test/runner-unix.c +6 -26
- data/ext/asyncengine/libuv/test/runner-win.c +5 -63
- data/ext/asyncengine/libuv/test/runner.c +10 -1
- data/ext/asyncengine/libuv/test/task.h +0 -8
- data/ext/asyncengine/libuv/test/test-async.c +43 -141
- data/ext/asyncengine/libuv/test/test-callback-order.c +76 -0
- data/ext/asyncengine/libuv/test/test-counters-init.c +2 -3
- data/ext/asyncengine/libuv/test/test-dlerror.c +17 -8
- data/ext/asyncengine/libuv/test/test-fs-event.c +31 -39
- data/ext/asyncengine/libuv/test/test-fs-poll.c +146 -0
- data/ext/asyncengine/libuv/test/test-fs.c +114 -2
- data/ext/asyncengine/libuv/test/test-gethostbyname.c +8 -8
- data/ext/asyncengine/libuv/test/test-hrtime.c +18 -15
- data/ext/asyncengine/libuv/test/test-ipc.c +8 -2
- data/ext/asyncengine/libuv/test/test-list.h +59 -9
- data/ext/asyncengine/libuv/test/test-loop-handles.c +2 -25
- data/ext/asyncengine/libuv/{src/unix/idle.c → test/test-poll-close.c} +37 -39
- data/ext/asyncengine/libuv/test/test-poll.c +573 -0
- data/ext/asyncengine/libuv/test/test-ref.c +79 -63
- data/ext/asyncengine/libuv/test/test-run-once.c +15 -11
- data/ext/asyncengine/libuv/test/test-semaphore.c +111 -0
- data/ext/asyncengine/libuv/test/test-spawn.c +368 -20
- data/ext/asyncengine/libuv/test/test-stdio-over-pipes.c +25 -35
- data/ext/asyncengine/libuv/test/test-tcp-close-while-connecting.c +80 -0
- data/ext/asyncengine/libuv/test/test-tcp-close.c +1 -1
- data/ext/asyncengine/libuv/test/test-tcp-connect-error-after-write.c +95 -0
- data/ext/asyncengine/libuv/test/test-tcp-connect-timeout.c +85 -0
- data/ext/asyncengine/libuv/test/test-tcp-shutdown-after-write.c +131 -0
- data/ext/asyncengine/libuv/test/test-tcp-write-error.c +2 -2
- data/ext/asyncengine/libuv/test/test-tcp-writealot.c +29 -54
- data/ext/asyncengine/libuv/test/test-timer-again.c +1 -1
- data/ext/asyncengine/libuv/test/test-timer.c +23 -1
- data/ext/asyncengine/libuv/test/test-udp-options.c +1 -1
- data/ext/asyncengine/libuv/test/{test-eio-overflow.c → test-walk-handles.c} +31 -44
- data/ext/asyncengine/libuv/uv.gyp +26 -9
- data/ext/asyncengine/rb_utilities.c +54 -0
- data/ext/asyncengine/rb_utilities.h +63 -0
- data/lib/asyncengine.rb +45 -38
- data/lib/asyncengine/asyncengine_ext.so +0 -0
- data/lib/asyncengine/debug.rb +37 -0
- data/lib/asyncengine/handle.rb +9 -0
- data/lib/asyncengine/tcp.rb +28 -0
- data/lib/asyncengine/timer.rb +18 -28
- data/lib/asyncengine/udp.rb +29 -0
- data/lib/asyncengine/utils.rb +32 -0
- data/lib/asyncengine/uv_error.rb +17 -0
- data/lib/asyncengine/version.rb +9 -1
- data/test/ae_test_helper.rb +62 -0
- data/test/test_basic.rb +169 -0
- data/test/test_call_from_other_thread.rb +55 -0
- data/test/test_error.rb +92 -0
- data/test/test_ip_utils.rb +44 -0
- data/test/test_next_tick.rb +37 -0
- data/test/test_resolver.rb +51 -0
- data/test/test_threads.rb +69 -0
- data/test/test_timer.rb +95 -0
- data/test/test_udp.rb +216 -0
- data/test/test_utils.rb +49 -0
- metadata +84 -57
- data/ext/asyncengine/libuv/mkmf.log +0 -24
- data/ext/asyncengine/libuv/src/unix/cares.c +0 -194
- data/ext/asyncengine/libuv/src/unix/cares.o +0 -0
- data/ext/asyncengine/libuv/src/unix/check.o +0 -0
- data/ext/asyncengine/libuv/src/unix/idle.o +0 -0
- data/ext/asyncengine/libuv/src/unix/prepare.o +0 -0
- data/ext/asyncengine/libuv/src/win/cares.c +0 -290
- data/lib/asyncengine/errors.rb +0 -5
- data/lib/asyncengine/next_tick.rb +0 -24
Binary file
|
@@ -211,7 +211,8 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
|
|
211
211
|
uv_cpu_info_t* cpu_info;
|
212
212
|
|
213
213
|
size = sizeof(model);
|
214
|
-
if (sysctlbyname("
|
214
|
+
if (sysctlbyname("machdep.cpu.brand_string", &model, &size, NULL, 0) < 0 &&
|
215
|
+
sysctlbyname("hw.model", &model, &size, NULL, 0) < 0) {
|
215
216
|
return uv__new_sys_error(errno);
|
216
217
|
}
|
217
218
|
size = sizeof(cpuspeed);
|
@@ -27,65 +27,57 @@
|
|
27
27
|
#include <string.h>
|
28
28
|
#include <locale.h>
|
29
29
|
|
30
|
-
|
31
|
-
* errors to the caller but there is only dlerror() and that returns a string -
|
32
|
-
* a string that may or may not be safe to keep a reference to...
|
33
|
-
*/
|
34
|
-
static const uv_err_t uv_inval_ = { UV_EINVAL, EINVAL };
|
35
|
-
|
30
|
+
static int uv__dlerror(uv_lib_t* lib);
|
36
31
|
|
37
|
-
uv_err_t uv_dlopen(const char* filename, uv_lib_t* library) {
|
38
|
-
void* handle = dlopen(filename, RTLD_LAZY);
|
39
|
-
if (handle == NULL) {
|
40
|
-
return uv_inval_;
|
41
|
-
}
|
42
32
|
|
43
|
-
|
44
|
-
|
33
|
+
int uv_dlopen(const char* filename, uv_lib_t* lib) {
|
34
|
+
dlerror(); /* Reset error status. */
|
35
|
+
lib->errmsg = NULL;
|
36
|
+
lib->handle = dlopen(filename, RTLD_LAZY);
|
37
|
+
return uv__dlerror(lib);
|
45
38
|
}
|
46
39
|
|
47
40
|
|
48
|
-
|
49
|
-
if (
|
50
|
-
|
41
|
+
void uv_dlclose(uv_lib_t* lib) {
|
42
|
+
if (lib->errmsg) {
|
43
|
+
free(lib->errmsg);
|
44
|
+
lib->errmsg = NULL;
|
51
45
|
}
|
52
46
|
|
53
|
-
|
47
|
+
if (lib->handle) {
|
48
|
+
/* Ignore errors. No good way to signal them without leaking memory. */
|
49
|
+
dlclose(lib->handle);
|
50
|
+
lib->handle = NULL;
|
51
|
+
}
|
54
52
|
}
|
55
53
|
|
56
54
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
55
|
+
int uv_dlsym(uv_lib_t* lib, const char* name, void** ptr) {
|
56
|
+
dlerror(); /* Reset error status. */
|
57
|
+
*ptr = dlsym(lib->handle, name);
|
58
|
+
return uv__dlerror(lib);
|
59
|
+
}
|
62
60
|
|
63
|
-
address = dlsym(library, name);
|
64
61
|
|
65
|
-
|
66
|
-
|
67
|
-
}
|
68
|
-
|
69
|
-
*ptr = (void*) address;
|
70
|
-
return uv_ok_;
|
62
|
+
const char* uv_dlerror(uv_lib_t* lib) {
|
63
|
+
return lib->errmsg ? lib->errmsg : "no error";
|
71
64
|
}
|
72
65
|
|
73
66
|
|
74
|
-
|
75
|
-
|
76
|
-
/* Make uv_dlerror() be independent of locale */
|
77
|
-
char* loc = setlocale(LC_MESSAGES, NULL);
|
78
|
-
if(strcmp(loc, "C") == 0) {
|
79
|
-
return strdup(dlerror());
|
80
|
-
} else {
|
81
|
-
setlocale(LC_MESSAGES, "C");
|
82
|
-
buf = dlerror();
|
83
|
-
setlocale(LC_MESSAGES, loc);
|
84
|
-
return strdup(buf);
|
85
|
-
}
|
86
|
-
}
|
67
|
+
static int uv__dlerror(uv_lib_t* lib) {
|
68
|
+
char* errmsg;
|
87
69
|
|
70
|
+
if (lib->errmsg)
|
71
|
+
free(lib->errmsg);
|
88
72
|
|
89
|
-
|
90
|
-
|
73
|
+
errmsg = dlerror();
|
74
|
+
|
75
|
+
if (errmsg) {
|
76
|
+
lib->errmsg = strdup(errmsg);
|
77
|
+
return -1;
|
78
|
+
}
|
79
|
+
else {
|
80
|
+
lib->errmsg = NULL;
|
81
|
+
return 0;
|
82
|
+
}
|
91
83
|
}
|
Binary file
|
Binary file
|
@@ -59,6 +59,7 @@ void uv_fatal_error(const int errorno, const char* syscall) {
|
|
59
59
|
uv_err_code uv_translate_sys_error(int sys_errno) {
|
60
60
|
switch (sys_errno) {
|
61
61
|
case 0: return UV_OK;
|
62
|
+
case EIO: return UV_EIO;
|
62
63
|
case EPERM: return UV_EPERM;
|
63
64
|
case ENOSYS: return UV_ENOSYS;
|
64
65
|
case ENOTSOCK: return UV_ENOTSOCK;
|
@@ -68,6 +69,9 @@ uv_err_code uv_translate_sys_error(int sys_errno) {
|
|
68
69
|
case EBADF: return UV_EBADF;
|
69
70
|
case EPIPE: return UV_EPIPE;
|
70
71
|
case EAGAIN: return UV_EAGAIN;
|
72
|
+
#if EWOULDBLOCK != EAGAIN
|
73
|
+
case EWOULDBLOCK: return UV_EAGAIN;
|
74
|
+
#endif
|
71
75
|
case ECONNRESET: return UV_ECONNRESET;
|
72
76
|
case EFAULT: return UV_EFAULT;
|
73
77
|
case EMFILE: return UV_EMFILE;
|
@@ -92,6 +96,8 @@ uv_err_code uv_translate_sys_error(int sys_errno) {
|
|
92
96
|
case EBUSY: return UV_EBUSY;
|
93
97
|
case ENOTEMPTY: return UV_ENOTEMPTY;
|
94
98
|
case ENOSPC: return UV_ENOSPC;
|
99
|
+
case EROFS: return UV_EROFS;
|
100
|
+
case ENOMEM: return UV_ENOMEM;
|
95
101
|
default: return UV_UNKNOWN;
|
96
102
|
}
|
97
103
|
UNREACHABLE();
|
Binary file
|
@@ -608,9 +608,6 @@ ev_syserr (const char *msg)
|
|
608
608
|
static void *
|
609
609
|
ev_realloc_emul (void *ptr, long size)
|
610
610
|
{
|
611
|
-
#if __GLIBC__
|
612
|
-
return realloc (ptr, size);
|
613
|
-
#else
|
614
611
|
/* some systems, notably openbsd and darwin, fail to properly
|
615
612
|
* implement realloc (x, 0) (as required by both ansi c-89 and
|
616
613
|
* the single unix specification, so work around them here.
|
@@ -621,7 +618,6 @@ ev_realloc_emul (void *ptr, long size)
|
|
621
618
|
|
622
619
|
free (ptr);
|
623
620
|
return 0;
|
624
|
-
#endif
|
625
621
|
}
|
626
622
|
|
627
623
|
static void *(*alloc)(void *ptr, long size) = ev_realloc_emul;
|
@@ -2538,6 +2534,14 @@ ev_run (EV_P_ int flags)
|
|
2538
2534
|
#endif
|
2539
2535
|
}
|
2540
2536
|
|
2537
|
+
/* libuv special */
|
2538
|
+
void
|
2539
|
+
ev__run (EV_P_ ev_tstamp waittime)
|
2540
|
+
{
|
2541
|
+
fd_reify (EV_A);
|
2542
|
+
backend_poll (EV_A_ waittime);
|
2543
|
+
}
|
2544
|
+
|
2541
2545
|
void
|
2542
2546
|
ev_break (EV_P_ int how)
|
2543
2547
|
{
|
Binary file
|
@@ -49,7 +49,6 @@
|
|
49
49
|
uv__set_sys_error(loop, ENOMEM); \
|
50
50
|
return -1; \
|
51
51
|
} \
|
52
|
-
uv_ref(loop); \
|
53
52
|
} else { \
|
54
53
|
/* sync */ \
|
55
54
|
req->result = func(args); \
|
@@ -66,8 +65,7 @@ static void uv_fs_req_init(uv_loop_t* loop, uv_fs_t* req, uv_fs_type fs_type,
|
|
66
65
|
/* Make sure the thread pool is initialized. */
|
67
66
|
uv_eio_init(loop);
|
68
67
|
|
69
|
-
uv__req_init(loop,
|
70
|
-
req->type = UV_FS;
|
68
|
+
uv__req_init(loop, req, UV_FS);
|
71
69
|
req->loop = loop;
|
72
70
|
req->fs_type = fs_type;
|
73
71
|
req->cb = cb;
|
@@ -76,10 +74,17 @@ static void uv_fs_req_init(uv_loop_t* loop, uv_fs_t* req, uv_fs_type fs_type,
|
|
76
74
|
req->path = path ? strdup(path) : NULL;
|
77
75
|
req->errorno = 0;
|
78
76
|
req->eio = NULL;
|
77
|
+
|
78
|
+
/* synchronous requests don't increase the reference count */
|
79
|
+
if (!req->cb)
|
80
|
+
uv__req_unregister(req->loop, req);
|
79
81
|
}
|
80
82
|
|
81
83
|
|
82
84
|
void uv_fs_req_cleanup(uv_fs_t* req) {
|
85
|
+
if (req->cb)
|
86
|
+
uv__req_unregister(req->loop, req);
|
87
|
+
|
83
88
|
free(req->path);
|
84
89
|
req->path = NULL;
|
85
90
|
|
@@ -170,10 +175,9 @@ static int uv__fs_after(eio_req* eio) {
|
|
170
175
|
break;
|
171
176
|
}
|
172
177
|
|
173
|
-
uv_unref(req->loop);
|
174
178
|
req->eio = NULL; /* Freed by libeio */
|
175
|
-
|
176
179
|
req->cb(req);
|
180
|
+
|
177
181
|
return 0;
|
178
182
|
}
|
179
183
|
|
@@ -190,7 +194,6 @@ int uv_fs_open(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags,
|
|
190
194
|
|
191
195
|
if (cb) {
|
192
196
|
/* async */
|
193
|
-
uv_ref(loop);
|
194
197
|
req->eio = eio_open(path, flags, mode, EIO_PRI_DEFAULT, uv__fs_after, req, &loop->uv_eio_channel);
|
195
198
|
if (!req->eio) {
|
196
199
|
uv__set_sys_error(loop, ENOMEM);
|
@@ -215,12 +218,11 @@ int uv_fs_open(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags,
|
|
215
218
|
|
216
219
|
|
217
220
|
int uv_fs_read(uv_loop_t* loop, uv_fs_t* req, uv_file fd, void* buf,
|
218
|
-
size_t length,
|
221
|
+
size_t length, int64_t offset, uv_fs_cb cb) {
|
219
222
|
uv_fs_req_init(loop, req, UV_FS_READ, NULL, cb);
|
220
223
|
|
221
224
|
if (cb) {
|
222
225
|
/* async */
|
223
|
-
uv_ref(loop);
|
224
226
|
req->eio = eio_read(fd, buf, length, offset, EIO_PRI_DEFAULT,
|
225
227
|
uv__fs_after, req, &loop->uv_eio_channel);
|
226
228
|
|
@@ -253,12 +255,11 @@ int uv_fs_unlink(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) {
|
|
253
255
|
|
254
256
|
|
255
257
|
int uv_fs_write(uv_loop_t* loop, uv_fs_t* req, uv_file file, void* buf,
|
256
|
-
size_t length,
|
258
|
+
size_t length, int64_t offset, uv_fs_cb cb) {
|
257
259
|
uv_fs_req_init(loop, req, UV_FS_WRITE, NULL, cb);
|
258
260
|
|
259
261
|
if (cb) {
|
260
262
|
/* async */
|
261
|
-
uv_ref(loop);
|
262
263
|
req->eio = eio_write(file, buf, length, offset, EIO_PRI_DEFAULT,
|
263
264
|
uv__fs_after, req, &loop->uv_eio_channel);
|
264
265
|
if (!req->eio) {
|
@@ -306,7 +307,6 @@ int uv_fs_readdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags,
|
|
306
307
|
|
307
308
|
if (cb) {
|
308
309
|
/* async */
|
309
|
-
uv_ref(loop);
|
310
310
|
req->eio = eio_readdir(path, flags, EIO_PRI_DEFAULT, uv__fs_after, req, &loop->uv_eio_channel);
|
311
311
|
if (!req->eio) {
|
312
312
|
uv__set_sys_error(loop, ENOMEM);
|
@@ -376,7 +376,6 @@ int uv_fs_stat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) {
|
|
376
376
|
|
377
377
|
if (cb) {
|
378
378
|
/* async */
|
379
|
-
uv_ref(loop);
|
380
379
|
req->eio = eio_stat(pathdup, EIO_PRI_DEFAULT, uv__fs_after, req, &loop->uv_eio_channel);
|
381
380
|
|
382
381
|
free(pathdup);
|
@@ -410,7 +409,6 @@ int uv_fs_fstat(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) {
|
|
410
409
|
|
411
410
|
if (cb) {
|
412
411
|
/* async */
|
413
|
-
uv_ref(loop);
|
414
412
|
req->eio = eio_fstat(file, EIO_PRI_DEFAULT, uv__fs_after, req, &loop->uv_eio_channel);
|
415
413
|
|
416
414
|
if (!req->eio) {
|
@@ -461,7 +459,7 @@ int uv_fs_fdatasync(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) {
|
|
461
459
|
}
|
462
460
|
|
463
461
|
|
464
|
-
int uv_fs_ftruncate(uv_loop_t* loop, uv_fs_t* req, uv_file file,
|
462
|
+
int uv_fs_ftruncate(uv_loop_t* loop, uv_fs_t* req, uv_file file, int64_t offset,
|
465
463
|
uv_fs_cb cb) {
|
466
464
|
char* path = NULL;
|
467
465
|
WRAP_EIO(UV_FS_FTRUNCATE, eio_ftruncate, ftruncate, ARGS2(file, offset))
|
@@ -469,7 +467,7 @@ int uv_fs_ftruncate(uv_loop_t* loop, uv_fs_t* req, uv_file file, off_t offset,
|
|
469
467
|
|
470
468
|
|
471
469
|
int uv_fs_sendfile(uv_loop_t* loop, uv_fs_t* req, uv_file out_fd, uv_file in_fd,
|
472
|
-
|
470
|
+
int64_t in_offset, size_t length, uv_fs_cb cb) {
|
473
471
|
char* path = NULL;
|
474
472
|
WRAP_EIO(UV_FS_SENDFILE, eio_sendfile, eio_sendfile_sync,
|
475
473
|
ARGS4(out_fd, in_fd, in_offset, length))
|
@@ -496,7 +494,6 @@ int uv_fs_utime(uv_loop_t* loop, uv_fs_t* req, const char* path, double atime,
|
|
496
494
|
}
|
497
495
|
|
498
496
|
|
499
|
-
#if HAVE_FUTIMES
|
500
497
|
static int _futime(const uv_file fd, double atime, double mtime) {
|
501
498
|
#if __linux__
|
502
499
|
/* utimesat() has nanosecond resolution but we stick to microseconds
|
@@ -508,30 +505,24 @@ static int _futime(const uv_file fd, double atime, double mtime) {
|
|
508
505
|
ts[1].tv_sec = mtime;
|
509
506
|
ts[1].tv_nsec = (unsigned long)(mtime * 1000000) % 1000000 * 1000;
|
510
507
|
return uv__utimesat(fd, NULL, ts, 0);
|
511
|
-
#
|
508
|
+
#elif HAVE_FUTIMES
|
512
509
|
struct timeval tv[2];
|
513
510
|
tv[0].tv_sec = atime;
|
514
511
|
tv[0].tv_usec = (unsigned long)(atime * 1000000) % 1000000;
|
515
512
|
tv[1].tv_sec = mtime;
|
516
513
|
tv[1].tv_usec = (unsigned long)(mtime * 1000000) % 1000000;
|
517
514
|
return futimes(fd, tv);
|
518
|
-
#
|
515
|
+
#else /* !HAVE_FUTIMES */
|
516
|
+
errno = ENOSYS;
|
517
|
+
return -1;
|
518
|
+
#endif
|
519
519
|
}
|
520
|
-
#endif /* HAVE_FUTIMES */
|
521
520
|
|
522
521
|
|
523
522
|
int uv_fs_futime(uv_loop_t* loop, uv_fs_t* req, uv_file file, double atime,
|
524
523
|
double mtime, uv_fs_cb cb) {
|
525
524
|
const char* path = NULL;
|
526
|
-
|
527
|
-
uv_fs_req_init(loop, req, UV_FS_FUTIME, path, cb);
|
528
|
-
|
529
|
-
#if HAVE_FUTIMES
|
530
525
|
WRAP_EIO(UV_FS_FUTIME, eio_futime, _futime, ARGS3(file, atime, mtime))
|
531
|
-
#else
|
532
|
-
uv__set_sys_error(loop, ENOSYS);
|
533
|
-
return -1;
|
534
|
-
#endif
|
535
526
|
}
|
536
527
|
|
537
528
|
|
@@ -553,7 +544,6 @@ int uv_fs_lstat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) {
|
|
553
544
|
|
554
545
|
if (cb) {
|
555
546
|
/* async */
|
556
|
-
uv_ref(loop);
|
557
547
|
req->eio = eio_lstat(pathdup, EIO_PRI_DEFAULT, uv__fs_after, req, &loop->uv_eio_channel);
|
558
548
|
|
559
549
|
free(pathdup);
|
@@ -603,7 +593,6 @@ int uv_fs_readlink(uv_loop_t* loop, uv_fs_t* req, const char* path,
|
|
603
593
|
|
604
594
|
if (cb) {
|
605
595
|
if ((req->eio = eio_readlink(path, EIO_PRI_DEFAULT, uv__fs_after, req, &loop->uv_eio_channel))) {
|
606
|
-
uv_ref(loop);
|
607
596
|
return 0;
|
608
597
|
} else {
|
609
598
|
uv__set_sys_error(loop, ENOMEM);
|
@@ -675,7 +664,7 @@ static void uv__work(eio_req* eio) {
|
|
675
664
|
|
676
665
|
static int uv__after_work(eio_req *eio) {
|
677
666
|
uv_work_t* req = eio->data;
|
678
|
-
|
667
|
+
uv__req_unregister(req->loop, req);
|
679
668
|
if (req->after_work_cb) {
|
680
669
|
req->after_work_cb(req);
|
681
670
|
}
|
@@ -689,14 +678,17 @@ int uv_queue_work(uv_loop_t* loop, uv_work_t* req, uv_work_cb work_cb,
|
|
689
678
|
|
690
679
|
uv_eio_init(loop);
|
691
680
|
|
692
|
-
uv__req_init(loop,
|
693
|
-
uv_ref(loop);
|
681
|
+
uv__req_init(loop, req, UV_WORK);
|
694
682
|
req->loop = loop;
|
695
683
|
req->data = data;
|
696
684
|
req->work_cb = work_cb;
|
697
685
|
req->after_work_cb = after_work_cb;
|
698
686
|
|
699
|
-
req->eio = eio_custom(uv__work,
|
687
|
+
req->eio = eio_custom(uv__work,
|
688
|
+
EIO_PRI_DEFAULT,
|
689
|
+
uv__after_work,
|
690
|
+
req,
|
691
|
+
&loop->uv_eio_channel);
|
700
692
|
|
701
693
|
if (!req->eio) {
|
702
694
|
uv__set_sys_error(loop, ENOMEM);
|
Binary file
|
@@ -27,7 +27,6 @@
|
|
27
27
|
|
28
28
|
#include <assert.h>
|
29
29
|
#include <stdlib.h> /* abort */
|
30
|
-
#include <stddef.h> /* offsetof */
|
31
30
|
|
32
31
|
#if __STRICT_ANSI__
|
33
32
|
# define inline __inline
|
@@ -64,9 +63,6 @@
|
|
64
63
|
# define HAVE_KQUEUE 1
|
65
64
|
#endif
|
66
65
|
|
67
|
-
#define container_of(ptr, type, member) \
|
68
|
-
((type *) ((char *) (ptr) - offsetof(type, member)))
|
69
|
-
|
70
66
|
#define UNREACHABLE() \
|
71
67
|
do { \
|
72
68
|
assert(0 && "unreachable code"); \
|
@@ -82,47 +78,67 @@
|
|
82
78
|
} \
|
83
79
|
while (0)
|
84
80
|
|
81
|
+
#define UV__IO_READ EV_READ
|
82
|
+
#define UV__IO_WRITE EV_WRITE
|
83
|
+
#define UV__IO_ERROR EV_ERROR
|
84
|
+
|
85
85
|
/* flags */
|
86
86
|
enum {
|
87
|
-
UV_CLOSING
|
88
|
-
UV_CLOSED
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
UV_TIMER_REPEAT = 0x100
|
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. */
|
98
97
|
};
|
99
98
|
|
99
|
+
inline static void uv__req_init(uv_loop_t* loop,
|
100
|
+
uv_req_t* req,
|
101
|
+
uv_req_type type) {
|
102
|
+
loop->counters.req_init++;
|
103
|
+
req->type = type;
|
104
|
+
uv__req_register(loop, req);
|
105
|
+
}
|
106
|
+
#define uv__req_init(loop, req, type) \
|
107
|
+
uv__req_init((loop), (uv_req_t*)(req), (type))
|
108
|
+
|
100
109
|
/* core */
|
101
110
|
void uv__handle_init(uv_loop_t* loop, uv_handle_t* handle, uv_handle_type type);
|
102
|
-
int uv__nonblock(int fd, int set)
|
103
|
-
int uv__cloexec(int fd, int set)
|
111
|
+
int uv__nonblock(int fd, int set);
|
112
|
+
int uv__cloexec(int fd, int set);
|
104
113
|
int uv__socket(int domain, int type, int protocol);
|
105
114
|
int uv__dup(int fd);
|
115
|
+
int uv_async_stop(uv_async_t* handle);
|
116
|
+
|
117
|
+
void uv__io_init(uv__io_t* handle, uv__io_cb cb, int fd, int events);
|
118
|
+
void uv__io_set(uv__io_t* handle, uv__io_cb cb, int fd, int events);
|
119
|
+
void uv__io_start(uv_loop_t* loop, uv__io_t* handle);
|
120
|
+
void uv__io_stop(uv_loop_t* loop, uv__io_t* handle);
|
121
|
+
void uv__io_feed(uv_loop_t* loop, uv__io_t* handle, int event);
|
122
|
+
int uv__io_active(uv__io_t* handle);
|
106
123
|
|
107
124
|
/* loop */
|
108
125
|
int uv__loop_init(uv_loop_t* loop, int default_loop);
|
109
126
|
void uv__loop_delete(uv_loop_t* loop);
|
127
|
+
void uv__run_idle(uv_loop_t* loop);
|
128
|
+
void uv__run_check(uv_loop_t* loop);
|
129
|
+
void uv__run_prepare(uv_loop_t* loop);
|
110
130
|
|
111
131
|
/* error */
|
112
132
|
uv_err_code uv_translate_sys_error(int sys_errno);
|
113
133
|
void uv_fatal_error(const int errorno, const char* syscall);
|
114
134
|
|
115
|
-
/* requests */
|
116
|
-
void uv__req_init(uv_loop_t* loop, uv_req_t*);
|
117
|
-
|
118
135
|
/* stream */
|
119
136
|
void uv__stream_init(uv_loop_t* loop, uv_stream_t* stream,
|
120
137
|
uv_handle_type type);
|
121
138
|
int uv__stream_open(uv_stream_t*, int fd, int flags);
|
122
139
|
void uv__stream_destroy(uv_stream_t* stream);
|
123
|
-
void
|
124
|
-
|
125
|
-
int uv__accept(int sockfd, struct sockaddr* saddr, socklen_t len);
|
140
|
+
void uv__server_io(uv_loop_t* loop, uv__io_t* watcher, int events);
|
141
|
+
int uv__accept(int sockfd);
|
126
142
|
int uv__connect(uv_connect_t* req, uv_stream_t* stream, struct sockaddr* addr,
|
127
143
|
socklen_t addrlen, uv_connect_cb cb);
|
128
144
|
|
@@ -133,19 +149,18 @@ int uv__tcp_keepalive(uv_tcp_t* handle, int enable, unsigned int delay);
|
|
133
149
|
|
134
150
|
/* pipe */
|
135
151
|
int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb);
|
136
|
-
void uv__pipe_accept(EV_P_ ev_io* watcher, int revents);
|
137
152
|
|
138
|
-
/*
|
139
|
-
|
140
|
-
int
|
141
|
-
int uv__prepare_active(const uv_prepare_t* handle);
|
142
|
-
int uv__timer_active(const uv_timer_t* handle);
|
153
|
+
/* timer */
|
154
|
+
void uv__run_timers(uv_loop_t* loop);
|
155
|
+
unsigned int uv__next_timeout(uv_loop_t* loop);
|
143
156
|
|
157
|
+
/* various */
|
144
158
|
void uv__async_close(uv_async_t* handle);
|
145
159
|
void uv__check_close(uv_check_t* handle);
|
146
160
|
void uv__fs_event_close(uv_fs_event_t* handle);
|
147
161
|
void uv__idle_close(uv_idle_t* handle);
|
148
162
|
void uv__pipe_close(uv_pipe_t* handle);
|
163
|
+
void uv__poll_close(uv_poll_t* handle);
|
149
164
|
void uv__prepare_close(uv_prepare_t* handle);
|
150
165
|
void uv__process_close(uv_process_t* handle);
|
151
166
|
void uv__stream_close(uv_stream_t* handle);
|
@@ -153,8 +168,12 @@ void uv__timer_close(uv_timer_t* handle);
|
|
153
168
|
void uv__udp_close(uv_udp_t* handle);
|
154
169
|
void uv__udp_finish_close(uv_udp_t* handle);
|
155
170
|
|
156
|
-
#
|
157
|
-
#define UV__F_NONBLOCK
|
171
|
+
#ifdef UV__O_NONBLOCK
|
172
|
+
# define UV__F_NONBLOCK UV__O_NONBLOCK
|
173
|
+
#else
|
174
|
+
# define UV__F_NONBLOCK 1
|
175
|
+
#endif
|
176
|
+
|
158
177
|
int uv__make_socketpair(int fds[2], int flags);
|
159
178
|
int uv__make_pipe(int fds[2], int flags);
|
160
179
|
|