Permalink
Browse files

Upgrade libuv to joyent/libuv@f5bd21f

  • Loading branch information...
1 parent 9584445 commit 7584225873cd27b53f3fdfb6af5c12c6514acdfa @ry ry committed Jan 16, 2012
@@ -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
View
@@ -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.
View
@@ -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;
@@ -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;
View
@@ -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)
View
@@ -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);
@@ -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);
@@ -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
}
View
@@ -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++;
}
View
@@ -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;
}
@@ -1543,3 +1574,4 @@ void uv_fs_req_cleanup(uv_fs_t* req) {
req->flags |= UV_FS_CLEANEDUP;
}
+
@@ -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) \
View
@@ -24,6 +24,7 @@
#include <malloc.h>
#include <stdio.h>
#include <string.h>
+#include <time.h>
#include "uv.h"
#include "internal.h"
@@ -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;
+ }
+}
View
@@ -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;
@@ -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;
@@ -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;
@@ -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;
+}
View
@@ -42,6 +42,7 @@
typedef enum {
TCP = 0,
+ UDP,
PIPE
} stream_type;
@@ -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);
@@ -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;
-}
Oops, something went wrong.

0 comments on commit 7584225

Please sign in to comment.