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

Commit

Permalink
deps: upgrade libuv to e079a99
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Dec 13, 2012
1 parent 0506d29 commit 6cf68ae
Show file tree
Hide file tree
Showing 34 changed files with 1,340 additions and 251 deletions.
2 changes: 0 additions & 2 deletions deps/uv/.gitignore
Expand Up @@ -31,5 +31,3 @@ UpgradeLog*.XML
Debug
Release
ipch
*.mk
*.Makefile
4 changes: 2 additions & 2 deletions deps/uv/Makefile
Expand Up @@ -44,10 +44,10 @@ BENCHMARKS=test/blackhole-server.c test/echo-server.c test/dns-server.c test/ben
all: libuv.a

test/run-tests$(E): test/run-tests.c test/runner.c $(RUNNER_SRC) $(TESTS) libuv.$(SOEXT)
$(CC) $(CPPFLAGS) $(RUNNER_CFLAGS) -o $@ $^ $(RUNNER_LIBS) $(RUNNER_LINKFLAGS)
$(CC) $(CPPFLAGS) $(RUNNER_CFLAGS) -o $@ $^ $(RUNNER_LIBS) $(RUNNER_LDFLAGS)

test/run-benchmarks$(E): test/run-benchmarks.c test/runner.c $(RUNNER_SRC) $(BENCHMARKS) libuv.$(SOEXT)
$(CC) $(CPPFLAGS) $(RUNNER_CFLAGS) -o $@ $^ $(RUNNER_LIBS) $(RUNNER_LINKFLAGS)
$(CC) $(CPPFLAGS) $(RUNNER_CFLAGS) -o $@ $^ $(RUNNER_LIBS) $(RUNNER_LDFLAGS)

test/echo.o: test/echo.c test/echo.h

Expand Down
4 changes: 2 additions & 2 deletions deps/uv/config-mingw.mk
Expand Up @@ -25,13 +25,13 @@ AR = $(PREFIX)ar
E=.exe

CFLAGS=$(CPPFLAGS) -g --std=gnu89 -D_WIN32_WINNT=0x0600
LINKFLAGS=-lm
LDFLAGS=-lm

