Navigation Menu

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

Commit

Permalink
Upgrade libuv to joyent/libuv@f5bd21f
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Jan 16, 2012
1 parent 9584445 commit 7584225
Show file tree
Hide file tree
Showing 17 changed files with 377 additions and 152 deletions.
2 changes: 2 additions & 0 deletions deps/uv/include/uv-private/ev.h
Expand Up @@ -562,6 +562,8 @@ EV_MAYBE_UNUSED ev_is_default_loop (EV_P)
/* create and destroy alternative loops that don't handle signals */
struct ev_loop *ev_loop_new (unsigned int flags EV_CPP (= 0));

int ev_loop_refcount (EV_P);

ev_tstamp ev_now (EV_P); /* time w.r.t. timers and the eventloop, updated after each poll */

#else
Expand Down
3 changes: 3 additions & 0 deletions deps/uv/include/uv.h
Expand Up @@ -202,6 +202,9 @@ typedef struct uv_work_s uv_work_t;
UV_EXTERN uv_loop_t* uv_loop_new(void);
UV_EXTERN void uv_loop_delete(uv_loop_t*);

/* This is a debugging tool. It's NOT part of the official API. */
UV_EXTERN int uv_loop_refcount(const uv_loop_t*);


/*
* Returns the default loop.
Expand Down
11 changes: 5 additions & 6 deletions deps/uv/src/unix/core.c
Expand Up @@ -63,12 +63,6 @@ void uv__next(EV_P_ ev_idle* watcher, int revents);
static void uv__finish_close(uv_handle_t* handle);



#ifndef __GNUC__
#define __attribute__(a)
#endif


void uv_close(uv_handle_t* handle, uv_close_cb close_cb) {
uv_udp_t* udp;
uv_async_t* async;
Expand Down Expand Up @@ -202,6 +196,11 @@ void uv_loop_delete(uv_loop_t* loop) {
}


int uv_loop_refcount(const uv_loop_t* loop) {
return ev_loop_refcount(loop->ev);
}


uv_loop_t* uv_default_loop(void) {
if (default_loop_ptr)
return default_loop_ptr;
Expand Down
6 changes: 6 additions & 0 deletions deps/uv/src/unix/ev/ev.c
Expand Up @@ -1958,6 +1958,12 @@ ev_loop_new (unsigned int flags)

#endif /* multiplicity */

int
ev_loop_refcount (EV_P)
{
return activecnt;
}

