Browse Source

Upgrade libuv to 8fd916d6ddc9c7fd0e3e8e668efbc2d782e8e742

v0.7.4-release
Ryan Dahl 14 years ago
parent
commit
1cb7b67ac3
  1. 1
      deps/uv/AUTHORS
  2. 1
      deps/uv/msvs/libuv-test.vcxproj
  3. 2
      deps/uv/test/benchmark-sizes.c
  4. 164
      deps/uv/test/test-bind6-error.c
  5. 8
      deps/uv/test/test-get-currentexe.c
  6. 18
      deps/uv/test/test-gethostbyname.c
  7. 14
      deps/uv/test/test-hrtime.c
  8. 16
      deps/uv/test/test-list.h
  9. 68
      deps/uv/uv-common.c
  10. 51
      deps/uv/uv-common.h
  11. 4
      deps/uv/uv-darwin.c
  12. 2
      deps/uv/uv-freebsd.c
  13. 4
      deps/uv/uv-linux.c
  14. 4
      deps/uv/uv-sunos.c
  15. 210
      deps/uv/uv-unix.c
  16. 5
      deps/uv/uv-unix.h
  17. 92
      deps/uv/uv-win.c
  18. 8
      deps/uv/uv-win.h
  19. 70
      deps/uv/uv.h

1
deps/uv/AUTHORS

@ -8,3 +8,4 @@ Vanilla Hsu <vanilla@fatpipi.com>
Ben Noordhuis <info@bnoordhuis.nl>
Henry Rawas <henryr@schakra.com>
Robert Mustacchi <rm@joyent.com>
Matt Stevens <matt@alloysoft.com>

1
deps/uv/msvs/libuv-test.vcxproj

@ -148,6 +148,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\test\test-async.c" />
<ClCompile Include="..\test\test-bind6-error.c" />
<ClCompile Include="..\test\test-delayed-accept.c" />
<ClCompile Include="..\test\test-callback-stack.c" />
<ClCompile Include="..\test\test-connection-fail.c" />

2
deps/uv/test/benchmark-sizes.c

@ -31,7 +31,5 @@ BENCHMARK_IMPL(sizes) {
LOGF("uv_idle_t: %u bytes\n", (unsigned int) sizeof(uv_idle_t));
LOGF("uv_async_t: %u bytes\n", (unsigned int) sizeof(uv_async_t));
LOGF("uv_timer_t: %u bytes\n", (unsigned int) sizeof(uv_timer_t));
LOGF("uv_ares_task_t: %u bytes\n", (unsigned int) sizeof(uv_ares_task_t));
LOGF("uv_ares_action_t: %u bytes\n", (unsigned int) sizeof(uv_ares_action_t));
return 0;
}

164
deps/uv/test/test-bind6-error.c

