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 497b1ec
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Jan 21, 2012
1 parent 35fe3eb commit 08ab306
Show file tree
Hide file tree
Showing 18 changed files with 353 additions and 136 deletions.
1 change: 0 additions & 1 deletion deps/uv/common.gypi
Expand Up @@ -153,7 +153,6 @@
'GCC_SYMBOLS_PRIVATE_EXTERN': 'YES', # -fvisibility=hidden
'GCC_THREADSAFE_STATICS': 'NO', # -fno-threadsafe-statics
'GCC_WARN_ABOUT_MISSING_NEWLINE': 'YES', # -Wnewline-eof
'MACOSX_DEPLOYMENT_TARGET': '10.4', # -mmacosx-version-min=10.4
'PREBINDING': 'NO', # No -Wl,-prebind
'USE_HEADERMAP': 'NO',
'OTHER_CFLAGS': [
Expand Down
4 changes: 2 additions & 2 deletions deps/uv/gyp_uv
Expand Up @@ -45,12 +45,12 @@ if __name__ == '__main__':

# There's a bug with windows which doesn't allow this feature.
if sys.platform != 'win32':

# Tell gyp to write the Makefiles into output_dir
args.extend(['--generator-output', output_dir])

# Tell make to write its output into the same dir
args.extend(['-Goutput_dir=' + output_dir])
# Create Makefiles, not XCode projects
args.extend('-f make'.split())

args.append('-Dtarget_arch=ia32')
args.append('-Dcomponent=static_library')
Expand Down
2 changes: 2 additions & 0 deletions deps/uv/include/uv-private/ev.h
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions deps/uv/include/uv.h
Expand Up @@ -200,6 +200,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.
Expand Down Expand Up @@ -628,6 +631,32 @@ UV_EXTERN int uv_udp_set_membership(uv_udp_t* handle,
const char* multicast_addr, const char* interface_addr,
uv_membership membership);

/*
* Set the multicast ttl
*
* Arguments:
* handle UDP handle. Should have been initialized with
* `uv_udp_init`.
* ttl 1 through 255
*
* Returns:
* 0 on success, -1 on error.
*/
int uv_udp_set_multicast_ttl(uv_udp_t* handle, int ttl);

/*
* Set broadcast on or off
*
* Arguments:
* handle UDP handle. Should have been initialized with
* `uv_udp_init`.
* on 1 for on, 0 for off
*
* Returns:
* 0 on success, -1 on error.
*/
int uv_udp_set_broadcast(uv_udp_t* handle, int on);

/*
* Send data. If the socket has not previously been bound with `uv_udp_bind`
* or `uv_udp_bind6`, it is bound to 0.0.0.0 (the "all interfaces" address)
Expand Down
11 changes: 5 additions & 6 deletions deps/uv/src/unix/core.c
Expand Up @@ -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;
Expand Down Expand Up @@ -181,6 +175,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) {
default_loop_ptr = &default_loop_struct;
Expand Down
6 changes: 6 additions & 0 deletions deps/uv/src/unix/ev/ev.c
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions deps/uv/src/unix/ev/ev_kqueue.c
Expand Up @@ -200,8 +200,6 @@ kqueue_destroy (EV_P)
void inline_size
kqueue_fork (EV_P)
{
close (backend_fd);

while ((backend_fd = kqueue ()) < 0)
ev_syserr ("(libev) kqueue");

Expand Down
6 changes: 2 additions & 4 deletions deps/uv/src/unix/tty.c
Expand Up @@ -120,17 +120,15 @@ uv_handle_type uv_guess_handle(uv_file file) {
struct stat s;

if (file < 0) {
uv__set_sys_error(NULL, EINVAL); /* XXX Need loop? */
return -1;
return UV_UNKNOWN_HANDLE;
}

if (isatty(file)) {
return UV_TTY;
}

if (fstat(file, &s)) {
uv__set_sys_error(NULL, errno); /* XXX Need loop? */
return -1;
return UV_UNKNOWN_HANDLE;
}

if (!S_ISSOCK(s.st_mode) && !S_ISFIFO(s.st_mode)) {
Expand Down
36 changes: 35 additions & 1 deletion deps/uv/src/unix/udp.c
Expand Up @@ -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);

Expand All @@ -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);
Expand Down Expand Up @@ -324,6 +334,12 @@ static int uv__bind(uv_udp_t* handle,
goto out;
}

yes = 1;
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof yes) == -1) {
uv__set_sys_error(handle->loop, errno);
goto out;
}

if (flags & UV_UDP_IPV6ONLY) {
#ifdef IPV6_V6ONLY
yes = 1;
Expand All @@ -332,7 +348,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
}
Expand Down Expand Up @@ -493,6 +509,24 @@ int uv_udp_set_membership(uv_udp_t* handle, const char* multicast_addr,
return 0;
}

int uv_udp_set_multicast_ttl(uv_udp_t* handle, int ttl) {
if (setsockopt(handle->fd, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof ttl) == -1) {
uv__set_sys_error(handle->loop, errno);
return -1;
}

return 0;
}

int uv_udp_set_broadcast(uv_udp_t* handle, int on) {
if (setsockopt(handle->fd, SOL_SOCKET, SO_BROADCAST, &on, sizeof on) == -1) {
uv__set_sys_error(handle->loop, errno);
return -1;
}

return 0;
}


int uv_udp_getsockname(uv_udp_t* handle, struct sockaddr* name,
int* namelen) {
Expand Down
5 changes: 5 additions & 0 deletions deps/uv/src/win/core.c
Expand Up @@ -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++;
}
Expand Down
64 changes: 64 additions & 0 deletions deps/uv/test/echo-server.c
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions deps/uv/test/task.h
Expand Up @@ -42,6 +42,7 @@

typedef enum {
TCP = 0,
UDP,
PIPE
} stream_type;

Expand Down
18 changes: 0 additions & 18 deletions deps/uv/test/test-fs-event.c
Expand Up @@ -308,21 +308,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;
}

0 comments on commit 08ab306

Please sign in to comment.