Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

upgrade libuv to ab8c3b85c1

  • Loading branch information...
Igor Zinkovsky
Igor Zinkovsky committed Mar 30, 2012
1 parent 1752443 commit 6aa7f6f73274c8df52a20d823bd28fc928a46a23
Showing with 902 additions and 442 deletions.
  1. +4 −2 deps/uv/config-unix.mk
  2. +3 −3 deps/uv/include/uv-private/ngx-queue.h
  3. +8 −4 deps/uv/include/uv-private/tree.h
  4. +4 −0 deps/uv/include/uv-private/uv-unix.h
  5. +4 −1 deps/uv/include/uv-private/uv-win.h
  6. +13 −10 deps/uv/include/uv.h
  7. +3 −2 deps/uv/src/unix/cares.c
  8. +6 −5 deps/uv/src/unix/core.c
  9. +2 −0 deps/uv/src/unix/error.c
  10. +0 −7 deps/uv/src/unix/internal.h
  11. +1 −1 deps/uv/src/unix/kqueue.c
  12. +26 −12 deps/uv/src/unix/linux/core.c
  13. +2 −3 deps/uv/src/unix/linux/inotify.c
  14. +2 −1 deps/uv/src/unix/openbsd.c
  15. +2 −2 deps/uv/src/unix/pipe.c
  16. +17 −17 deps/uv/src/unix/process.c
  17. +5 −2 deps/uv/src/unix/stream.c
  18. +1 −1 deps/uv/src/unix/sunos.c
  19. +2 −2 deps/uv/src/unix/tcp.c
  20. +2 −2 deps/uv/src/unix/udp.c
  21. +25 −34 deps/uv/src/uv-common.c
  22. +2 −2 deps/uv/src/uv-common.h
  23. +1 −0 deps/uv/src/win/cares.c
  24. +1 −1 deps/uv/src/win/core.c
  25. +5 −0 deps/uv/src/win/error.c
  26. +9 −4 deps/uv/src/win/fs-event.c
  27. +1 −14 deps/uv/src/win/handle.c
  28. +4 −2 deps/uv/src/win/internal.h
  29. +36 −25 deps/uv/src/win/pipe.c
  30. +148 −29 deps/uv/src/win/tcp.c
  31. +1 −1 deps/uv/src/win/winapi.h
  32. +6 −8 deps/uv/test/benchmark-ares.c
  33. +0 −7 deps/uv/test/dns-server.c
  34. +9 −207 deps/uv/test/run-tests.c
  35. +2 −1 deps/uv/test/runner.c
  36. +99 −7 deps/uv/test/test-fs-event.c
  37. +1 −1 deps/uv/test/test-get-memory.c
  38. +334 −11 deps/uv/test/test-ipc.c
  39. +6 −0 deps/uv/test/test-list.h
  40. +6 −6 deps/uv/test/test-platform-output.c
  41. +99 −0 deps/uv/test/test-stdio-over-pipes.c
  42. +0 −1 deps/uv/test/test-tcp-writealot.c
  43. +0 −3 deps/uv/test/test-udp-multicast-ttl.c
  44. +0 −1 deps/uv/uv.gyp
@@ -152,14 +152,16 @@ src/unix/uv-eio.o: src/unix/uv-eio.c

clean-platform:
-rm -f src/ares/*.o
-rm -f src/unix/*.o
-rm -f src/unix/ev/*.o
-rm -f src/unix/eio/*.o
-rm -f src/unix/*.o
-rm -f src/unix/linux/*.o
-rm -rf test/run-tests.dSYM run-benchmarks.dSYM

distclean-platform:
-rm -f src/ares/*.o
-rm -f src/unix/ev/*.o
-rm -f src/unix/*.o
-rm -f src/unix/ev/*.o
-rm -f src/unix/eio/*.o
-rm -f src/unix/linux/*.o
-rm -rf test/run-tests.dSYM run-benchmarks.dSYM
@@ -4,8 +4,8 @@
*/


#ifndef _NGX_QUEUE_H_INCLUDED_
#define _NGX_QUEUE_H_INCLUDED_
#ifndef NGX_QUEUE_H_INCLUDED_
#define NGX_QUEUE_H_INCLUDED_


