Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
uv: upgrade to 9bd8bd7
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Sep 12, 2011
1 parent 7e7e983 commit 0d80040
Show file tree
Hide file tree
Showing 41 changed files with 91 additions and 204 deletions.
3 changes: 1 addition & 2 deletions deps/uv/include/uv.h
Expand Up @@ -81,11 +81,10 @@ typedef struct uv_work_s uv_work_t;
* All callbacks in libuv are made asynchronously. That is they are never
* made by the function that takes them as a parameter.
*/
void uv_init();
uv_loop_t* uv_loop_new();

void uv_loop_delete(uv_loop_t*);


/*
* Returns the default loop.
*/
Expand Down
20 changes: 9 additions & 11 deletions deps/uv/src/unix/core.c
Expand Up @@ -65,17 +65,6 @@ static void uv__finish_close(uv_handle_t* handle);
#endif


void uv_init() {
default_loop_ptr = &default_loop_struct;
#if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
default_loop_struct.ev = ev_default_loop(EVBACKEND_KQUEUE);
#else
default_loop_struct.ev = ev_default_loop(EVFLAG_AUTO);
#endif
ev_set_userdata(default_loop_struct.ev, default_loop_ptr);
}


void uv_close(uv_handle_t* handle, uv_close_cb close_cb) {
uv_udp_t* udp;
uv_async_t* async;
Expand Down Expand Up @@ -176,6 +165,15 @@ void uv_loop_delete(uv_loop_t* loop) {


uv_loop_t* uv_default_loop() {
if (!default_loop_ptr) {
default_loop_ptr = &default_loop_struct;
#if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
default_loop_struct.ev = ev_default_loop(EVBACKEND_KQUEUE);
#else
default_loop_struct.ev = ev_default_loop(EVFLAG_AUTO);
#endif
ev_set_userdata(default_loop_struct.ev, default_loop_ptr);
}
assert(default_loop_ptr->ev == EV_DEFAULT_UC);
return default_loop_ptr;
}
Expand Down
26 changes: 13 additions & 13 deletions deps/uv/src/unix/pipe.c
Expand Up @@ -38,7 +38,7 @@ int uv_pipe_init(uv_loop_t* loop, uv_pipe_t* handle) {


int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
struct sockaddr_un sun;
struct sockaddr_un saddr;
const char* pipe_fname;
int saved_errno;
int sockfd;
Expand Down Expand Up @@ -71,11 +71,11 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
goto out;
}

memset(&sun, 0, sizeof sun);
uv__strlcpy(sun.sun_path, pipe_fname, sizeof(sun.sun_path));
sun.sun_family = AF_UNIX;
memset(&saddr, 0, sizeof saddr);
uv__strlcpy(saddr.sun_path, pipe_fname, sizeof(saddr.sun_path));
saddr.sun_family = AF_UNIX;

if (bind(sockfd, (struct sockaddr*)&sun, sizeof sun) == -1) {
if (bind(sockfd, (struct sockaddr*)&saddr, sizeof saddr) == -1) {
/* On EADDRINUSE:
*
* We hold the file lock so there is no other process listening
Expand All @@ -86,7 +86,7 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
*/
if (errno != EADDRINUSE
|| unlink(pipe_fname) == -1
|| bind(sockfd, (struct sockaddr*)&sun, sizeof sun) == -1) {
|| bind(sockfd, (struct sockaddr*)&saddr, sizeof saddr) == -1) {
/* Convert ENOENT to EACCES for compatibility with Windows. */
uv_err_new(handle->loop, (errno == ENOENT) ? EACCES : errno);
goto out;
Expand Down Expand Up @@ -174,7 +174,7 @@ int uv_pipe_connect(uv_connect_t* req,
uv_pipe_t* handle,
const char* name,
uv_connect_cb cb) {
struct sockaddr_un sun;
struct sockaddr_un saddr;
int saved_errno;
int sockfd;
int status;
Expand All @@ -189,15 +189,15 @@ int uv_pipe_connect(uv_connect_t* req,
goto out;
}

memset(&sun, 0, sizeof sun);
uv__strlcpy(sun.sun_path, name, sizeof(sun.sun_path));
sun.sun_family = AF_UNIX;
memset(&saddr, 0, sizeof saddr);
uv__strlcpy(saddr.sun_path, name, sizeof(saddr.sun_path));
saddr.sun_family = AF_UNIX;

/* We don't check for EINPROGRESS. Think about it: the socket
* is either there or not.
*/
do {
r = connect(sockfd, (struct sockaddr*)&sun, sizeof sun);
r = connect(sockfd, (struct sockaddr*)&saddr, sizeof saddr);
}
while (r == -1 && errno == EINTR);

Expand Down Expand Up @@ -236,7 +236,7 @@ int uv_pipe_connect(uv_connect_t* req,

/* TODO merge with uv__server_io()? */
void uv__pipe_accept(EV_P_ ev_io* watcher, int revents) {
struct sockaddr_un sun;
struct sockaddr_un saddr;
uv_pipe_t* pipe;
int saved_errno;
int sockfd;
Expand All @@ -247,7 +247,7 @@ void uv__pipe_accept(EV_P_ ev_io* watcher, int revents) {
assert(pipe->type == UV_NAMED_PIPE);
assert(pipe->pipe_fname != NULL);

sockfd = uv__accept(pipe->fd, (struct sockaddr *)&sun, sizeof sun);
sockfd = uv__accept(pipe->fd, (struct sockaddr *)&saddr, sizeof saddr);
if (sockfd == -1) {
if (errno == EAGAIN || errno == EWOULDBLOCK) {
assert(0 && "EAGAIN on uv__accept(pipefd)");
Expand Down
40 changes: 24 additions & 16 deletions deps/uv/src/win/core.c
Expand Up @@ -33,7 +33,22 @@

/* The only event loop we support right now */
static uv_loop_t uv_default_loop_;
static int uv_default_loop_initialized_ = 0;

/* uv_once intialization guards */
static uv_once_t uv_init_guard_ = UV_ONCE_INIT;
static uv_once_t uv_default_loop_init_guard_ = UV_ONCE_INIT;


static void uv_init(void) {
/* Initialize winsock */
uv_winsock_init();

/* Fetch winapi function pointers */
uv_winapi_init();

/* Initialize FS */
uv_fs_init();
}


static void uv_loop_init(uv_loop_t* loop) {
Expand Down Expand Up @@ -68,25 +83,18 @@ static void uv_loop_init(uv_loop_t* loop) {
}


uv_loop_t* uv_default_loop() {
if (!uv_default_loop_initialized_) {
uv_loop_init(&uv_default_loop_);
uv_default_loop_initialized_ = 1;
}
static void uv_default_loop_init(void) {
/* Intialize libuv itself first */
uv_once(&uv_init_guard_, uv_init);

return &uv_default_loop_;
/* Initialize the main loop */
uv_loop_init(&uv_default_loop_);
}


void uv_init() {
/* Initialize winsock */
uv_winsock_init();

/* Fetch winapi function pointers */
uv_winapi_init();

/* Initialize FS */
uv_fs_init();
uv_loop_t* uv_default_loop() {
uv_once(&uv_default_loop_init_guard_, uv_default_loop_init);
return &uv_default_loop_;
}


Expand Down
15 changes: 15 additions & 0 deletions deps/uv/src/win/internal.h
Expand Up @@ -279,4 +279,19 @@ void uv_winsock_init();
int uv_ntstatus_to_winsock_error(NTSTATUS status);


/* Threads and synchronization */
typedef struct uv_once_s {
unsigned char ran;
/* The actual event handle must be aligned to sizeof(HANDLE), so in */
/* practice it might overlap padding a little. */
HANDLE event;
HANDLE padding;
} uv_once_t;

#define UV_ONCE_INIT \
{ 0, NULL, NULL }

void uv_once(uv_once_t* guard, void (*callback)(void));


#endif /* UV_WIN_INTERNAL_H_ */
30 changes: 15 additions & 15 deletions deps/uv/src/win/timer.c
Expand Up @@ -33,7 +33,7 @@
/* The resolution of the high-resolution clock. */
static int64_t uv_ticks_per_msec_ = 0;
static uint64_t uv_hrtime_frequency_ = 0;
static char uv_hrtime_initialized_ = 0;
static uv_once_t uv_hrtime_init_guard_ = UV_ONCE_INIT;


void uv_update_time(uv_loop_t* loop) {
Expand All @@ -57,24 +57,24 @@ int64_t uv_now(uv_loop_t* loop) {
return loop->time;
}

/* TODO: thread safety */
uint64_t uv_hrtime(void) {
LARGE_INTEGER counter;

/* When called for the first time, obtain the high-resolution clock */
/* frequency. */
if (!uv_hrtime_initialized_) {
uv_hrtime_initialized_ = 1;

if (!QueryPerformanceFrequency(&counter)) {
uv_hrtime_frequency_ = 0;
/* uv_set_sys_error(loop, GetLastError()); */
return 0;
}
static void uv_hrtime_init(void) {
LARGE_INTEGER frequency;

uv_hrtime_frequency_ = counter.QuadPart;
if (!QueryPerformanceFrequency(&frequency)) {
uv_hrtime_frequency_ = 0;
return;
}

uv_hrtime_frequency_ = frequency.QuadPart;
}


uint64_t uv_hrtime(void) {
LARGE_INTEGER counter;

uv_once(&uv_hrtime_init_guard_, uv_hrtime_init);

/* If the performance frequency is zero, there's no support. */
if (!uv_hrtime_frequency_) {
/* uv_set_sys_error(loop, ERROR_NOT_SUPPORTED); */
Expand Down
1 change: 0 additions & 1 deletion deps/uv/test/benchmark-ares.c
Expand Up @@ -86,7 +86,6 @@ BENCHMARK_IMPL(gethostbyname) {
return 1;
}

uv_init();
loop = uv_default_loop();

ares_callbacks = 0;
Expand Down
1 change: 0 additions & 1 deletion deps/uv/test/benchmark-getaddrinfo.c
Expand Up @@ -68,7 +68,6 @@ static void getaddrinfo_initiate(uv_getaddrinfo_t* handle) {
BENCHMARK_IMPL(getaddrinfo) {
int i;

uv_init(loop);
loop = uv_default_loop();

uv_update_time(loop);
Expand Down
1 change: 0 additions & 1 deletion deps/uv/test/benchmark-ping-pongs.c
Expand Up @@ -200,7 +200,6 @@ static void pinger_new() {


BENCHMARK_IMPL(ping_pongs) {
uv_init();
loop = uv_default_loop();

start_time = uv_now(loop);
Expand Down
1 change: 0 additions & 1 deletion deps/uv/test/benchmark-pound.c
Expand Up @@ -277,7 +277,6 @@ static int pound_it(int concurrency,
uint64_t start_time; /* in ns */
uint64_t end_time;

uv_init();
loop = uv_default_loop();

uv_update_time(loop);
Expand Down
4 changes: 0 additions & 4 deletions deps/uv/test/benchmark-pump.c
Expand Up @@ -367,7 +367,6 @@ HELPER_IMPL(tcp_pump_server) {
int r;

type = TCP;
uv_init();
loop = uv_default_loop();

listen_addr = uv_ip4_addr("0.0.0.0", TEST_PORT);
Expand All @@ -391,7 +390,6 @@ HELPER_IMPL(pipe_pump_server) {
int r;
type = PIPE;

uv_init();
loop = uv_default_loop();

/* Server */
Expand All @@ -414,7 +412,6 @@ void tcp_pump(int n) {
TARGET_CONNECTIONS = n;
type = TCP;

uv_init();
loop = uv_default_loop();

connect_addr = uv_ip4_addr("127.0.0.1", TEST_PORT);
Expand All @@ -431,7 +428,6 @@ void pipe_pump(int n) {
TARGET_CONNECTIONS = n;
type = PIPE;

uv_init();
loop = uv_default_loop();

/* Start making connections */
Expand Down
1 change: 0 additions & 1 deletion deps/uv/test/benchmark-spawn.c
Expand Up @@ -132,7 +132,6 @@ BENCHMARK_IMPL(spawn) {
int r;
static int64_t start_time, end_time;

uv_init();
loop = uv_default_loop();

r = uv_exepath(exepath, &exepath_size);
Expand Down
1 change: 0 additions & 1 deletion deps/uv/test/benchmark-udp-packet-storm.c
Expand Up @@ -134,7 +134,6 @@ static int do_packet_storm(int n_senders, int n_receivers) {
ASSERT(n_senders <= MAX_SENDERS);
ASSERT(n_receivers <= MAX_RECEIVERS);

uv_init();
loop = uv_default_loop();

n_senders_ = n_senders;
Expand Down
1 change: 0 additions & 1 deletion deps/uv/test/dns-server.c
Expand Up @@ -317,7 +317,6 @@ static int dns_start(int port) {


HELPER_IMPL(dns_server) {
uv_init();
loop = uv_default_loop();

if (dns_start(TEST_PORT_2))
Expand Down
3 changes: 0 additions & 3 deletions deps/uv/test/echo-server.c
Expand Up @@ -272,7 +272,6 @@ static int pipe_echo_start(char* pipeName) {


HELPER_IMPL(tcp4_echo_server) {
uv_init();
loop = uv_default_loop();

if (tcp4_echo_start(TEST_PORT))
Expand All @@ -284,7 +283,6 @@ HELPER_IMPL(tcp4_echo_server) {


HELPER_IMPL(tcp6_echo_server) {
uv_init();
loop = uv_default_loop();

if (tcp6_echo_start(TEST_PORT))
Expand All @@ -296,7 +294,6 @@ HELPER_IMPL(tcp6_echo_server) {


HELPER_IMPL(pipe_echo_server) {
uv_init();
loop = uv_default_loop();

if (pipe_echo_start(TEST_PIPENAME))
Expand Down
2 changes: 0 additions & 2 deletions deps/uv/test/test-async.c
Expand Up @@ -182,8 +182,6 @@ static void prepare_cb(uv_prepare_t* handle, int status) {
TEST_IMPL(async) {
int r;

uv_init();

r = uv_prepare_init(uv_default_loop(), &prepare_handle);
ASSERT(r == 0);
r = uv_prepare_start(&prepare_handle, prepare_cb);
Expand Down
2 changes: 0 additions & 2 deletions deps/uv/test/test-callback-stack.c
Expand Up @@ -176,8 +176,6 @@ static void connect_cb(uv_connect_t* req, int status) {
TEST_IMPL(callback_stack) {
struct sockaddr_in addr = uv_ip4_addr("127.0.0.1", TEST_PORT);

uv_init();

if (uv_tcp_init(uv_default_loop(), &client)) {
FATAL("uv_tcp_init failed");
}
Expand Down

0 comments on commit 0d80040

Please sign in to comment.