Browse Source

deps: upgrade libuv to 0ddf9d6

v0.9.4-release
Ben Noordhuis 12 years ago
parent
commit
a7ac1a1d88
  1. 3
      deps/uv/include/uv-private/uv-darwin.h
  2. 5
      deps/uv/include/uv-private/uv-unix.h
  3. 18
      deps/uv/include/uv.h
  4. 14
      deps/uv/src/unix/darwin.c
  5. 2
      deps/uv/src/unix/fs.c
  6. 1
      deps/uv/src/unix/pipe.c
  7. 2
      deps/uv/src/unix/process.c
  8. 217
      deps/uv/src/unix/stream.c
  9. 49
      deps/uv/src/unix/tty.c
  10. 2
      deps/uv/test/benchmark-fs-stat.c
  11. 2
      deps/uv/test/benchmark-spawn.c
  12. 6
      deps/uv/test/benchmark-udp-pummel.c
  13. 22
      deps/uv/test/echo-server.c
  14. 13
      deps/uv/test/run-tests.c
  15. 2
      deps/uv/test/runner.h
  16. 2
      deps/uv/test/test-list.h
  17. 2
      deps/uv/test/test-poll.c
  18. 39
      deps/uv/test/test-spawn.c
  19. 3
      deps/uv/test/test-stdio-over-pipes.c
  20. 3
      deps/uv/test/test-timer.c
  21. 6
      deps/uv/uv.gyp

3
deps/uv/include/uv-private/uv-darwin.h

@ -51,7 +51,4 @@
uv_sem_t cf_sem; \
uv_mutex_t cf_mutex; \
#define UV_STREAM_PRIVATE_PLATFORM_FIELDS \
void* select; \
#endif /* UV_DARWIN_H */

5
deps/uv/include/uv-private/uv-unix.h