#if EV_VERIFY
static void noinline
verify_watcher (EV_P_ W w)
Expand Down
12 changes: 11 additions & 1 deletion deps/uv/src/unix/udp.c
Expand Up @@ -42,6 +42,10 @@ static int uv__udp_send(uv_udp_send_t* req, uv_udp_t* handle, uv_buf_t bufs[],
static void uv__udp_watcher_start(uv_udp_t* handle, ev_io* w) {
int flags;

if (ev_is_active(w)) {
return;
}

assert(w == &handle->read_watcher
|| w == &handle->write_watcher);

Expand All @@ -51,17 +55,23 @@ static void uv__udp_watcher_start(uv_udp_t* handle, ev_io* w) {
ev_set_cb(w, uv__udp_io);
ev_io_set(w, handle->fd, flags);
ev_io_start(handle->loop->ev, w);
ev_unref(handle->loop->ev);
}


void uv__udp_watcher_stop(uv_udp_t* handle, ev_io* w) {
int flags;

if (!ev_is_active(w)) {
return;
}

assert(w == &handle->read_watcher
|| w == &handle->write_watcher);

flags = (w == &handle->read_watcher ? EV_READ : EV_WRITE);

ev_ref(handle->loop->ev);
ev_io_stop(handle->loop->ev, w);
ev_io_set(w, -1, flags);
ev_set_cb(w, NULL);
Expand Down Expand Up @@ -332,7 +342,7 @@ static int uv__bind(uv_udp_t* handle,
goto out;
}
#else
uv__set_sys_error((uv_handle_t*)handle, ENOTSUP);
uv__set_sys_error(handle->loop, ENOTSUP);
goto out;
#endif
}
Expand Down
5 changes: 5 additions & 0 deletions deps/uv/src/win/core.c
Expand Up @@ -116,6 +116,11 @@ void uv_loop_delete(uv_loop_t* loop) {
}


int uv_loop_refcount(const uv_loop_t* loop) {
return loop->refs;
}


void uv_ref(uv_loop_t* loop) {
loop->refs++;
}
Expand Down
74 changes: 53 additions & 21 deletions deps/uv/src/win/fs.c
Expand Up @@ -490,38 +490,69 @@ void fs__readdir(uv_fs_t* req, const wchar_t* path, int flags) {


void fs__stat(uv_fs_t* req, const wchar_t* path) {
HANDLE file;
WIN32_FIND_DATAW ent;
int result;
unsigned short mode;

fs__open(req, path, _O_RDONLY, 0);
if (req->result == -1) {
req->ptr = NULL;

file = FindFirstFileExW(path, FindExInfoStandard, &ent,
FindExSearchNameMatch, NULL, 0);

if (file == INVALID_HANDLE_VALUE) {
SET_REQ_RESULT_WIN32_ERROR(req, GetLastError());
return;
}

result = _fstati64(req->result, &req->stat);
if (result == -1) {
req->ptr = NULL;
} else {
FindClose(file);

/*
* VC CRT doesn't properly set S_IFDIR in _fstati64,
* so we set it here if path is a directory.
*/
if (GetFileAttributesW(path) & FILE_ATTRIBUTE_DIRECTORY) {
mode = req->stat.st_mode;
mode &= ~_S_IFMT;
mode |= _S_IFDIR;

req->stat.st_mode = mode;
assert((req->stat.st_mode & _S_IFMT) == _S_IFDIR);
if (ent.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT &&
ent.dwReserved0 == IO_REPARSE_TAG_SYMLINK) {
fs__open(req, path, _O_RDONLY, 0);
if (req->result != -1) {
result = _fstati64(req->result, &req->stat);
_close(req->result);

if (result != -1) {
req->ptr = &req->stat;
}

SET_REQ_RESULT(req, result);
}

req->ptr = &req->stat;
return;
}

_close(req->result);
req->stat.st_ino = 0;
req->stat.st_uid = 0;
req->stat.st_gid = 0;
req->stat.st_mode = 0;
req->stat.st_rdev = 0;
req->stat.st_dev = 0;
req->stat.st_nlink = 1;

SET_REQ_RESULT(req, result);
if (ent.dwFileAttributes & FILE_ATTRIBUTE_READONLY ) {
req->stat.st_mode |= (_S_IREAD + (_S_IREAD >> 3) + (_S_IREAD >> 6));
} else {
req->stat.st_mode |= ((_S_IREAD|_S_IWRITE) + ((_S_IREAD|_S_IWRITE) >> 3) +
((_S_IREAD|_S_IWRITE) >> 6));
}

if (ent.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
req->stat.st_mode |= _S_IFDIR;
} else {
req->stat.st_mode |= _S_IFREG;
}

uv_filetime_to_time_t(&ent.ftLastWriteTime, &(req->stat.st_mtime));
uv_filetime_to_time_t(&ent.ftLastAccessTime, &(req->stat.st_atime));
uv_filetime_to_time_t(&ent.ftCreationTime, &(req->stat.st_ctime));

req->stat.st_size = ((int64_t)ent.nFileSizeHigh << 32) +
(int64_t)ent.nFileSizeLow;

req->ptr = &req->stat;
req->result = 0;
}


Expand Down Expand Up @@ -1543,3 +1574,4 @@ void uv_fs_req_cleanup(uv_fs_t* req) {

req->flags |= UV_FS_CLEANEDUP;
}

4 changes: 1 addition & 3 deletions deps/uv/src/win/internal.h
Expand Up @@ -284,10 +284,8 @@ void uv_fs_event_endgame(uv_loop_t* loop, uv_fs_event_t* handle);

/* Utils */
int uv_parent_pid();


void uv_filetime_to_time_t(FILETIME* file_time, time_t* stat_time);
void uv_fatal_error(const int errorno, const char* syscall);

uv_err_code uv_translate_sys_error(int sys_errno);

#define SET_REQ_STATUS(req, status) \
Expand Down
23 changes: 23 additions & 0 deletions deps/uv/src/win/util.c
Expand Up @@ -24,6 +24,7 @@
#include <malloc.h>
#include <stdio.h>
#include <string.h>
#include <time.h>

#include "uv.h"
#include "internal.h"
Expand Down Expand Up @@ -579,3 +580,25 @@ void uv_free_interface_addresses(uv_interface_address_t* addresses,

free(addresses);
}


void uv_filetime_to_time_t(FILETIME* file_time, time_t* stat_time) {
FILETIME local_time;
SYSTEMTIME system_time;
struct tm time;

if ((file_time->dwLowDateTime || file_time->dwHighDateTime) &&
FileTimeToLocalFileTime(file_time, &local_time) &&
FileTimeToSystemTime(&local_time, &system_time)) {
time.tm_year = system_time.wYear - 1900;
time.tm_mon = system_time.wMonth - 1;
time.tm_mday = system_time.wDay;
time.tm_hour = system_time.wHour;
time.tm_min = system_time.wMinute;
time.tm_sec = system_time.wSecond;

*stat_time = mktime(&time);
} else {
*stat_time = 0;
}
}
64 changes: 64 additions & 0 deletions deps/uv/test/echo-server.c
Expand Up @@ -34,6 +34,7 @@ static uv_loop_t* loop;
static int server_closed;
static stream_type serverType;
static uv_tcp_t tcpServer;
static uv_udp_t udpServer;
static uv_pipe_t pipeServer;
static uv_handle_t* server;

Expand Down Expand Up @@ -176,6 +177,34 @@ static void on_server_close(uv_handle_t* handle) {
}


static void on_send(uv_udp_send_t* req, int status);


static void on_recv(uv_udp_t* handle,
ssize_t nread,
uv_buf_t buf,
struct sockaddr* addr,
unsigned flags) {
uv_udp_send_t* req;
int r;

ASSERT(nread > 0);
ASSERT(addr->sa_family == AF_INET);

req = malloc(sizeof(*req));
ASSERT(req != NULL);

r = uv_udp_send(req, handle, &buf, 1, *(struct sockaddr_in*)addr, on_send);
ASSERT(r == 0);
}


static void on_send(uv_udp_send_t* req, int status) {
ASSERT(status == 0);
free(req);
}


static int tcp4_echo_start(int port) {
struct sockaddr_in addr = uv_ip4_addr("0.0.0.0", port);
int r;
Expand Down Expand Up @@ -242,6 +271,30 @@ static int tcp6_echo_start(int port) {
}


static int udp4_echo_start(int port) {
int r;

server = (uv_handle_t*)&udpServer;
serverType = UDP;

r = uv_udp_init(loop, &udpServer);
if (r) {
fprintf(stderr, "uv_udp_init: %s\n",
uv_strerror(uv_last_error(loop)));
return 1;
}

r = uv_udp_recv_start(&udpServer, echo_alloc, on_recv);
if (r) {
fprintf(stderr, "uv_udp_recv_start: %s\n",
uv_strerror(uv_last_error(loop)));
return 1;
}

return 0;
}


static int pipe_echo_start(char* pipeName) {
int r;

Expand Down Expand Up @@ -304,3 +357,14 @@ HELPER_IMPL(pipe_echo_server) {
uv_run(loop);
return 0;
}


HELPER_IMPL(udp4_echo_server) {
loop = uv_default_loop();

if (udp4_echo_start(TEST_PORT))
return 1;

uv_run(loop);
return 0;
}
1 change: 1 addition & 0 deletions deps/uv/test/task.h
Expand Up @@ -42,6 +42,7 @@

typedef enum {
TCP = 0,
UDP,
PIPE
} stream_type;

Expand Down
4 changes: 3 additions & 1 deletion deps/uv/test/test-eio-overflow.c
Expand Up @@ -46,9 +46,11 @@ void after_work_cb(uv_work_t* work) {


void make_eio_req(void) {
uv_work_t* w;

opened++;

uv_work_t* w = (uv_work_t*) malloc(sizeof(*w));
w = (uv_work_t*) malloc(sizeof(*w));
ASSERT(w != NULL);

uv_queue_work(uv_default_loop(), w, work_cb, after_work_cb);
Expand Down
18 changes: 0 additions & 18 deletions deps/uv/test/test-fs-event.c
Expand Up @@ -328,21 +328,3 @@ TEST_IMPL(fs_event_immediate_close) {

return 0;
}


TEST_IMPL(fs_event_unref) {
uv_loop_t* loop;
int r;

loop = uv_default_loop();

r = uv_fs_event_init(loop, &fs_event, ".", fs_event_fail, 0);
ASSERT(r == 0);

uv_unref(loop);

r = uv_run(loop);
ASSERT(r == 0);

return 0;
}

0 comments on commit 7584225

Please sign in to comment.