typedef struct ngx_queue_s ngx_queue_t;
@@ -103,4 +103,4 @@ struct ngx_queue_s {
for ((q) = ngx_queue_head(h); (q) != (h); (q) = ngx_queue_next(q))


#endif /* _NGX_QUEUE_H_INCLUDED_ */
#endif /* NGX_QUEUE_H_INCLUDED_ */
@@ -23,10 +23,14 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef _UV_TREE_H_
#define _UV_TREE_H_
#ifndef UV_TREE_H_
#define UV_TREE_H_

#define __unused
#if __GNUC__
# define __unused __attribute__((unused))
#else
# define __unused
#endif

/*
* This file defines data structures for different types of trees:
@@ -759,4 +763,4 @@ name##_RB_MINMAX(struct name *head, int val) \
((x) != NULL) && ((y) = name##_RB_PREV(x), (x) != NULL); \
(x) = (y))

#endif /* _UV_TREE_H_ */
#endif /* UV_TREE_H_ */
@@ -78,6 +78,10 @@ typedef void* uv_lib_t;
/* Poll result queue */ \
eio_channel uv_eio_channel; \
struct ev_loop* ev; \
/* Various thing for libeio. */ \
uv_async_t uv_eio_want_poll_notifier; \
uv_async_t uv_eio_done_poll_notifier; \
uv_idle_t uv_eio_poller; \
UV_LOOP_PRIVATE_PLATFORM_FIELDS

#define UV_REQ_BUFSML_SIZE (4)
@@ -318,7 +318,10 @@ RB_HEAD(uv_timer_tree_s, uv_timer_s);
uv_write_t ipc_header_write_req; \
int ipc_pid; \
uint64_t remaining_ipc_rawdata_bytes; \
WSAPROTOCOL_INFOW* pending_socket_info; \
struct { \
WSAPROTOCOL_INFOW* socket_info; \
int tcp_connection; \
} pending_ipc_info; \
uv_write_t* non_overlapped_writes_tail;

#define UV_PIPE_PRIVATE_FIELDS \
@@ -121,7 +121,8 @@ typedef intptr_t ssize_t;
XX( 50, EPERM, "operation not permitted") \
XX( 51, ELOOP, "too many symbolic links encountered") \
XX( 52, EXDEV, "cross-device link not permitted") \
XX( 53, ENOTEMPTY, "directory not empty")
XX( 53, ENOTEMPTY, "directory not empty") \
XX( 54, ENOSPC, "no space left on device")


#define UV_ERRNO_GEN(val, name, s) UV_##name = val,
@@ -494,6 +495,13 @@ UV_EXTERN int uv_read2_start(uv_stream_t*, uv_alloc_cb alloc_cb,
UV_EXTERN int uv_write(uv_write_t* req, uv_stream_t* handle,
uv_buf_t bufs[], int bufcnt, uv_write_cb cb);

/*
* Extended write function for sending handles over a pipe. The pipe must be
* initialized with ipc == 1.
* send_handle must be a TCP socket or pipe, which is a server or a connection
* (listening or connected state). Bound sockets or pipes will be assumed to
* be servers.
*/
UV_EXTERN int uv_write2(uv_write_t* req, uv_stream_t* handle, uv_buf_t bufs[],
int bufcnt, uv_stream_t* send_handle, uv_write_cb cb);

@@ -509,10 +517,9 @@ struct uv_write_s {

/*
* Used to determine whether a stream is readable or writable.
* TODO: export in v0.8.
*/
/* UV_EXTERN */ int uv_is_readable(uv_stream_t* handle);
/* UV_EXTERN */ int uv_is_writable(uv_stream_t* handle);
UV_EXTERN int uv_is_readable(uv_stream_t* handle);
UV_EXTERN int uv_is_writable(uv_stream_t* handle);


/*
@@ -1482,12 +1489,8 @@ struct uv_counters_s {

struct uv_loop_s {
UV_LOOP_PRIVATE_FIELDS
/* list used for ares task handles */
uv_ares_task_t* uv_ares_handles_;
/* Various thing for libeio. */
uv_async_t uv_eio_want_poll_notifier;
uv_async_t uv_eio_done_poll_notifier;
uv_idle_t uv_eio_poller;
/* RB_HEAD(uv__ares_tasks, uv_ares_task_t) */
struct uv__ares_tasks { uv_ares_task_t* rbh_root; } uv_ares_handles_;
/* Diagnostic counters */
uv_counters_t counters;
/* The last error */
@@ -62,14 +62,15 @@ static void uv__ares_io(struct ev_loop* ev, struct ev_io* watcher,


/* Allocates and returns a new uv_ares_task_t */
static uv_ares_task_t* uv__ares_task_create(int fd) {
static uv_ares_task_t* uv__ares_task_create(uv_loop_t* loop, int fd) {
uv_ares_task_t* h = malloc(sizeof(uv_ares_task_t));

if (h == NULL) {
uv_fatal_error(ENOMEM, "malloc");
return NULL;
}

h->loop = loop;
h->sock = fd;

ev_io_init(&h->read_watcher, uv__ares_io, fd, EV_READ);
@@ -102,7 +103,7 @@ static void uv__ares_sockstate_cb(void* data, ares_socket_t sock,
ev_timer_again(loop->ev, &loop->timer);
}

h = uv__ares_task_create(sock);
h = uv__ares_task_create(loop, sock);
uv_add_ares_handle(loop, h);
}

@@ -82,11 +82,11 @@ void uv_close(uv_handle_t* handle, uv_close_cb close_cb) {
uv_read_stop(stream);
ev_io_stop(stream->loop->ev, &stream->write_watcher);

uv__close(stream->fd);
close(stream->fd);
stream->fd = -1;

if (stream->accepted_fd >= 0) {
uv__close(stream->accepted_fd);
close(stream->accepted_fd);
stream->accepted_fd = -1;
}

@@ -145,6 +145,7 @@ void uv_close(uv_handle_t* handle, uv_close_cb close_cb) {
static int uv__loop_init(uv_loop_t* loop,
struct ev_loop *(ev_loop_new)(unsigned int flags)) {
memset(loop, 0, sizeof(*loop));
RB_INIT(&loop->uv_ares_handles_);
#if HAVE_KQUEUE
loop->ev = ev_loop_new(EVBACKEND_KQUEUE);
#else
@@ -751,7 +752,7 @@ int uv__socket(int domain, int type, int protocol) {
goto out;

if (uv__nonblock(sockfd, 1) || uv__cloexec(sockfd, 1)) {
uv__close(sockfd);
close(sockfd);
sockfd = -1;
}

@@ -787,7 +788,7 @@ int uv__accept(int sockfd, struct sockaddr* saddr, socklen_t slen) {
}

if (uv__cloexec(peerfd, 1) || uv__nonblock(peerfd, 1)) {
uv__close(peerfd);
close(peerfd);
peerfd = -1;
}

@@ -861,7 +862,7 @@ int uv__dup(int fd) {
return -1;

if (uv__cloexec(fd, 1)) {
SAVE_ERRNO(uv__close(fd));
SAVE_ERRNO(close(fd));
return -1;
}

@@ -74,6 +74,7 @@ uv_err_code uv_translate_sys_error(int sys_errno) {
case EMSGSIZE: return UV_EMSGSIZE;
case ENAMETOOLONG: return UV_ENAMETOOLONG;
case EINVAL: return UV_EINVAL;
case ENETUNREACH: return UV_ENETUNREACH;
case ECONNABORTED: return UV_ECONNABORTED;
case ELOOP: return UV_ELOOP;
case ECONNREFUSED: return UV_ECONNREFUSED;
@@ -90,6 +91,7 @@ uv_err_code uv_translate_sys_error(int sys_errno) {
case EXDEV: return UV_EXDEV;
case EBUSY: return UV_EBUSY;
case ENOTEMPTY: return UV_ENOTEMPTY;
case ENOSPC: return UV_ENOSPC;
default: return UV_UNKNOWN;
}
UNREACHABLE();
@@ -172,13 +172,6 @@ int uv__cloexec(int fd, int set) __attribute__((unused));
int uv__socket(int domain, int type, int protocol);
int uv__dup(int fd);

/* We used to handle EINTR in uv__close() but linux 2.6 will have closed the
* file descriptor anyway, even on EINTR. Retrying in that case isn't merely
* useless, it's actively harmful - the file descriptor may have been acquired
* by another thread.
*/
#define uv__close(fd) close(fd)

/* error */
uv_err_code uv_translate_sys_error(int sys_errno);
void uv_fatal_error(const int errorno, const char* syscall);
@@ -124,7 +124,7 @@ int uv_fs_event_init(uv_loop_t* loop,
void uv__fs_event_destroy(uv_fs_event_t* handle) {
uv__fs_event_stop(handle);
free(handle->filename);
uv__close(handle->fd);
close(handle->fd);
handle->fd = -1;
}

@@ -48,6 +48,14 @@
#undef NANOSEC
#define NANOSEC 1000000000

/* This is rather annoying: CLOCK_BOOTTIME lives in <linux/time.h> but we can't
* include that file because it conflicts with <time.h>. We'll just have to
* define it ourselves.
*/
#ifndef CLOCK_BOOTTIME
# define CLOCK_BOOTTIME 7
#endif

static char buf[MAXPATHLEN + 1];

static struct {
@@ -267,22 +275,28 @@ uv_err_t uv_resident_set_memory(size_t* rss) {


uv_err_t uv_uptime(double* uptime) {
#ifdef CLOCK_MONOTONIC
static volatile int no_clock_boottime;
struct timespec now;
if (0 == clock_gettime(CLOCK_MONOTONIC, &now)) {
*uptime = now.tv_sec;
*uptime += (double)now.tv_nsec / 1000000000.0;
return uv_ok_;
int r;

/* Try CLOCK_BOOTTIME first, fall back to CLOCK_MONOTONIC if not available
* (pre-2.6.39 kernels). CLOCK_MONOTONIC doesn't increase when the system
* is suspended.
*/
if (no_clock_boottime) {
retry: r = clock_gettime(CLOCK_MONOTONIC, &now);
}
return uv__new_sys_error(errno);
#else
struct sysinfo info;
if (sysinfo(&info) < 0) {
return uv__new_sys_error(errno);
else if ((r = clock_gettime(CLOCK_BOOTTIME, &now)) && errno == EINVAL) {
no_clock_boottime = 1;
goto retry;
}
*uptime = (double)info.uptime;

if (r)
return uv__new_sys_error(errno);

*uptime = now.tv_sec;
*uptime += (double)now.tv_nsec / 1000000000.0;
return uv_ok_;
#endif
}


@@ -132,8 +132,7 @@ static int compare_watchers(const uv_fs_event_t* a, const uv_fs_event_t* b) {
}


RB_GENERATE_INTERNAL(uv__inotify_watchers, uv_fs_event_s, node, compare_watchers,
inline static __attribute__((unused)))
RB_GENERATE_STATIC(uv__inotify_watchers, uv_fs_event_s, node, compare_watchers)


void uv__inotify_loop_init(uv_loop_t* loop) {
@@ -170,7 +169,7 @@ static int new_inotify_fd(void) {
return -1;

if (uv__cloexec(fd, 1) || uv__nonblock(fd, 1)) {
SAVE_ERRNO(uv__close(fd));
SAVE_ERRNO(close(fd));
return -1;
}

@@ -216,6 +216,7 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
int numcpus = 1;
static int which[] = {CTL_HW,HW_MODEL,0};
size_t size;
int i;
uv_cpu_info_t* cpu_info;

size = sizeof(model);
@@ -245,7 +246,7 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
size = sizeof(info);
which[0] = CTL_KERN;
which[1] = KERN_CPTIME2;
for (int i = 0; i < numcpus; i++) {
for (i = 0; i < numcpus; i++) {
which[2] = i;
size = sizeof(info);
if (sysctl(which, 3, &info, &size, NULL, 0) < 0) {
@@ -109,7 +109,7 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
assert(pipe_fname != NULL);
unlink(pipe_fname);
}
uv__close(sockfd);
close(sockfd);

free((void*)pipe_fname);
}
@@ -210,7 +210,7 @@ void uv_pipe_connect(uv_connect_t* req,

if (r == -1) {
status = errno;
uv__close(sockfd);
close(sockfd);
goto out;
}

0 comments on commit 6aa7f6f

Please sign in to comment.
You can’t perform that action at this time.