@ -85,10 +85,6 @@ struct uv__work {
# define UV_PLATFORM_FS_EVENT_FIELDS /* empty */
#endif
#ifndef UV_STREAM_PRIVATE_PLATFORM_FIELDS
# define UV_STREAM_PRIVATE_PLATFORM_FIELDS /* empty */
#endif
/* Note: May be cast to struct iovec. See writev(2). */
typedef struct {
char* base;
@ -205,7 +201,6 @@ typedef struct {
int delayed_error; \
int accepted_fd; \
int fd; \
UV_STREAM_PRIVATE_PLATFORM_FIELDS \
#define UV_TCP_PRIVATE_FIELDS /* empty */

18
deps/uv/include/uv.h

@ -76,11 +76,11 @@ extern "C" {
XX( 1, EOF, "end of file") \
XX( 2, EADDRINFO, "getaddrinfo error") \
XX( 3, EACCES, "permission denied") \
XX( 4, EAGAIN, "no more processes") \
XX( 4, EAGAIN, "resource temporarily unavailable") \
XX( 5, EADDRINUSE, "address already in use") \
XX( 6, EADDRNOTAVAIL, "") \
XX( 7, EAFNOSUPPORT, "") \
XX( 8, EALREADY, "") \
XX( 6, EADDRNOTAVAIL, "address not available") \
XX( 7, EAFNOSUPPORT, "address family not supported") \
XX( 8, EALREADY, "connection already in progress") \
XX( 9, EBADF, "bad file descriptor") \
XX( 10, EBUSY, "resource busy or locked") \
XX( 11, ECONNABORTED, "software caused connection abort") \
@ -112,11 +112,11 @@ extern "C" {
XX( 38, EPROTONOSUPPORT, "protocol not supported") \
XX( 39, EPROTOTYPE, "protocol wrong type for socket") \
XX( 40, ETIMEDOUT, "connection timed out") \
XX( 41, ECHARSET, "") \
XX( 42, EAIFAMNOSUPPORT, "") \
XX( 44, EAISERVICE, "") \
XX( 45, EAISOCKTYPE, "") \
XX( 46, ESHUTDOWN, "") \
XX( 41, ECHARSET, "invalid Unicode character") \
XX( 42, EAIFAMNOSUPPORT, "address family for hostname not supported") \
XX( 44, EAISERVICE, "servname not supported for ai_socktype") \
XX( 45, EAISOCKTYPE, "ai_socktype not supported") \
XX( 46, ESHUTDOWN, "cannot send after transport endpoint shutdown") \
XX( 47, EEXIST, "file already exists") \
XX( 48, ESRCH, "no such process") \
XX( 49, ENAMETOOLONG, "name too long") \

14
deps/uv/src/unix/darwin.c

@ -173,9 +173,7 @@ void uv__cf_loop_signal(uv_loop_t* loop, cf_loop_signal_cb cb, void* arg) {
}
#if TARGET_OS_IPHONE
/* see: http://developer.apple.com/library/mac/#qa/qa1398/_index.html */
uint64_t uv_hrtime() {
uint64_t uv_hrtime(void) {
uint64_t time;
uint64_t enano;
static mach_timebase_info_data_t sTimebaseInfo;
@ -190,15 +188,7 @@ uint64_t uv_hrtime() {
return enano;
}
#else
uint64_t uv_hrtime() {
uint64_t time;
Nanoseconds enano;
time = mach_absolute_time();
enano = AbsoluteToNanoseconds(*(AbsoluteTime *)&time);
return (*(uint64_t *)&enano);
}
#endif
int uv_exepath(char* buffer, size_t* size) {
uint32_t usize;

2
deps/uv/src/unix/fs.c

@ -46,7 +46,7 @@
#define INIT(type) \
do { \
uv__req_init((loop), (req), UV_FS_ ## type); \
uv__req_init((loop), (req), UV_FS); \
(req)->fs_type = UV_FS_ ## type; \
(req)->errorno = 0; \
(req)->result = 0; \

1
deps/uv/src/unix/pipe.c

@ -150,6 +150,7 @@ void uv__pipe_close(uv_pipe_t* handle) {
*/
unlink(handle->pipe_fname);
free((void*)handle->pipe_fname);
handle->pipe_fname = NULL;
}
uv__stream_close((uv_stream_t*)handle);

2
deps/uv/src/unix/process.c

@ -340,7 +340,9 @@ static void uv__process_child_init(uv_process_options_t options,
_exit(127);
}
if (options.env) {
environ = options.env;
}
execvp(options.file, options.args);
uv__write_int(error_fd, errno);

217
deps/uv/src/unix/stream.c

@ -34,27 +34,6 @@
#include <sys/un.h>
#include <unistd.h>
#if defined(__APPLE__)
# include <sys/event.h>
# include <sys/time.h>
# include <sys/select.h>
/* ev.h is overwriting EV_ERROR from sys/event.h */
#define EV_ERROR_ORIG 0x4000
/* Forward declaration */
typedef struct uv__stream_select_s uv__stream_select_t;
struct uv__stream_select_s {
uv_stream_t* stream;
uv_thread_t thread;
uv_sem_t sem;
uv_mutex_t mutex;
uv_async_t async;
int events;
int fake_fd;
};
#endif /* defined(__APPLE__) */
static void uv__stream_connect(uv_stream_t*);
static void uv__write(uv_stream_t* stream);
@ -118,182 +97,11 @@ void uv__stream_init(uv_loop_t* loop,
if (loop->emfile_fd == -1)
loop->emfile_fd = uv__open_cloexec("/", O_RDONLY);
#if defined(__APPLE__)
stream->select = NULL;
#endif /* defined(__APPLE_) */
uv__io_init(&stream->read_watcher, uv__stream_io, -1, 0);
uv__io_init(&stream->write_watcher, uv__stream_io, -1, 0);
}
#if defined(__APPLE__)
void uv__stream_osx_select(void* arg) {
uv_stream_t* stream;
uv__stream_select_t* s;
fd_set read;
fd_set write;
fd_set error;
struct timeval timeout;
int events;
int fd;
int r;
stream = arg;
s = stream->select;
fd = stream->fd;
while (1) {
/* Terminate on semaphore */
if (uv_sem_trywait(&s->sem) == 0) break;
/* Watch fd using select(2) */
FD_ZERO(&read);
FD_ZERO(&write);
FD_ZERO(&error);
FD_SET(fd, &read);
FD_SET(fd, &write);
FD_SET(fd, &error);
timeout.tv_sec = 0;
timeout.tv_usec = 250000; /* 250 ms timeout */
r = select(fd + 1, &read, &write, &error, &timeout);
if (r == -1) {
if (errno == EINTR) continue;
/* XXX: Possible?! */
abort();
}
/* Ignore timeouts */
if (r == 0) continue;
/* Handle events */
events = 0;
if (FD_ISSET(fd, &read)) events |= UV__IO_READ;
if (FD_ISSET(fd, &write)) events |= UV__IO_WRITE;
if (FD_ISSET(fd, &error)) events |= UV__IO_ERROR;
uv_mutex_lock(&s->mutex);
s->events |= events;
uv_mutex_unlock(&s->mutex);
if (events != 0) uv_async_send(&s->async);
}
}
void uv__stream_osx_select_cb(uv_async_t* handle, int status) {
uv_stream_t* stream;
uv__stream_select_t* s;
int events;
s = container_of(handle, uv__stream_select_t, async);
stream = s->stream;
/* Get and reset stream's events */
uv_mutex_lock(&s->mutex);
events = s->events;
s->events = 0;
uv_mutex_unlock(&s->mutex);
/* Invoke callback on event-loop */
if ((events & UV__IO_READ) && uv__io_active(&stream->read_watcher)) {
uv__stream_io(stream->loop, &stream->read_watcher, UV__IO_READ);
}
if ((events & UV__IO_WRITE) && uv__io_active(&stream->write_watcher)) {
uv__stream_io(stream->loop, &stream->write_watcher, UV__IO_WRITE);
}
if (events & UV__IO_ERROR) {
/* XXX: Handle it! */
uv__stream_io(stream->loop, NULL, UV__IO_ERROR);
}
}
void uv__stream_osx_cb_close(uv_handle_t* async) {
/* Free container */
free(container_of(async, uv__stream_select_t, async));
}
int uv__stream_try_select(uv_stream_t* stream, int fd) {
/*
* kqueue doesn't work with some files from /dev mount on osx.
* select(2) in separate thread for those fds
*/
int kq;
int ret;
struct kevent filter[1];
struct kevent events[1];
struct timespec timeout;
uv__stream_select_t* s;
kq = kqueue();
if (kq < 0) {
fprintf(stderr, "(libuv) Failed to create kqueue (%d)\n", errno);
abort();
}
EV_SET(&filter[0], fd, EVFILT_READ, EV_ADD | EV_ENABLE, 0, 0, 0);
/* Use small timeout, because we only want to capture EINVALs */
timeout.tv_sec = 0;
timeout.tv_nsec = 1;
ret = kevent(kq, filter, 1, events, 1, &timeout);
close(kq);
if (ret < 1) return -1;
if ((events[0].flags & EV_ERROR_ORIG) == 0 || events[0].data != EINVAL) {
return -1;
}
/* At this point we definitely know that this fd won't work with kqueue */
s = malloc(sizeof(*s));
if (s == NULL) {
/* TODO: Return error */
abort();
}
if (uv_async_init(stream->loop,
&s->async,
uv__stream_osx_select_cb)) {
return -1;
}
s->async.flags |= UV__HANDLE_INTERNAL;
uv__handle_unref((uv_handle_t*) &s->async);
if (uv_sem_init(&s->sem, 0)) goto fatal1;
if (uv_mutex_init(&s->mutex)) goto fatal2;
/* Create fake fd for io watcher */
s->fake_fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (s->fake_fd == -1) goto fatal3;
if (uv_thread_create(&s->thread, uv__stream_osx_select, stream)) {
goto fatal4;
}
s->stream = stream;
stream->select = s;
return 0;
fatal4:
close(s->fake_fd);
fatal3:
uv_mutex_destroy(&s->mutex);
fatal2:
uv_sem_destroy(&s->sem);
fatal1:
uv_close((uv_handle_t*) &s->async, uv__stream_osx_cb_close);
free(s);
return -1;
}
#endif /* defined(__APPLE__) */
int uv__stream_open(uv_stream_t* stream, int fd, int flags) {
socklen_t yes;
@ -322,13 +130,6 @@ int uv__stream_open(uv_stream_t* stream, int fd, int flags) {
}
}
#if defined(__APPLE__)
if (uv__stream_try_select(stream, fd) == 0) {
/* Use fake fd */
fd = ((uv__stream_select_t*) stream->select)->fake_fd;
}
#endif /* defined(__APPLE__) */
/* Associate the fd with each watcher. */
uv__io_set(&stream->read_watcher, uv__stream_io, fd, UV__IO_READ);
uv__io_set(&stream->write_watcher, uv__stream_io, fd, UV__IO_WRITE);
@ -1248,24 +1049,6 @@ int uv_is_writable(const uv_stream_t* stream) {
void uv__stream_close(uv_stream_t* handle) {
#if defined(__APPLE__)
/* Terminate select loop first */
if (handle->select != NULL) {
uv__stream_select_t* s;
s = handle->select;
uv_sem_post(&s->sem);
uv_thread_join(&s->thread);
uv_sem_destroy(&s->sem);
uv_mutex_destroy(&s->mutex);
close(s->fake_fd);
uv_close((uv_handle_t*) &s->async, uv__stream_osx_cb_close);
handle->select = NULL;
}
#endif /* defined(__APPLE__) */
uv_read_stop(handle);
uv__io_stop(handle->loop, &handle->write_watcher);

49
deps/uv/src/unix/tty.c

@ -34,53 +34,18 @@ static struct termios orig_termios;
int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, int fd, int readable) {
int flags;
int newfd;
int r;
uv__stream_init(loop, (uv_stream_t*)tty, UV_TTY);
/* Reopen the file descriptor when it refers to a tty. This lets us put the
* tty in non-blocking mode without affecting other processes that share it
* with us.
*
* Example: `node | cat` - if we put our fd 0 in non-blocking mode, it also
* affects fd 1 of `cat` because both file descriptors refer to the same
* struct file in the kernel. When we reopen our fd 0, it points to a
* different struct file, hence changing its properties doesn't affect
* other processes.
*/
if (isatty(fd)) {
newfd = open("/dev/tty", O_RDWR);
if (newfd == -1)
return uv__set_sys_error(loop, errno);
do
r = dup2(newfd, fd);
while (r == -1 && (errno == EINTR || errno == EBUSY));
/* EINVAL means newfd == fd which could conceivably happen if another
* thread called close(fd) between our calls to isatty() and open().
* That's a rather unlikely event but let's handle it anyway.
*/
if (r == -1 && errno != EINVAL) {
close(newfd);
return uv__set_sys_error(loop, errno);
}
fd = newfd;
if (readable) {
uv__nonblock(fd, 1);
uv__stream_open((uv_stream_t*)tty, fd, UV_STREAM_READABLE);
} else {
/* Note: writable tty we set to blocking mode. */
uv__stream_open((uv_stream_t*)tty, fd, UV_STREAM_WRITABLE);
tty->flags |= UV_STREAM_BLOCKING;
}
if (readable)
flags = UV_STREAM_READABLE;
else
flags = UV_STREAM_WRITABLE;
uv__nonblock(fd, 1);
uv__stream_open((uv_stream_t*)tty, fd, flags);
tty->mode = 0;
return 0;
}

2
deps/uv/test/benchmark-fs-stat.c

@ -45,7 +45,7 @@ struct async_req {
static void warmup(const char* path) {
uv_fs_t reqs[MAX_CONCURRENT_REQS];
int i;
unsigned int i;
/* warm up the thread pool */
for (i = 0; i < ARRAY_SIZE(reqs); i++)

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

@ -30,7 +30,7 @@ static int N = 1000;
static int done;
static uv_process_t process;
static uv_process_options_t options = { 0 };
static uv_process_options_t options;
static char exepath[1024];
static size_t exepath_size = 1024;
static char* args[3];

6
deps/uv/test/benchmark-udp-pummel.c

@ -143,13 +143,13 @@ static void timeout_cb(uv_timer_t* timer, int status) {
}
static int do_packet_storm(int n_senders,
int n_receivers,
static int do_packet_storm(unsigned int n_senders,
unsigned int n_receivers,
unsigned long timeout) {
uv_timer_t timer_handle;
uint64_t duration;
uv_loop_t* loop;
int i;
unsigned int i;
ASSERT(n_senders <= ARRAY_SIZE(senders));
ASSERT(n_receivers <= ARRAY_SIZE(receivers));

22
deps/uv/test/echo-server.c

@ -47,18 +47,24 @@ static void on_connection(uv_stream_t*, int status);
static void after_write(uv_write_t* req, int status) {
write_req_t* wr;
if (status) {
uv_err_t err = uv_last_error(loop);
fprintf(stderr, "uv_write error: %s\n", uv_strerror(err));
ASSERT(0);
}
wr = (write_req_t*) req;
uv_err_t err;
/* Free the read/write buffer and the request */
wr = (write_req_t*) req;
free(wr->buf.base);
free(wr);
if (status == 0)
return;
err = uv_last_error(loop);
fprintf(stderr, "uv_write error: %s\n", uv_strerror(err));
if (err.code == UV_ECANCELED)
return;
ASSERT(err.code == UV_EPIPE);
uv_close((uv_handle_t*)req->handle, on_close);
}

13
deps/uv/test/run-tests.c

@ -134,5 +134,18 @@ static int maybe_run_test(int argc, char **argv) {
return 1;
}
if (strcmp(argv[1], "spawn_helper7") == 0) {
int r;
char *test;
/* Test if the test value from the parent is still set */
test = getenv("ENV_TEST");
ASSERT(test != NULL);
r = fprintf(stdout, "%s", test);
ASSERT(r > 0);
return 1;
}
return run_test(argv[1], TEST_TIMEOUT, 0);
}

2
deps/uv/test/runner.h

@ -51,7 +51,7 @@ typedef struct {
task_entry_t TASKS[] = {
#define TASK_LIST_END \
{ 0, 0, 0, 0 } \
{ 0, 0, 0, 0, 0 } \
};
#define TEST_DECLARE(name) \

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

@ -146,6 +146,7 @@ TEST_DECLARE (spawn_and_kill)
TEST_DECLARE (spawn_detached)
TEST_DECLARE (spawn_and_kill_with_std)
TEST_DECLARE (spawn_and_ping)
TEST_DECLARE (spawn_preserve_env)
TEST_DECLARE (spawn_setuid_fails)
TEST_DECLARE (spawn_setgid_fails)
TEST_DECLARE (spawn_stdout_to_file)
@ -395,6 +396,7 @@ TASK_LIST_START
TEST_ENTRY (spawn_detached)
TEST_ENTRY (spawn_and_kill_with_std)
TEST_ENTRY (spawn_and_ping)
TEST_ENTRY (spawn_preserve_env)
TEST_ENTRY (spawn_setuid_fails)
TEST_ENTRY (spawn_setgid_fails)
TEST_ENTRY (spawn_stdout_to_file)

2
deps/uv/test/test-poll.c

@ -205,7 +205,7 @@ static void destroy_connection_context(connection_context_t* context) {
static void connection_poll_cb(uv_poll_t* handle, int status, int events) {
connection_context_t* context = (connection_context_t*) handle->data;
int new_events;
unsigned int new_events;
int r;
ASSERT(status == 0);

39
deps/uv/test/test-spawn.c

@ -387,6 +387,45 @@ TEST_IMPL(spawn_and_kill) {
return 0;
}
TEST_IMPL(spawn_preserve_env) {
int r;
uv_pipe_t out;
uv_stdio_container_t stdio[2];
init_process_options("spawn_helper7", exit_cb);
uv_pipe_init(uv_default_loop(), &out, 0);
options.stdio = stdio;
options.stdio[0].flags = UV_IGNORE;
options.stdio[1].flags = UV_CREATE_PIPE | UV_WRITABLE_PIPE;
options.stdio[1].data.stream = (uv_stream_t*) &out;
options.stdio_count = 2;
ASSERT(setenv("ENV_TEST", "testval", 1) == 0);
/* Explicitly set options.env to NULL to test for env clobbering. */
options.env = NULL;
r = uv_spawn(uv_default_loop(), &process, options);
ASSERT(r == 0);
r = uv_read_start((uv_stream_t*) &out, on_alloc, on_read);
ASSERT(r == 0);
r = uv_run(uv_default_loop());
ASSERT(r == 0);
ASSERT(exit_cb_called == 1);
ASSERT(close_cb_called == 2);
printf("output is: %s", output);
ASSERT(strcmp("testval", output) == 0);
MAKE_VALGRIND_HAPPY();
return 0;
}
TEST_IMPL(spawn_detached) {
int r;
uv_err_t err;

3
deps/uv/test/test-stdio-over-pipes.c

@ -196,7 +196,8 @@ int stdio_over_pipes_helper() {
uv_write_t write_req[ARRAY_SIZE(buffers)];
uv_buf_t buf[ARRAY_SIZE(buffers)];
int r, i;
unsigned int i;
int r;
uv_loop_t* loop = uv_default_loop();
ASSERT(UV_NAMED_PIPE == uv_guess_handle(0));

3
deps/uv/test/test-timer.c

@ -90,7 +90,8 @@ TEST_IMPL(timer) {
uv_timer_t once_timers[10];
uv_timer_t *once;
uv_timer_t repeat, never;
int i, r;
unsigned int i;
int r;
start_time = uv_now(uv_default_loop());
ASSERT(0 < start_time);

6
deps/uv/uv.gyp

@ -32,6 +32,12 @@
'direct_dependent_settings': {
'include_dirs': [ 'include' ],
'conditions': [
['OS != "win"', {
'defines': [ '_LARGEFILE_SOURCE', '_FILE_OFFSET_BITS=64' ],
}],
['OS == "mac"', {
'defines': [ '_DARWIN_USE_64_BIT_INODE=1' ],
}],
['OS == "linux"', {
'libraries': [ '-ldl' ],
}],

Loading…
Cancel
Save