WIN_SRCS=$(wildcard src/win/*.c)
WIN_OBJS=$(WIN_SRCS:.c=.o)

RUNNER_CFLAGS=$(CFLAGS) -D_GNU_SOURCE # Need _GNU_SOURCE for strdup?
RUNNER_LINKFLAGS=$(LINKFLAGS)
RUNNER_LDFLAGS=$(LDFLAGS)
RUNNER_LIBS=-lws2_32 -lpsapi -liphlpapi
RUNNER_SRC=test/runner-win.c

Expand Down
32 changes: 16 additions & 16 deletions deps/uv/config-unix.mk
Expand Up @@ -22,14 +22,14 @@ E=
CSTDFLAG=--std=c89 -pedantic -Wall -Wextra -Wno-unused-parameter
CFLAGS += -g
CPPFLAGS += -Isrc
LINKFLAGS=-lm
LDFLAGS=-lm

CPPFLAGS += -D_LARGEFILE_SOURCE
CPPFLAGS += -D_FILE_OFFSET_BITS=64

RUNNER_SRC=test/runner-unix.c
RUNNER_CFLAGS=$(CFLAGS) -Itest
RUNNER_LINKFLAGS=-L"$(PWD)" -luv -Xlinker -rpath -Xlinker "$(PWD)"
RUNNER_LDFLAGS=-L"$(PWD)" -luv -Xlinker -rpath -Xlinker "$(PWD)"

OBJS += src/unix/async.o
OBJS += src/unix/core.o
Expand All @@ -56,21 +56,21 @@ OBJS += src/inet.o

ifeq (SunOS,$(uname_S))
CPPFLAGS += -D__EXTENSIONS__ -D_XOPEN_SOURCE=500
LINKFLAGS+=-lkstat -lnsl -lsendfile -lsocket
LDFLAGS+=-lkstat -lnsl -lsendfile -lsocket
# Library dependencies are not transitive.
RUNNER_LINKFLAGS += $(LINKFLAGS)
RUNNER_LDFLAGS += $(LDFLAGS)
OBJS += src/unix/sunos.o
endif

ifeq (AIX,$(uname_S))
CPPFLAGS += -Isrc/ares/config_aix -D_ALL_SOURCE -D_XOPEN_SOURCE=500
LINKFLAGS+= -lperfstat
LDFLAGS+= -lperfstat
OBJS += src/unix/aix.o
endif

ifeq (Darwin,$(uname_S))
CPPFLAGS += -D_DARWIN_USE_64_BIT_INODE=1
LINKFLAGS+=-framework CoreServices -dynamiclib -install_name "@rpath/libuv.dylib"
LDFLAGS+=-framework CoreServices -dynamiclib -install_name "@rpath/libuv.dylib"
SOEXT = dylib
OBJS += src/unix/darwin.o
OBJS += src/unix/kqueue.o
Expand All @@ -79,56 +79,56 @@ endif

ifeq (Linux,$(uname_S))
CSTDFLAG += -D_GNU_SOURCE
LINKFLAGS+=-ldl -lrt
LDFLAGS+=-ldl -lrt
RUNNER_CFLAGS += -D_GNU_SOURCE
OBJS += src/unix/linux/linux-core.o \
src/unix/linux/inotify.o \
src/unix/linux/syscalls.o
endif

ifeq (FreeBSD,$(uname_S))
LINKFLAGS+=-lkvm
LDFLAGS+=-lkvm
OBJS += src/unix/freebsd.o
OBJS += src/unix/kqueue.o
endif

ifeq (DragonFly,$(uname_S))
LINKFLAGS+=-lkvm
LDFLAGS+=-lkvm
OBJS += src/unix/freebsd.o
OBJS += src/unix/kqueue.o
endif

ifeq (NetBSD,$(uname_S))
LINKFLAGS+=-lkvm
LDFLAGS+=-lkvm
OBJS += src/unix/netbsd.o
OBJS += src/unix/kqueue.o
endif

ifeq (OpenBSD,$(uname_S))
LINKFLAGS+=-lkvm
LDFLAGS+=-lkvm
OBJS += src/unix/openbsd.o
OBJS += src/unix/kqueue.o
endif

ifneq (,$(findstring CYGWIN,$(uname_S)))
# We drop the --std=c89, it hides CLOCK_MONOTONIC on cygwin
CSTDFLAG = -D_GNU_SOURCE
LINKFLAGS+=
LDFLAGS+=
OBJS += src/unix/cygwin.o
endif

ifeq (SunOS,$(uname_S))
RUNNER_LINKFLAGS += -pthreads
RUNNER_LDFLAGS += -pthreads
else
RUNNER_LINKFLAGS += -pthread
RUNNER_LDFLAGS += -pthread
endif

libuv.a: $(OBJS)
$(AR) rcs $@ $^

libuv.$(SOEXT): CFLAGS += -fPIC
libuv.$(SOEXT): override CFLAGS += -fPIC
libuv.$(SOEXT): $(OBJS)
$(CC) -shared -o $@ $^ $(LINKFLAGS)
$(CC) -shared -o $@ $^ $(LDFLAGS)

src/%.o: src/%.c include/uv.h include/uv-private/uv-unix.h
$(CC) $(CSTDFLAG) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
Expand Down
3 changes: 3 additions & 0 deletions deps/uv/include/uv-private/uv-darwin.h
Expand Up @@ -49,4 +49,7 @@
uv_sem_t cf_sem; \
uv_mutex_t cf_mutex; \

#define UV_STREAM_PRIVATE_PLATFORM_FIELDS \
void* select; \

#endif /* UV_DARWIN_H */
7 changes: 6 additions & 1 deletion deps/uv/include/uv-private/uv-unix.h
Expand Up @@ -60,7 +60,7 @@ struct uv__io_s {

struct uv__work {
void (*work)(struct uv__work *w);
void (*done)(struct uv__work *w);
void (*done)(struct uv__work *w, int status);
struct uv_loop_s* loop;
ngx_queue_t wq;
};
Expand Down Expand Up @@ -90,6 +90,10 @@ 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;
Expand Down Expand Up @@ -209,6 +213,7 @@ typedef struct {
uv_connection_cb connection_cb; \
int delayed_error; \
int accepted_fd; \
UV_STREAM_PRIVATE_PLATFORM_FIELDS \

#define UV_TCP_PRIVATE_FIELDS /* empty */

Expand Down
56 changes: 54 additions & 2 deletions deps/uv/include/uv.h
Expand Up @@ -261,6 +261,28 @@ UV_EXTERN void uv_unref(uv_handle_t*);
UV_EXTERN void uv_update_time(uv_loop_t*);
UV_EXTERN int64_t uv_now(uv_loop_t*);

/*
* Get backend file descriptor. Only kqueue, epoll and event ports are
* supported.
*
* This can be used in conjuction with uv_run_once() to poll in one thread and
* run the event loop's event callbacks in another.
*
* Useful for embedding libuv's event loop in another event loop.
* See test/test-embed.c for an example.
*
* Note that embedding a kqueue fd in another kqueue pollset doesn't work on
* all platforms. It's not an error to add the fd but it never generates
* events.
*/
UV_EXTERN int uv_backend_fd(const uv_loop_t*);

/*
* Get the poll timeout. The return value is in milliseconds, or -1 for no
* timeout.
*/
UV_EXTERN int uv_backend_timeout(const uv_loop_t*);


/*
* Should return a buffer that libuv can use to read data into.
Expand Down Expand Up @@ -308,7 +330,7 @@ typedef void (*uv_exit_cb)(uv_process_t*, int exit_status, int term_signal);
typedef void (*uv_walk_cb)(uv_handle_t* handle, void* arg);
typedef void (*uv_fs_cb)(uv_fs_t* req);
typedef void (*uv_work_cb)(uv_work_t* req);
typedef void (*uv_after_work_cb)(uv_work_t* req);
typedef void (*uv_after_work_cb)(uv_work_t* req, int status);
typedef void (*uv_getaddrinfo_cb)(uv_getaddrinfo_t* req,
int status,
struct addrinfo* res);
Expand Down Expand Up @@ -1314,7 +1336,13 @@ enum uv_process_flags {
* parent's event loop alive unless the parent process calls uv_unref() on
* the child's process handle.
*/
UV_PROCESS_DETACHED = (1 << 3)
UV_PROCESS_DETACHED = (1 << 3),
/*
* Hide the subprocess console window that would normally be created. This
* option is only meaningful on Windows systems. On unix it is silently
* ignored.
*/
UV_PROCESS_WINDOWS_HIDE = (1 << 4)
};

/*
Expand Down Expand Up @@ -1358,6 +1386,30 @@ struct uv_work_s {
UV_EXTERN int uv_queue_work(uv_loop_t* loop, uv_work_t* req,
uv_work_cb work_cb, uv_after_work_cb after_work_cb);

/* Cancel a pending request. Fails if the request is executing or has finished
* executing.
*
* Returns 0 on success, -1 on error. The loop error code is not touched.
*
* Only cancellation of uv_fs_t, uv_getaddrinfo_t and uv_work_t requests is
* currently supported.
*
* Cancelled requests have their callbacks invoked some time in the future.
* It's _not_ safe to free the memory associated with the request until your
* callback is called.
*
* Here is how cancellation is reported to your callback:
*
* - A uv_fs_t request has its req->errorno field set to UV_ECANCELED.
*
* - A uv_work_t or uv_getaddrinfo_t request has its callback invoked with
* status == -1 and uv_last_error(loop).code == UV_ECANCELED.
*
* This function is currently only implemented on UNIX platforms. On Windows,
* it always returns -1.
*/
UV_EXTERN int uv_cancel(uv_req_t* req);


struct uv_cpu_info_s {
char* model;
Expand Down
2 changes: 2 additions & 0 deletions deps/uv/src/unix/async.c
Expand Up @@ -84,6 +84,8 @@ int uv_async_send(uv_async_t* handle) {
r = write(handle->loop->async_pipefd[1], "x", 1);
while (r == -1 && errno == EINTR);

assert(r == -1 || r == 1);

if (r == -1 && errno != EAGAIN && errno != EWOULDBLOCK)
return uv__set_sys_error(handle->loop, errno);

Expand Down
25 changes: 20 additions & 5 deletions deps/uv/src/unix/core.c
Expand Up @@ -248,7 +248,12 @@ void uv_loop_delete(uv_loop_t* loop) {
}


static unsigned int uv__poll_timeout(uv_loop_t* loop) {
int uv_backend_fd(const uv_loop_t* loop) {
return loop->backend_fd;
}


int uv_backend_timeout(const uv_loop_t* loop) {
if (!uv__has_active_handles(loop) && !uv__has_active_reqs(loop))
return 0;

Expand All @@ -268,7 +273,7 @@ static int uv__run(uv_loop_t* loop) {
uv__run_idle(loop);
uv__run_prepare(loop);
uv__run_pending(loop);
uv__io_poll(loop, uv__poll_timeout(loop));
uv__io_poll(loop, uv_backend_timeout(loop));
uv__run_check(loop);
uv__run_closing_handles(loop);
return uv__has_active_handles(loop) || uv__has_active_reqs(loop);
Expand Down Expand Up @@ -325,6 +330,13 @@ int uv__socket(int domain, int type, int protocol) {
sockfd = -1;
}

#if defined(SO_NOSIGPIPE)
{
int on = 1;
setsockopt(sockfd, SOL_SOCKET, SO_NOSIGPIPE, &on, sizeof(on));
}
#endif

out:
return sockfd;
}
Expand Down Expand Up @@ -629,9 +641,6 @@ void uv__io_stop(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
w->pevents &= ~events;

if (w->pevents == 0) {
ngx_queue_remove(&w->pending_queue);
ngx_queue_init(&w->pending_queue);

ngx_queue_remove(&w->watcher_queue);
ngx_queue_init(&w->watcher_queue);

Expand All @@ -648,6 +657,12 @@ void uv__io_stop(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
}


void uv__io_close(uv_loop_t* loop, uv__io_t* w) {
uv__io_stop(loop, w, UV__POLLIN | UV__POLLOUT);
ngx_queue_remove(&w->pending_queue);
}


void uv__io_feed(uv_loop_t* loop, uv__io_t* w) {
if (ngx_queue_empty(&w->pending_queue))
ngx_queue_insert_tail(&loop->pending_queue, &w->pending_queue);
Expand Down
10 changes: 8 additions & 2 deletions deps/uv/src/unix/fs.c
Expand Up @@ -90,7 +90,7 @@
} \
else { \
uv__fs_work(&(req)->work_req); \
uv__fs_done(&(req)->work_req); \
uv__fs_done(&(req)->work_req, 0); \
return (req)->result; \
} \
} \
Expand Down Expand Up @@ -516,7 +516,7 @@ static void uv__fs_work(struct uv__work* w) {
}


static void uv__fs_done(struct uv__work* w) {
static void uv__fs_done(struct uv__work* w, int status) {
uv_fs_t* req;

req = container_of(w, uv_fs_t, work_req);
Expand All @@ -527,6 +527,12 @@ static void uv__fs_done(struct uv__work* w) {
uv__set_artificial_error(req->loop, req->errorno);
}

if (status == -UV_ECANCELED) {
assert(req->errorno == 0);
req->errorno = UV_ECANCELED;
uv__set_artificial_error(req->loop, UV_ECANCELED);
}

if (req->cb != NULL)
req->cb(req);
}
Expand Down

0 comments on commit 6cf68ae

Please sign in to comment.