@ -0,0 +1,164 @@
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include "../uv.h"
#include "task.h"
#include <stdio.h>
#include <stdlib.h>
static int close_cb_called = 0;
static void close_cb(uv_handle_t* handle) {
ASSERT(handle != NULL);
close_cb_called++;
}
TEST_IMPL(bind6_error_addrinuse) {
struct sockaddr_in6 addr = uv_ip6_addr("::", TEST_PORT);
uv_tcp_t server1, server2;
int r;
uv_init();
r = uv_tcp_init(&server1);
ASSERT(r == 0);
r = uv_bind6(&server1, addr);
ASSERT(r == 0);
r = uv_tcp_init(&server2);
ASSERT(r == 0);
r = uv_bind6(&server2, addr);
ASSERT(r == 0);
r = uv_listen(&server1, 128, NULL);
ASSERT(r == 0);
r = uv_listen(&server2, 128, NULL);
ASSERT(r == -1);
ASSERT(uv_last_error().code == UV_EADDRINUSE);
uv_close((uv_handle_t*)&server1, close_cb);
uv_close((uv_handle_t*)&server2, close_cb);
uv_run();
ASSERT(close_cb_called == 2);
return 0;
}
TEST_IMPL(bind6_error_addrnotavail) {
struct sockaddr_in6 addr = uv_ip6_addr("4:4:4:4:4:4:4:4", TEST_PORT);
uv_tcp_t server;
int r;
uv_init();
r = uv_tcp_init(&server);
ASSERT(r == 0);
r = uv_bind6(&server, addr);
ASSERT(r == -1);
ASSERT(uv_last_error().code == UV_EADDRNOTAVAIL);
uv_close((uv_handle_t*)&server, close_cb);
uv_run();
ASSERT(close_cb_called == 1);
return 0;
}
TEST_IMPL(bind6_error_fault) {
char garbage[] = "blah blah blah blah blah blah blah blah blah blah blah blah";
struct sockaddr_in6* garbage_addr;
uv_tcp_t server;
int r;
garbage_addr = (struct sockaddr_in6*) &garbage;
uv_init();
r = uv_tcp_init(&server);
ASSERT(r == 0);
r = uv_bind6(&server, *garbage_addr);
ASSERT(r == -1);
ASSERT(uv_last_error().code == UV_EFAULT);
uv_close((uv_handle_t*)&server, close_cb);
uv_run();
ASSERT(close_cb_called == 1);
return 0;
}
/* Notes: On Linux uv_bind6(server, NULL) will segfault the program. */
TEST_IMPL(bind6_error_inval) {
struct sockaddr_in6 addr1 = uv_ip6_addr("::", TEST_PORT);
struct sockaddr_in6 addr2 = uv_ip6_addr("::", TEST_PORT_2);
uv_tcp_t server;
int r;
uv_init();
r = uv_tcp_init(&server);
ASSERT(r == 0);
r = uv_bind6(&server, addr1);
ASSERT(r == 0);
r = uv_bind6(&server, addr2);
ASSERT(r == -1);
ASSERT(uv_last_error().code == UV_EINVAL);
uv_close((uv_handle_t*)&server, close_cb);
uv_run();
ASSERT(close_cb_called == 1);
return 0;
}
TEST_IMPL(bind6_localhost_ok) {
struct sockaddr_in6 addr = uv_ip6_addr("::1", TEST_PORT);
uv_tcp_t server;
int r;
uv_init();
r = uv_tcp_init(&server);
ASSERT(r == 0);
r = uv_bind6(&server, addr);
ASSERT(r == 0);
return 0;
}

8
deps/uv/test/test-get-currentexe.c

