Skip to content

Commit

Permalink
Upgrade libuv to 2806b0386b266ee7377459b49156a60a15b1dfea
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus committed Jul 22, 2011
1 parent 0ed1354 commit 9e77b1a
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 25 deletions.
2 changes: 1 addition & 1 deletion deps/uv/config-unix.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
CC = $(PREFIX)gcc
AR = $(PREFIX)ar
E=
CSTDFLAG=--std=c89 -pedantic
CSTDFLAG=--std=c89 -pedantic -Wall -Wextra -Wno-unused-parameter
CFLAGS=-g
CPPFLAGS += -Isrc/ev
LINKFLAGS=-lm
Expand Down
24 changes: 15 additions & 9 deletions deps/uv/include/ev.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@

EV_CPP(extern "C" {)

#ifdef __GNUC__
# define EV_MAYBE_UNUSED __attribute__ ((unused))
#else
# define EV_MAYBE_UNUSED
#endif

/*****************************************************************************/

/* pre-4.0 compatibility */
Expand Down Expand Up @@ -539,15 +545,15 @@ void ev_set_syserr_cb (void (*cb)(const char *msg));
struct ev_loop *ev_default_loop (unsigned int flags EV_CPP (= 0));

EV_INLINE struct ev_loop *
ev_default_loop_uc_ (void)
EV_MAYBE_UNUSED ev_default_loop_uc_ (void)
{
extern struct ev_loop *ev_default_loop_ptr;

return ev_default_loop_ptr;
}

EV_INLINE int
ev_is_default_loop (EV_P)
EV_MAYBE_UNUSED ev_is_default_loop (EV_P)
{
return EV_A == EV_DEFAULT_UC;
}
Expand Down Expand Up @@ -807,14 +813,14 @@ void ev_async_send (EV_P_ ev_async *w);
#define EVUNLOOP_ONE EVBREAK_ONE
#define EVUNLOOP_ALL EVBREAK_ALL
#if EV_PROTOTYPES
EV_INLINE void ev_loop (EV_P_ int flags) { ev_run (EV_A_ flags); }
EV_INLINE void ev_unloop (EV_P_ int how ) { ev_break (EV_A_ how ); }
EV_INLINE void ev_default_destroy (void) { ev_loop_destroy (EV_DEFAULT); }
EV_INLINE void ev_default_fork (void) { ev_loop_fork (EV_DEFAULT); }
EV_INLINE void EV_MAYBE_UNUSED ev_loop (EV_P_ int flags) { ev_run (EV_A_ flags); }
EV_INLINE void EV_MAYBE_UNUSED ev_unloop (EV_P_ int how ) { ev_break (EV_A_ how ); }
EV_INLINE void EV_MAYBE_UNUSED ev_default_destroy (void) { ev_loop_destroy (EV_DEFAULT); }
EV_INLINE void EV_MAYBE_UNUSED ev_default_fork (void) { ev_loop_fork (EV_DEFAULT); }
#if EV_FEATURE_API
EV_INLINE unsigned int ev_loop_count (EV_P) { return ev_iteration (EV_A); }
EV_INLINE unsigned int ev_loop_depth (EV_P) { return ev_depth (EV_A); }
EV_INLINE void ev_loop_verify (EV_P) { ev_verify (EV_A); }
EV_INLINE unsigned int EV_MAYBE_UNUSED ev_loop_count (EV_P) { return ev_iteration (EV_A); }
EV_INLINE unsigned int EV_MAYBE_UNUSED ev_loop_depth (EV_P) { return ev_depth (EV_A); }
EV_INLINE void EV_MAYBE_UNUSED ev_loop_verify (EV_P) { ev_verify (EV_A); }
#endif
#endif
#else
Expand Down
41 changes: 31 additions & 10 deletions deps/uv/src/uv-unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ static uv_write_t* uv__write(uv_stream_t* stream) {

assert(req->write_index < req->bufcnt);

if (n < len) {
if ((size_t)n < len) {
buf->base += n;
buf->len -= n;
stream->write_queue_size -= n;
Expand All @@ -717,7 +717,7 @@ static uv_write_t* uv__write(uv_stream_t* stream) {
/* Finished writing the buf at index req->write_index. */
req->write_index++;

assert(n >= len);
assert((size_t)n >= len);
n -= len;

assert(stream->write_queue_size >= len);
Expand Down Expand Up @@ -1788,29 +1788,40 @@ int uv_pipe_init(uv_pipe_t* handle) {

int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
struct sockaddr_un sun;
const char* pipe_fname;
int saved_errno;
int sockfd;
int status;
int bound;

saved_errno = errno;
pipe_fname = NULL;
sockfd = -1;
status = -1;
bound = 0;

/* Already bound? */
if (handle->fd >= 0) {
uv_err_new_artificial((uv_handle_t*)handle, UV_EINVAL);
goto out;
}

/* Make a copy of the file name, it outlives this function's scope. */
if ((name = (const char*)strdup(name)) == NULL) {
if ((pipe_fname = strdup(name)) == NULL) {
uv_err_new((uv_handle_t*)handle, ENOMEM);
goto out;
}

/* We've got a copy, don't touch the original any more. */
name = NULL;

if ((sockfd = uv__socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
uv_err_new((uv_handle_t*)handle, errno);
goto out;
}

memset(&sun, 0, sizeof sun);
uv__strlcpy(sun.sun_path, name, sizeof(sun.sun_path));
uv__strlcpy(sun.sun_path, pipe_fname, sizeof(sun.sun_path));
sun.sun_family = AF_UNIX;

if (bind(sockfd, (struct sockaddr*)&sun, sizeof sun) == -1) {
Expand All @@ -1820,24 +1831,25 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
* on EADDRINUSE. Unlinking and trying to bind again opens
* a window for races with other threads and processes.
*/
uv_err_new((uv_handle_t*)handle, errno);
uv_err_new((uv_handle_t*)handle, (errno == ENOENT) ? EACCES : errno);
goto out;
#else
/*
* Try to re-purpose the socket. This is a potential race window.
*/
if (errno != EADDRINUSE
|| unlink(name) == -1
|| unlink(pipe_fname) == -1
|| bind(sockfd, (struct sockaddr*)&sun, sizeof sun) == -1) {
uv_err_new((uv_handle_t*)handle, errno);
/* Convert ENOENT to EACCES for compatibility with Windows. */
uv_err_new((uv_handle_t*)handle, (errno == ENOENT) ? EACCES : errno);
goto out;
}
#endif
}
bound = 1;

/* Success. */
handle->pipe_fname = name; /* Is a strdup'ed copy. */
handle->pipe_fname = pipe_fname; /* Is a strdup'ed copy. */
handle->fd = sockfd;
status = 0;

Expand All @@ -1846,10 +1858,11 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
if (status) {
if (bound) {
/* unlink() before close() to avoid races. */
unlink(name);
assert(pipe_fname != NULL);
unlink(pipe_fname);
}
uv__close(sockfd);
free((void*)name);
free((void*)pipe_fname);
}

errno = saved_errno;
Expand All @@ -1862,6 +1875,13 @@ int uv_pipe_listen(uv_pipe_t* handle, uv_connection_cb cb) {
int status;

saved_errno = errno;
status = -1;

if (handle->fd == -1) {
uv_err_new_artificial((uv_handle_t*)handle, UV_ENOTCONN);
goto out;
}
assert(handle->fd >= 0);

if ((status = listen(handle->fd, SOMAXCONN)) == -1) {
uv_err_new((uv_handle_t*)handle, errno);
Expand All @@ -1871,6 +1891,7 @@ int uv_pipe_listen(uv_pipe_t* handle, uv_connection_cb cb) {
ev_io_start(EV_DEFAULT_ &handle->read_watcher);
}

out:
errno = saved_errno;
return status;
}
Expand Down
3 changes: 1 addition & 2 deletions deps/uv/src/win/pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
handle->error = LOOP->last_error;
handle->flags |= UV_HANDLE_BIND_ERROR;
} else if (errno == ERROR_PATH_NOT_FOUND || errno == ERROR_INVALID_NAME) {
uv_set_error(UV_EADDRNOTAVAIL, errno);
uv_set_error(UV_EACCESS, errno);
} else {
uv_set_sys_error(errno);
}
Expand Down Expand Up @@ -399,7 +399,6 @@ int uv_pipe_accept(uv_pipe_t* server, uv_pipe_t* client) {
}

/* Initialize the client handle and copy the pipeHandle to the client */
uv_pipe_init(client);
uv_connection_init((uv_stream_t*) client);
client->handle = req->pipeHandle;

Expand Down
7 changes: 7 additions & 0 deletions deps/uv/test/runner.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ int run_test(const char* test, int timeout, int benchmark_output) {
status = 255;
process_count = 0;

/* If it's a helper the user asks for, start it directly. */
for (task = TASKS; task->main; task++) {
if (task->is_helper && strcmp(test, task->process_name) == 0) {
return task->main();
}
}

/* Start the helpers first. */
for (task = TASKS; task->main; task++) {
if (strcmp(test, task->task_name) != 0) {
Expand Down
5 changes: 2 additions & 3 deletions deps/uv/test/test-pipe-bind-error.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
#ifdef _WIN32
# define BAD_PIPENAME "bad-pipe"
#else
/* TODO: define a bad pipe name for unix (see pipe_bind_error_addrnotavail) */
# define BAD_PIPENAME ""
# define BAD_PIPENAME "/path/to/unix/socket/that/really/should/not/be/there"
#endif


Expand Down Expand Up @@ -89,7 +88,7 @@ TEST_IMPL(pipe_bind_error_addrnotavail) {
r = uv_pipe_bind(&server, BAD_PIPENAME);

ASSERT(r == -1);
ASSERT(uv_last_error().code == UV_EADDRNOTAVAIL);
ASSERT(uv_last_error().code == UV_EACCESS);

uv_close((uv_handle_t*)&server, close_cb);

Expand Down

0 comments on commit 9e77b1a

Please sign in to comment.