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

Commit

Permalink
uv: upgrade to b7e150ee
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus committed Jun 12, 2012
1 parent 0385b17 commit b615077
Show file tree
Hide file tree
Showing 33 changed files with 410 additions and 115 deletions.
4 changes: 3 additions & 1 deletion deps/uv/include/uv-private/ngx-queue.h
Expand Up @@ -100,7 +100,9 @@ struct ngx_queue_s {


#define ngx_queue_foreach(q, h) \
for ((q) = ngx_queue_head(h); (q) != (h); (q) = ngx_queue_next(q))
for ((q) = ngx_queue_head(h); \
(q) != ngx_queue_sentinel(h); \
(q) = ngx_queue_next(q))


#endif /* NGX_QUEUE_H_INCLUDED_ */
11 changes: 8 additions & 3 deletions deps/uv/include/uv-private/uv-unix.h
Expand Up @@ -38,6 +38,7 @@

#include <semaphore.h>
#include <pthread.h>
#include <signal.h>

#if __sun
# include <sys/port.h>
Expand Down Expand Up @@ -113,6 +114,9 @@ struct uv__io_s {
ngx_queue_t prepare_handles; \
ngx_queue_t check_handles; \
ngx_queue_t idle_handles; \
ngx_queue_t async_handles; \
uv__io_t async_watcher; \
int async_pipefd[2]; \
/* RB_HEAD(uv__timers, uv_timer_s) */ \
struct uv__timers { struct uv_timer_s* rbh_root; } timer_handles; \
uint64_t time; \
Expand Down Expand Up @@ -211,9 +215,10 @@ struct uv__io_s {


/* UV_ASYNC */
#define UV_ASYNC_PRIVATE_FIELDS \
ev_async async_watcher; \
uv_async_cb async_cb;
#define UV_ASYNC_PRIVATE_FIELDS \
volatile sig_atomic_t pending; \
uv_async_cb async_cb; \
ngx_queue_t queue;


/* UV_TIMER */
Expand Down
95 changes: 77 additions & 18 deletions deps/uv/src/unix/async.c
Expand Up @@ -21,40 +21,99 @@
#include "uv.h"
#include "internal.h"

#include <errno.h>
#include <assert.h>
#include <stdlib.h>
#include <unistd.h>

static void uv__async(EV_P_ ev_async* w, int revents) {
uv_async_t* async = container_of(w, uv_async_t, async_watcher);
static int uv__async_init(uv_loop_t* loop);
static void uv__async_io(uv_loop_t* loop, uv__io_t* handle, int events);

if (async->async_cb) {
async->async_cb(async, 0);
}
}

int uv_async_init(uv_loop_t* loop, uv_async_t* handle, uv_async_cb async_cb) {
if (uv__async_init(loop))
return uv__set_sys_error(loop, errno);

int uv_async_init(uv_loop_t* loop, uv_async_t* async, uv_async_cb async_cb) {
uv__handle_init(loop, (uv_handle_t*)async, UV_ASYNC);
uv__handle_init(loop, (uv_handle_t*)handle, UV_ASYNC);
loop->counters.async_init++;

ev_async_init(&async->async_watcher, uv__async);
async->async_cb = async_cb;
handle->async_cb = async_cb;
handle->pending = 0;

/* Note: This does not have symmetry with the other libev wrappers. */
ev_async_start(loop->ev, &async->async_watcher);
uv__handle_unref(async);
uv__handle_start(async);
ngx_queue_insert_tail(&loop->async_handles, &handle->queue);
uv__handle_start(handle);

return 0;
}


int uv_async_send(uv_async_t* async) {
ev_async_send(async->loop->ev, &async->async_watcher);
int uv_async_send(uv_async_t* handle) {
int r;

handle->pending = 1; /* XXX needs a memory barrier? */

do
r = write(handle->loop->async_pipefd[1], "x", 1);
while (r == -1 && errno == EINTR);

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

return 0;
}


void uv__async_close(uv_async_t* handle) {
ev_async_stop(handle->loop->ev, &handle->async_watcher);
uv__handle_ref(handle);
ngx_queue_remove(&handle->queue);
uv__handle_stop(handle);
}


static int uv__async_init(uv_loop_t* loop) {
if (loop->async_pipefd[0] != -1)
return 0;

if (uv__make_pipe(loop->async_pipefd, UV__F_NONBLOCK))
return -1;

uv__io_init(&loop->async_watcher,
uv__async_io,
loop->async_pipefd[0],
UV__IO_READ);
uv__io_start(loop, &loop->async_watcher);

return 0;
}


static void uv__async_io(uv_loop_t* loop, uv__io_t* handle, int events) {
char buf[1024];
ngx_queue_t* q;
uv_async_t* h;
ssize_t r;

while (1) {
r = read(loop->async_pipefd[0], buf, sizeof(buf));

if (r == sizeof(buf))
continue;

if (r != -1)
break;

if (errno == EAGAIN || errno == EWOULDBLOCK)
break;

if (errno == EINTR)
continue;

abort();
}

ngx_queue_foreach(q, &loop->async_handles) {
h = ngx_queue_data(q, uv_async_t, queue);
if (!h->pending) continue;
h->pending = 0;
h->async_cb(h, 0);
}
}
3 changes: 3 additions & 0 deletions deps/uv/src/unix/core.c
Expand Up @@ -233,6 +233,9 @@ static unsigned int uv__poll_timeout(uv_loop_t* loop) {
if (!ngx_queue_empty(&loop->idle_handles))
return 0;

if (loop->closing_handles)
return 0;

return uv__next_timeout(loop);
}

Expand Down
2 changes: 1 addition & 1 deletion deps/uv/src/unix/cygwin.c
Expand Up @@ -29,7 +29,7 @@
#include <time.h>

#undef NANOSEC
#define NANOSEC 1000000000
#define NANOSEC ((uint64_t) 1e9)


uint64_t uv_hrtime() {
Expand Down
1 change: 1 addition & 0 deletions deps/uv/src/unix/dl.c
Expand Up @@ -31,6 +31,7 @@ static int uv__dlerror(uv_lib_t* lib);


int uv_dlopen(const char* filename, uv_lib_t* lib) {
dlerror(); /* Reset error status. */
lib->errmsg = NULL;
lib->handle = dlopen(filename, RTLD_LAZY);
return uv__dlerror(lib);
Expand Down
2 changes: 1 addition & 1 deletion deps/uv/src/unix/freebsd.c
Expand Up @@ -38,7 +38,7 @@
#include <fcntl.h>

#undef NANOSEC
#define NANOSEC 1000000000
#define NANOSEC ((uint64_t) 1e9)

#ifndef CPUSTATES
# define CPUSTATES 5U
Expand Down
8 changes: 6 additions & 2 deletions deps/uv/src/unix/internal.h
Expand Up @@ -168,8 +168,12 @@ void uv__timer_close(uv_timer_t* handle);
void uv__udp_close(uv_udp_t* handle);
void uv__udp_finish_close(uv_udp_t* handle);

#define UV__F_IPC (1 << 0)
#define UV__F_NONBLOCK (1 << 1)
#ifdef UV__O_NONBLOCK
# define UV__F_NONBLOCK UV__O_NONBLOCK
#else
# define UV__F_NONBLOCK 1
#endif

int uv__make_socketpair(int fds[2], int flags);
int uv__make_pipe(int fds[2], int flags);

Expand Down
2 changes: 1 addition & 1 deletion deps/uv/src/unix/linux/core.c
Expand Up @@ -46,7 +46,7 @@
#endif

#undef NANOSEC
#define NANOSEC 1000000000
#define NANOSEC ((uint64_t) 1e9)

/* 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
Expand Down
38 changes: 38 additions & 0 deletions deps/uv/src/unix/linux/syscalls.c
Expand Up @@ -49,6 +49,26 @@
# endif
#endif /* __NR_accept4 */

#ifndef __NR_eventfd
# if __x86_64__
# define __NR_eventfd 284
# elif __i386__
# define __NR_eventfd 323
# elif __arm__
# define __NR_eventfd (UV_SYSCALL_BASE + 351)
# endif
#endif /* __NR_eventfd */

#ifndef __NR_eventfd2
# if __x86_64__
# define __NR_eventfd2 290
# elif __i386__
# define __NR_eventfd2 328
# elif __arm__
# define __NR_eventfd2 (UV_SYSCALL_BASE + 356)
# endif
#endif /* __NR_eventfd2 */

#ifndef __NR_inotify_init
# if __x86_64__
# define __NR_inotify_init 253
Expand Down Expand Up @@ -147,6 +167,24 @@ int uv__accept4(int fd, struct sockaddr* addr, socklen_t* addrlen, int flags) {
}


int uv__eventfd(unsigned int count) {
#if __NR_eventfd
return syscall(__NR_eventfd, count);
#else
return errno = ENOSYS, -1;
#endif
}


int uv__eventfd2(unsigned int count, int flags) {
#if __NR_eventfd2
return syscall(__NR_eventfd2, count, flags);
#else
return errno = ENOSYS, -1;
#endif
}


int uv__inotify_init(void) {
#if __NR_inotify_init
return syscall(__NR_inotify_init);
Expand Down
10 changes: 8 additions & 2 deletions deps/uv/src/unix/linux/syscalls.h
Expand Up @@ -32,12 +32,16 @@
#define UV__O_NONBLOCK 0x800
#define UV__O_CLOEXEC 0x80000

#define UV__SOCK_CLOEXEC UV__O_CLOEXEC
#define UV__SOCK_NONBLOCK UV__O_NONBLOCK
#define UV__EFD_CLOEXEC UV__O_CLOEXEC
#define UV__EFD_NONBLOCK UV__O_NONBLOCK

#define UV__IN_CLOEXEC UV__O_CLOEXEC
#define UV__IN_NONBLOCK UV__O_NONBLOCK

#define UV__SOCK_CLOEXEC UV__O_CLOEXEC
#define UV__SOCK_NONBLOCK UV__O_NONBLOCK

/* inotify flags */
#define UV__IN_ACCESS 0x001
#define UV__IN_MODIFY 0x002
#define UV__IN_ATTRIB 0x004
Expand Down Expand Up @@ -65,6 +69,8 @@ struct uv__mmsghdr {
};

int uv__accept4(int fd, struct sockaddr* addr, socklen_t* addrlen, int flags);
int uv__eventfd(unsigned int count);
int uv__eventfd2(unsigned int count, int flags);
int uv__inotify_init(void);
int uv__inotify_init1(int flags);
int uv__inotify_add_watch(int fd, const char* path, __u32 mask);
Expand Down
3 changes: 3 additions & 0 deletions deps/uv/src/unix/loop.c
Expand Up @@ -40,12 +40,15 @@ int uv__loop_init(uv_loop_t* loop, int default_loop) {
RB_INIT(&loop->timer_handles);
ngx_queue_init(&loop->active_reqs);
ngx_queue_init(&loop->idle_handles);
ngx_queue_init(&loop->async_handles);
ngx_queue_init(&loop->check_handles);
ngx_queue_init(&loop->prepare_handles);
ngx_queue_init(&loop->handle_queue);
loop->closing_handles = NULL;
loop->channel = NULL;
loop->time = uv_hrtime() / 1000000;
loop->async_pipefd[0] = -1;
loop->async_pipefd[1] = -1;
loop->ev = (default_loop ? ev_default_loop : ev_loop_new)(flags);
ev_set_userdata(loop->ev, loop);
eio_channel_init(&loop->uv_eio_channel, loop);
Expand Down
2 changes: 1 addition & 1 deletion deps/uv/src/unix/netbsd.c
Expand Up @@ -32,7 +32,7 @@
#include <time.h>

#undef NANOSEC
#define NANOSEC 1000000000
#define NANOSEC ((uint64_t) 1e9)


uint64_t uv_hrtime(void) {
Expand Down
2 changes: 1 addition & 1 deletion deps/uv/src/unix/openbsd.c
Expand Up @@ -37,7 +37,7 @@
#include <unistd.h>

#undef NANOSEC
#define NANOSEC 1000000000
#define NANOSEC ((uint64_t) 1e9)


static char *process_title;
Expand Down
29 changes: 6 additions & 23 deletions deps/uv/src/unix/process.c
Expand Up @@ -68,25 +68,15 @@ static void uv__chld(EV_P_ ev_child* watcher, int revents) {


int uv__make_socketpair(int fds[2], int flags) {
#ifdef SOCK_NONBLOCK
int fl;

fl = SOCK_CLOEXEC;

if (flags & UV__F_NONBLOCK)
fl |= SOCK_NONBLOCK;

if (socketpair(AF_UNIX, SOCK_STREAM|fl, 0, fds) == 0)
#if __linux__
if (socketpair(AF_UNIX, SOCK_STREAM | UV__SOCK_CLOEXEC | flags, 0, fds) == 0)
return 0;

/* Retry on EINVAL, it means SOCK_CLOEXEC is not supported.
* Anything else is a genuine error.
*/
if (errno != EINVAL)
return -1;

/* errno == EINVAL so maybe the kernel headers lied about
* the availability of SOCK_NONBLOCK. This can happen if people
* build libuv against newer kernel headers than the kernel
* they actually run the software on.
*/
#endif

if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds))
Expand All @@ -106,14 +96,7 @@ int uv__make_socketpair(int fds[2], int flags) {

int uv__make_pipe(int fds[2], int flags) {
#if __linux__
int fl;

fl = UV__O_CLOEXEC;

if (flags & UV__F_NONBLOCK)
fl |= UV__O_NONBLOCK;

if (uv__pipe2(fds, fl) == 0)
if (uv__pipe2(fds, flags | UV__O_CLOEXEC) == 0)
return 0;

if (errno != ENOSYS)
Expand Down
2 changes: 1 addition & 1 deletion deps/uv/src/unix/stream.c
Expand Up @@ -708,7 +708,7 @@ int uv_shutdown(uv_shutdown_t* req, uv_stream_t* stream, uv_shutdown_cb cb) {
stream->flags & UV_STREAM_SHUT ||
stream->flags & UV_CLOSED ||
stream->flags & UV_CLOSING) {
uv__set_sys_error(stream->loop, EINVAL);
uv__set_artificial_error(stream->loop, UV_ENOTCONN);
return -1;
}

Expand Down

0 comments on commit b615077

Please sign in to comment.