@ -33,20 +33,20 @@ TEST_IMPL(get_currentexe) {
int r;
size = sizeof(buffer) / sizeof(buffer[0]);
r = uv_get_exepath(buffer, &size);
r = uv_exepath(buffer, &size);
ASSERT(!r);
match = strstr(buffer, executable_path);
/* Verify that the path returned from uv_get_exepath is a subdirectory of executable_path */
/* Verify that the path returned from uv_exepath is a subdirectory of executable_path */
ASSERT(match && !strcmp(match, executable_path));
ASSERT(size == strlen(buffer));
/* Negative tests */
size = sizeof(buffer) / sizeof(buffer[0]);
r = uv_get_exepath(NULL, &size);
r = uv_exepath(NULL, &size);
ASSERT(r == -1);
r = uv_get_exepath(buffer, NULL);
r = uv_exepath(buffer, NULL);
ASSERT(r == -1);
return 0;

18
deps/uv/test/test-gethostbyname.c

@ -35,13 +35,6 @@ int bynamecallbacksig;
int ares_byaddrcallbacks;
int byaddrcallbacksig;
static uv_buf_t alloc_cb(uv_handle_t* handle, size_t size) {
uv_buf_t buf;
buf.base = (char*)malloc(size);
buf.len = size;
return buf;
}
static void aresbynamecallback( void *arg,
int status,
int timeouts,
@ -52,9 +45,10 @@ static void aresbynamecallback( void *arg,
ASSERT(*iargs == bynamecallbacksig);
ASSERT(timeouts == 0);
ares_bynamecallbacks++;
printf("aresbynamecallback %d\n", ares_bynamecallbacks++);
}
static void aresbyaddrcallback( void *arg,
int status,
int timeouts,
@ -65,11 +59,11 @@ static void aresbyaddrcallback( void *arg,
ASSERT(*iargs == byaddrcallbacksig);
ASSERT(timeouts == 0);
ares_byaddrcallbacks++;
printf("aresbyaddrcallback %d\n", ares_byaddrcallbacks++);
}
static void prep_tcploopback()
{
static void prep_tcploopback() {
/* for test, use echo server - TCP port TEST_PORT on loopback */
struct sockaddr_in test_server = uv_ip4_addr("127.0.0.1", 0);
int rc;
@ -97,7 +91,7 @@ TEST_IMPL(gethostbyname) {
return 1;
}
uv_init(alloc_cb);
uv_init();
printf("Start basic gethostbyname test\n");
prep_tcploopback();

14
deps/uv/test/test-hrtime.c

@ -23,6 +23,16 @@
#include "task.h"
#ifndef MICROSEC
# define MICROSEC 1000000
#endif
#ifndef NANOSEC
# define NANOSEC 1000000000
#endif
/*
* We expect the amount of time passed to be at least one us plus two system
* calls. Therefore checking that at least a microsecond has elapsed is safe.
@ -30,9 +40,9 @@
TEST_IMPL(hrtime) {
uint64_t a, b, diff;
a = uv_get_hrtime();
a = uv_hrtime();
uv_sleep(1);
b = uv_get_hrtime();
b = uv_hrtime();
diff = b - a;

16
deps/uv/test/test-list.h

@ -28,6 +28,11 @@ TEST_DECLARE (bind_error_addrnotavail_2)
TEST_DECLARE (bind_error_fault)
TEST_DECLARE (bind_error_inval)
TEST_DECLARE (bind_localhost_ok)
TEST_DECLARE (bind6_error_addrinuse)
TEST_DECLARE (bind6_error_addrnotavail)
TEST_DECLARE (bind6_error_fault)
TEST_DECLARE (bind6_error_inval)
TEST_DECLARE (bind6_localhost_ok)
TEST_DECLARE (connection_fail)
TEST_DECLARE (connection_fail_doesnt_auto_close)
TEST_DECLARE (shutdown_eof)
@ -61,17 +66,18 @@ TASK_LIST_START
TEST_HELPER (tcp_writealot, echo_server)
TEST_ENTRY (bind_error_addrinuse)
TEST_ENTRY (bind_error_addrnotavail_1)
TEST_ENTRY (bind_error_addrnotavail_2)
TEST_ENTRY (bind_error_fault)
TEST_ENTRY (bind_error_inval)
TEST_ENTRY (bind_localhost_ok)
TEST_ENTRY (bind6_error_addrinuse)
TEST_ENTRY (bind6_error_addrnotavail)
TEST_ENTRY (bind6_error_fault)
TEST_ENTRY (bind6_error_inval)
TEST_ENTRY (bind6_localhost_ok)
TEST_ENTRY (connection_fail)
TEST_ENTRY (connection_fail_doesnt_auto_close)

68
deps/uv/uv-common.c

@ -20,11 +20,19 @@
*/
#include "uv.h"
#include "uv-common.h"
#include <assert.h>
#include <stddef.h> /* NULL */
#include <string.h> /* memset */
/* use inet_pton from c-ares if necessary */
#include "ares_config.h"
#include "c-ares/inet_net_pton.h"
/* list used for ares task handles */
static uv_ares_task_t* uv_ares_handles_ = NULL;
static uv_counters_t counters;
@ -89,3 +97,63 @@ struct sockaddr_in uv_ip4_addr(const char* ip, int port) {
return addr;
}
struct sockaddr_in6 uv_ip6_addr(const char* ip, int port) {
struct sockaddr_in6 addr;
memset(&addr, 0, sizeof(struct sockaddr_in6));
addr.sin6_family = AF_INET6;
addr.sin6_port = htons(port);
ares_inet_pton(AF_INET6, ip, &addr.sin6_addr);
return addr;
}
/* find matching ares handle in list */
void uv_add_ares_handle(uv_ares_task_t* handle) {
handle->ares_next = uv_ares_handles_;
handle->ares_prev = NULL;
if (uv_ares_handles_) {
uv_ares_handles_->ares_prev = handle;
}
uv_ares_handles_ = handle;
}
/* find matching ares handle in list */
/* TODO: faster lookup */
uv_ares_task_t* uv_find_ares_handle(ares_socket_t sock) {
uv_ares_task_t* handle = uv_ares_handles_;
while (handle != NULL) {
if (handle->sock == sock) {
break;
}
handle = handle->ares_next;
}
return handle;
}
/* remove ares handle in list */
void uv_remove_ares_handle(uv_ares_task_t* handle) {
if (handle == uv_ares_handles_) {
uv_ares_handles_ = handle->ares_next;
}
if (handle->ares_next) {
handle->ares_next->ares_prev = handle->ares_prev;
}
if (handle->ares_prev) {
handle->ares_prev->ares_next = handle->ares_next;
}
}
/* Returns 1 if the uv_ares_handles_ list is empty. 0 otherwise. */
int uv_ares_handles_empty() {
return uv_ares_handles_ ? 0 : 1;
}

51
deps/uv/uv-common.h

@ -0,0 +1,51 @@
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
/*
* This file is private to libuv. It provides common functionality to both
* Windows and Unix backends.
*/
#ifndef UV_COMMON_H_
#define UV_COMMON_H_
#include "uv.h"
/*
* Subclass of uv_handle_t. Used for integration of c-ares.
*/
typedef struct uv_ares_task_s uv_ares_task_t;
struct uv_ares_task_s {
UV_HANDLE_FIELDS
UV_ARES_TASK_PRIVATE_FIELDS
uv_ares_task_t* ares_prev;
uv_ares_task_t* ares_next;
};
void uv_remove_ares_handle(uv_ares_task_t* handle);
uv_ares_task_t* uv_find_ares_handle(ares_socket_t sock);
void uv_add_ares_handle(uv_ares_task_t* handle);
int uv_ares_handles_empty();
#endif /* UV_COMMON_H_ */

4
deps/uv/uv-darwin.c

@ -26,7 +26,7 @@
#include <mach/mach_time.h>
uint64_t uv_get_hrtime() {
uint64_t uv_hrtime() {
uint64_t time;
Nanoseconds enano;
time = mach_absolute_time();
@ -35,7 +35,7 @@ uint64_t uv_get_hrtime() {
}
int uv_get_exepath(char* buffer, size_t* size) {
int uv_exepath(char* buffer, size_t* size) {
uint32_t usize;
int result;
char* path;

2
deps/uv/uv-freebsd.c

@ -21,7 +21,7 @@
#include "uv.h"
int uv_get_exepath(char* buffer, size_t* size) {
int uv_exepath(char* buffer, size_t* size) {
uint32_t usize;
int result;
char* path;

4
deps/uv/uv-linux.c

@ -28,14 +28,14 @@
* There's probably some way to get time from Linux than gettimeofday(). What
* it is, I don't know.
*/
uint64_t uv_get_hrtime() {
uint64_t uv_hrtime() {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return (ts.tv_sec * NANOSEC + ts.tv_nsec);
}
int uv_get_exepath(char* buffer, size_t* size) {
int uv_exepath(char* buffer, size_t* size) {
uint32_t usize;
int result;
char* path;

4
deps/uv/uv-sunos.c

@ -27,7 +27,7 @@
#include <sys/time.h>
uint64_t uv_get_hrtime() {
uint64_t uv_hrtime() {
return (gethrtime());
}
@ -37,7 +37,7 @@ uint64_t uv_get_hrtime() {
* of the function, but this function could be called by multiple consumers and
* we don't want to potentially create a race condition in the use of snprintf.
*/
int uv_get_exepath(char* buffer, size_t* size) {
int uv_exepath(char* buffer, size_t* size) {
size_t res;
pid_t pid;
char buf[PATH_MAX];

210
deps/uv/uv-unix.c

@ -19,6 +19,7 @@
*/
#include "uv.h"
#include "uv-common.h"
#include <stddef.h> /* NULL */
#include <stdio.h> /* printf */
@ -44,6 +45,18 @@
static uv_err_t last_err;
struct uv_ares_data_s {
ares_channel channel;
/*
* While the channel is active this timer is called once per second to be sure
* that we're always calling ares_process. See the warning above the
* definition of ares_timeout().
*/
ev_timer timer;
};
static struct uv_ares_data_s ares_data;
void uv__tcp_io(EV_P_ ev_io* watcher, int revents);
void uv__next(EV_P_ ev_idle* watcher, int revents);
@ -67,6 +80,30 @@ void uv_flag_set(uv_handle_t* handle, int flag) {
}
/* TODO Share this code with Windows. */
/* TODO Expose callback to user to handle fatal error like V8 does. */
static void uv_fatal_error(const int errorno, const char* syscall) {
char* buf = NULL;
const char* errmsg;
if (buf) {
errmsg = buf;
} else {
errmsg = "Unknown error";
}
if (syscall) {
fprintf(stderr, "\nlibuv fatal error. %s: (%d) %s\n", syscall, errorno,
errmsg);
} else {
fprintf(stderr, "\nlibuv fatal error. (%d) %s\n", errorno, errmsg);
}
*((char*)NULL) = 0xff; /* Force debug break */
abort();
}
uv_err_t uv_last_error() {
return last_err;
}
@ -235,13 +272,11 @@ int uv_tcp_init(uv_tcp_t* tcp) {
}
int uv_bind(uv_tcp_t* tcp, struct sockaddr_in addr) {
int addrsize = sizeof(struct sockaddr_in);
int domain = AF_INET;
int uv__bind(uv_tcp_t* tcp, int domain, struct sockaddr* addr, int addrsize) {
int r;
if (tcp->fd <= 0) {
int fd = socket(AF_INET, SOCK_STREAM, 0);
int fd = socket(domain, SOCK_STREAM, 0);
if (fd < 0) {
uv_err_new((uv_handle_t*)tcp, errno);
@ -256,12 +291,7 @@ int uv_bind(uv_tcp_t* tcp, struct sockaddr_in addr) {
assert(tcp->fd >= 0);
if (addr.sin_family != AF_INET) {
uv_err_new((uv_handle_t*)tcp, EFAULT);
return -1;
}
r = bind(tcp->fd, (struct sockaddr*) &addr, addrsize);
r = bind(tcp->fd, addr, addrsize);
tcp->delayed_error = 0;
if (r) {
@ -280,6 +310,26 @@ int uv_bind(uv_tcp_t* tcp, struct sockaddr_in addr) {
}
int uv_bind(uv_tcp_t* tcp, struct sockaddr_in addr) {
if (addr.sin_family != AF_INET) {
uv_err_new((uv_handle_t*)tcp, EFAULT);
return -1;
}
return uv__bind(tcp, AF_INET, (struct sockaddr*)&addr, sizeof(struct sockaddr_in));
}
int uv_bind6(uv_tcp_t* tcp, struct sockaddr_in6 addr) {
if (addr.sin6_family != AF_INET6) {
uv_err_new((uv_handle_t*)tcp, EFAULT);
return -1;
}
return uv__bind(tcp, AF_INET6, (struct sockaddr*)&addr, sizeof(struct sockaddr_in6));
}
int uv_tcp_open(uv_tcp_t* tcp, int fd) {
int yes;
int r;
@ -313,8 +363,8 @@ int uv_tcp_open(uv_tcp_t* tcp, int fd) {
void uv__server_io(EV_P_ ev_io* watcher, int revents) {
int fd;
struct sockaddr addr;
socklen_t addrlen;
struct sockaddr_storage addr;
socklen_t addrlen = sizeof(struct sockaddr_storage);
uv_tcp_t* tcp = watcher->data;
assert(watcher == &tcp->read_watcher ||
@ -330,7 +380,7 @@ void uv__server_io(EV_P_ ev_io* watcher, int revents) {
while (1) {
assert(tcp->accepted_fd < 0);
fd = accept(tcp->fd, &addr, &addrlen);
fd = accept(tcp->fd, (struct sockaddr*)&addr, &addrlen);
if (fd < 0) {
if (errno == EAGAIN) {
@ -1290,17 +1340,145 @@ int64_t uv_timer_get_repeat(uv_timer_t* timer) {
return (int64_t)(1000 * timer->timer_watcher.repeat);
}
/*
* This is called once per second by ares_data.timer. It is used to
* constantly callback into c-ares for possibly processing timeouts.
*/
static void uv__ares_timeout(EV_P_ struct ev_timer* watcher, int revents) {
assert(watcher == &ares_data.timer);
assert(revents == EV_TIMER);
assert(!uv_ares_handles_empty());
ares_process_fd(ares_data.channel, ARES_SOCKET_BAD, ARES_SOCKET_BAD);
}
static void uv__ares_io(EV_P_ struct ev_io* watcher, int revents) {
/* Reset the idle timer */
ev_timer_again(EV_A_ &ares_data.timer);
/* Process DNS responses */
ares_process_fd(ares_data.channel,
revents & EV_READ ? watcher->fd : ARES_SOCKET_BAD,
revents & EV_WRITE ? watcher->fd : ARES_SOCKET_BAD);
}
/* Allocates and returns a new uv_ares_task_t */
static uv_ares_task_t* uv__ares_task_create(int fd) {
uv_ares_task_t* h = malloc(sizeof(uv_ares_task_t));
if (h == NULL) {
uv_fatal_error(ENOMEM, "malloc");
}
h->sock = fd;
ev_io_init(&h->read_watcher, uv__ares_io, fd, EV_READ);
ev_io_init(&h->write_watcher, uv__ares_io, fd, EV_WRITE);
h->read_watcher.data = h;
h->write_watcher.data = h;
}
/* Callback from ares when socket operation is started */
static void uv__ares_sockstate_cb(void* data, ares_socket_t sock,
int read, int write) {
uv_ares_task_t* h = uv_find_ares_handle(sock);
if (read || write) {
if (!h) {
/* New socket */
/* If this is the first socket then start the timer. */
if (!ev_is_active(&ares_data.timer)) {
assert(uv_ares_handles_empty());
ev_timer_again(EV_DEFAULT_UC_ &ares_data.timer);
}
h = uv__ares_task_create(sock);
uv_add_ares_handle(h);
}
if (read) {
ev_io_start(EV_DEFAULT_UC_ &h->read_watcher);
} else {
ev_io_stop(EV_DEFAULT_UC_ &h->read_watcher);
}
if (write) {
ev_io_start(EV_DEFAULT_UC_ &h->write_watcher);
} else {
ev_io_stop(EV_DEFAULT_UC_ &h->write_watcher);
}
} else {
/*
* read == 0 and write == 0 this is c-ares's way of notifying us that
* the socket is now closed. We must free the data associated with
* socket.
*/
assert(h && "When an ares socket is closed we should have a handle for it");
ev_io_stop(EV_DEFAULT_UC_ &h->read_watcher);
ev_io_stop(EV_DEFAULT_UC_ &h->write_watcher);
uv_remove_ares_handle(h);
free(h);
if (uv_ares_handles_empty()) {
ev_timer_stop(EV_DEFAULT_UC_ &ares_data.timer);
}
}
}
/* c-ares integration initialize and terminate */
/* TODO: share this with windows? */
int uv_ares_init_options(ares_channel *channelptr,
struct ares_options *options,
int optmask) {
int r;
r = ares_init_options(channelptr, options, optmask);
return r;
int rc;
/* only allow single init at a time */
if (ares_data.channel != NULL) {
uv_err_new_artificial(NULL, UV_EALREADY);
return -1;
}
/* set our callback as an option */
options->sock_state_cb = uv__ares_sockstate_cb;
options->sock_state_cb_data = &ares_data;
optmask |= ARES_OPT_SOCK_STATE_CB;
/* We do the call to ares_init_option for caller. */
rc = ares_init_options(channelptr, options, optmask);
/* if success, save channel */
if (rc == ARES_SUCCESS) {
ares_data.channel = *channelptr;
}
/*
* Initialize the timeout timer. The timer won't be started until the
* first socket is opened.
*/
ev_init(&ares_data.timer, uv__ares_timeout);
ares_data.timer.repeat = 1.0;
return rc;
}
/* TODO share this with windows? */
void uv_ares_destroy(ares_channel channel) {
/* only allow destroy if did init */
if (ares_data.channel != NULL) {
ev_timer_stop(EV_DEFAULT_UC_ &ares_data.timer);
ares_destroy(channel);
ares_data.channel = NULL;
}
}

5
deps/uv/uv-unix.h

@ -102,7 +102,10 @@ typedef struct {
#define UV_ARES_ACTION_PRIVATE_FIELDS /* TODO */
#define UV_ARES_TASK_PRIVATE_FIELDS /* TODO */
#define UV_ARES_TASK_PRIVATE_FIELDS \
int sock; \
ev_io read_watcher; \
ev_io write_watcher;
#define UV_GETADDRINFO_PRIVATE_FIELDS /* TODO */

92
deps/uv/uv-win.c

@ -26,6 +26,7 @@
#include <stdio.h>
#include "uv.h"
#include "uv-common.h"
#include "tree.h"
/*
@ -213,12 +214,22 @@ static struct sockaddr_in uv_addr_ip4_any_;
static char uv_zero_[] = "";
/*
* Subclass of uv_handle_t. Used for integration of c-ares.
*/
typedef struct uv_ares_action_s uv_ares_action_t;
struct uv_ares_action_s {
UV_HANDLE_FIELDS
struct uv_req_s ares_req;
SOCKET sock;
int read;
int write;
};
void uv_ares_process(uv_ares_action_t* handle, uv_req_t* req);
void uv_ares_task_cleanup(uv_ares_task_t* handle, uv_req_t* req);
/* list used for ares task handles */
static uv_ares_task_t* uv_ares_handles_ = NULL;
/* memory used per ares_channel */
struct uv_ares_channel_s {
ares_channel channel;
@ -748,19 +759,13 @@ int uv_close(uv_handle_t* handle, uv_close_cb close_cb) {
}
int uv_bind(uv_tcp_t* handle, struct sockaddr_in addr) {
int uv__bind(uv_tcp_t* handle, int domain, struct sockaddr* addr, int addrsize) {
DWORD err;
int r;
SOCKET sock;
int addrsize = sizeof(struct sockaddr_in);
if (addr.sin_family != AF_INET) {
uv_set_sys_error(WSAEFAULT);
return -1;
}
if (handle->socket == INVALID_SOCKET) {
sock = socket(AF_INET, SOCK_STREAM, 0);
sock = socket(domain, SOCK_STREAM, 0);
if (sock == INVALID_SOCKET) {
uv_set_sys_error(WSAGetLastError());
return -1;
@ -772,7 +777,7 @@ int uv_bind(uv_tcp_t* handle, struct sockaddr_in addr) {
}
}
r = bind(handle->socket, (struct sockaddr*) &addr, addrsize);
r = bind(handle->socket, addr, addrsize);
if (r == SOCKET_ERROR) {
err = WSAGetLastError();
@ -792,6 +797,26 @@ int uv_bind(uv_tcp_t* handle, struct sockaddr_in addr) {
}
int uv_bind(uv_tcp_t* handle, struct sockaddr_in addr) {
if (addr.sin_family != AF_INET) {
uv_set_sys_error(WSAEFAULT);
return -1;
}
return uv__bind(handle, AF_INET, (struct sockaddr*)&addr, sizeof(struct sockaddr_in));
}
int uv_bind6(uv_tcp_t* handle, struct sockaddr_in6 addr) {
if (addr.sin6_family != AF_INET6) {
uv_set_sys_error(WSAEFAULT);
return -1;
}
return uv__bind(handle, AF_INET6, (struct sockaddr*)&addr, sizeof(struct sockaddr_in6));
}
static void uv_queue_accept(uv_tcp_t* handle) {
uv_req_t* req;
BOOL success;
@ -1732,7 +1757,7 @@ int uv_utf8_to_utf16(const char* utf8Buffer, wchar_t* utf16Buffer, size_t utf16S
}
int uv_get_exepath(char* buffer, size_t* size) {
int uv_exepath(char* buffer, size_t* size) {
int retVal;
size_t utf16Size;
wchar_t* utf16Buffer;
@ -1777,49 +1802,10 @@ done:
}
uint64_t uv_get_hrtime(void) {
uint64_t uv_hrtime(void) {
assert(0 && "implement me");
}
/* find matching ares handle in list */
void uv_add_ares_handle(uv_ares_task_t* handle) {
handle->ares_next = uv_ares_handles_;
handle->ares_prev = NULL;
if (uv_ares_handles_) {
uv_ares_handles_->ares_prev = handle;
}
uv_ares_handles_ = handle;
}
/* find matching ares handle in list */
/* TODO: faster lookup */
uv_ares_task_t* uv_find_ares_handle(ares_socket_t sock) {
uv_ares_task_t* handle = uv_ares_handles_;
while (handle != NULL) {
if (handle->sock == sock) {
break;
}
handle = handle->ares_next;
}
return handle;
}
/* remove ares handle in list */
void uv_remove_ares_handle(uv_ares_task_t* handle) {
if (handle == uv_ares_handles_) {
uv_ares_handles_ = handle->ares_next;
}
if (handle->ares_next) {
handle->ares_next->ares_prev = handle->ares_prev;
}
if (handle->ares_prev) {
handle->ares_prev->ares_next = handle->ares_next;
}
}
/* thread pool callback when socket is signalled */
VOID CALLBACK uv_ares_socksignal_tp(void* parameter, BOOLEAN timerfired) {

8
deps/uv/uv-win.h

@ -107,15 +107,8 @@ typedef struct uv_buf_t {
unsigned int flags; \
uv_err_t error;
#define UV_ARES_ACTION_PRIVATE_FIELDS \
struct uv_req_s ares_req; \
SOCKET sock; \
int read; \
int write;
#define UV_ARES_TASK_PRIVATE_FIELDS \
uv_ares_task_t* ares_prev; \
uv_ares_task_t* ares_next; \
struct uv_req_s ares_req; \
SOCKET sock; \
HANDLE h_wait; \
@ -132,6 +125,5 @@ typedef struct uv_buf_t {
struct addrinfoW* res; \
int retcode;
int uv_utf16_to_utf8(wchar_t* utf16Buffer, size_t utf16Size, char* utf8Buffer, size_t utf8Size);
int uv_utf8_to_utf16(const char* utf8Buffer, wchar_t* utf16Buffer, size_t utf16Size);

70
deps/uv/uv.h

@ -48,10 +48,6 @@ typedef struct uv_check_s uv_check_t;
typedef struct uv_idle_s uv_idle_t;
typedef struct uv_req_s uv_req_t;
typedef struct uv_async_s uv_async_t;
/* TODO: make private */
typedef struct uv_ares_task_s uv_ares_task_t;
/* TODO: make private */
typedef struct uv_ares_action_s uv_ares_action_t;
typedef struct uv_getaddrinfo_s uv_getaddrinfo_t;
@ -223,6 +219,7 @@ struct uv_tcp_s {
int uv_tcp_init(uv_tcp_t* handle);
int uv_bind(uv_tcp_t* handle, struct sockaddr_in);
int uv_bind6(uv_tcp_t* handle, struct sockaddr_in6);
int uv_connect(uv_req_t* req, struct sockaddr_in);
@ -378,25 +375,6 @@ void uv_timer_set_repeat(uv_timer_t* timer, int64_t repeat);
int64_t uv_timer_get_repeat(uv_timer_t* timer);
/*
* Subclass of uv_handle_t. Used for integration of c-ares.
* TODO: make private
*/
struct uv_ares_task_s {
UV_HANDLE_FIELDS
UV_ARES_TASK_PRIVATE_FIELDS
};
/*
* Subclass of uv_handle_t. Used for integration of c-ares.
* TODO: make private
*/
struct uv_ares_action_s {
UV_HANDLE_FIELDS
UV_ARES_ACTION_PRIVATE_FIELDS
};
/* c-ares integration initialize and terminate */
int uv_ares_init_options(ares_channel *channelptr,
struct ares_options *options,
@ -453,9 +431,22 @@ int64_t uv_now();
/* Utility */
struct sockaddr_in uv_ip4_addr(const char* ip, int port);
struct sockaddr_in6 uv_ip6_addr(const char* ip, int port);
/* Gets the executable path */
int uv_get_exepath(char* buffer, size_t* size);
int uv_exepath(char* buffer, size_t* size);
/*
* Returns the current high-resolution real time. This is expressed in
* nanoseconds. It is relative to an arbitrary time in the past. It is not
* related to the time of day and therefore not subject to clock drift. The
* primary use is for measuring performance between intervals.
*
* Note not every platform can support nanosecond resolution; however, this
* value will always be in nanoseconds.
*/
extern uint64_t uv_hrtime(void);
/* the presence of this union forces similar struct layout */
union uv_any_handle {
@ -465,8 +456,6 @@ union uv_any_handle {
uv_idle_t idle;
uv_async_t async;
uv_timer_t timer;
uv_ares_task_t arest;
uv_ares_action_t aresa;
uv_getaddrinfo_t getaddrinfo;
};
@ -484,35 +473,6 @@ typedef struct {
uv_counters_t* uv_counters();
#ifndef SEC
# define SEC 1
#endif
#ifndef MILLISEC
# define MILLISEC 1000
#endif
#ifndef MICROSEC
# define MICROSEC 1000000
#endif
#ifndef NANOSEC
# define NANOSEC 1000000000
#endif
/*
* Returns the current high-resolution real time. This is expressed in
* nanoseconds. It is relative to an arbitrary time in the past. It is not
* related to the time of day and therefore not subject to clock drift. The
* primary use is for measuring performance between intervals.
*
* Note not every platform can support nanosecond resolution; however, this
* value will always be in nanoseconds.
*/
extern uint64_t uv_get_hrtime(void);
#ifdef __cplusplus
}
#endif

Loading…
Cancel
Save