Skip to content

Commit

Permalink
Merge branch 'v0.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Jun 29, 2012
2 parents c6f2ef2 + 5b8a112 commit b779a0d
Show file tree
Hide file tree
Showing 9 changed files with 232 additions and 196 deletions.
3 changes: 3 additions & 0 deletions common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
'LinkIncremental': 2, # enable incremental linking
},
},
'xcode_settings': {
'GCC_OPTIMIZATION_LEVEL': '0',
},
'conditions': [
['OS != "win"', {
'defines': [ 'EV_VERIFY=2' ],
Expand Down
3 changes: 2 additions & 1 deletion include/uv.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ extern "C" {
XX( 53, ENOTEMPTY, "directory not empty") \
XX( 54, ENOSPC, "no space left on device") \
XX( 55, EIO, "i/o error") \
XX( 56, EROFS, "read-only file system" )
XX( 56, EROFS, "read-only file system" ) \
XX( 57, ENODEV, "no such device" )


#define UV_ERRNO_GEN(val, name, s) UV_##name = val,
Expand Down
8 changes: 8 additions & 0 deletions src/unix/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,11 @@ int uv__accept(int sockfd) {

while (1) {
#if __linux__
static int no_accept4;

if (no_accept4)
goto skip;

peerfd = uv__accept4(sockfd,
NULL,
NULL,
Expand All @@ -464,6 +469,9 @@ int uv__accept(int sockfd) {

if (errno != ENOSYS)
break;

no_accept4 = 1;
skip:
#endif

peerfd = accept(sockfd, NULL, NULL);
Expand Down
2 changes: 1 addition & 1 deletion src/unix/dl.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ 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);
return lib->handle ? 0 : uv__dlerror(lib);
}


Expand Down
1 change: 1 addition & 0 deletions src/unix/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ uv_err_code uv_translate_sys_error(int sys_errno) {
case EADDRNOTAVAIL: return UV_EADDRNOTAVAIL;
case ENOTDIR: return UV_ENOTDIR;
case EISDIR: return UV_EISDIR;
case ENODEV: return UV_ENODEV;
case ENOTCONN: return UV_ENOTCONN;
case EEXIST: return UV_EEXIST;
case EHOSTUNREACH: return UV_EHOSTUNREACH;
Expand Down
26 changes: 19 additions & 7 deletions src/unix/linux/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,25 @@

int uv__accept4(int fd, struct sockaddr* addr, socklen_t* addrlen, int flags) {
#if __i386__
unsigned long args[] = {
(unsigned long) fd,
(unsigned long) addr,
(unsigned long) addrlen,
(unsigned long) flags
};
return syscall(__NR_socketcall, 18 /* SYS_ACCEPT4 */, args);
unsigned long args[4];
int r;

args[0] = (unsigned long) fd;
args[1] = (unsigned long) addr;
args[2] = (unsigned long) addrlen;
args[3] = (unsigned long) flags;

r = syscall(__NR_socketcall, 18 /* SYS_ACCEPT4 */, args);

/* socketcall() raises EINVAL when SYS_ACCEPT4 is not supported but so does
* a bad flags argument. Try to distinguish between the two cases.
*/
if (r == -1)
if (errno == EINVAL)
if ((flags & ~(UV__SOCK_CLOEXEC|UV__SOCK_NONBLOCK)) == 0)
errno = ENOSYS;

return r;
#elif __NR_accept4
return syscall(__NR_accept4, fd, addr, addrlen, flags);
#else
Expand Down
71 changes: 30 additions & 41 deletions src/unix/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -802,62 +802,51 @@ int uv__connect(uv_connect_t* req, uv_stream_t* stream, struct sockaddr* addr,
int sockfd;
int r;

if (stream->type != UV_TCP)
return uv__set_sys_error(stream->loop, ENOTSOCK);

if (stream->connect_req)
return uv__set_sys_error(stream->loop, EALREADY);

if (stream->fd <= 0) {
if ((sockfd = uv__socket(addr->sa_family, SOCK_STREAM, 0)) == -1) {
uv__set_sys_error(stream->loop, errno);
return -1;
}
sockfd = uv__socket(addr->sa_family, SOCK_STREAM, 0);

if (sockfd == -1)
return uv__set_sys_error(stream->loop, errno);

if (uv__stream_open(stream,
sockfd,
UV_STREAM_READABLE | UV_STREAM_WRITABLE)) {
close(sockfd);
return -2;
return -1;
}
}

uv__req_init(stream->loop, req, UV_CONNECT);
req->cb = cb;
req->handle = stream;
ngx_queue_init(&req->queue);

if (stream->connect_req) {
uv__set_sys_error(stream->loop, EALREADY);
return -1;
}

if (stream->type != UV_TCP) {
uv__set_sys_error(stream->loop, ENOTSOCK);
return -1;
}

stream->connect_req = req;
stream->delayed_error = 0;

do {
do
r = connect(stream->fd, addr, addrlen);
}
while (r == -1 && errno == EINTR);

stream->delayed_error = 0;

if (r != 0 && errno != EINPROGRESS) {
switch (errno) {
/* If we get a ECONNREFUSED wait until the next tick to report the
* error. Solaris wants to report immediately--other unixes want to
* wait.
*
* XXX: do the same for ECONNABORTED?
*/
case ECONNREFUSED:
stream->delayed_error = errno;
break;

default:
uv__set_sys_error(stream->loop, errno);
return -1;
}
if (r == -1) {
if (errno == EINPROGRESS)
; /* not an error */
else if (errno == ECONNREFUSED)
/* If we get a ECONNREFUSED wait until the next tick to report the
* error. Solaris wants to report immediately--other unixes want to
* wait.
*/
stream->delayed_error = errno;
else
return uv__set_sys_error(stream->loop, errno);
}

uv__req_init(stream->loop, req, UV_CONNECT);
req->cb = cb;
req->handle = stream;
ngx_queue_init(&req->queue);
stream->connect_req = req;

uv__io_start(stream->loop, &stream->write_watcher);

if (stream->delayed_error)
Expand Down
2 changes: 2 additions & 0 deletions src/win/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ uv_err_code uv_translate_sys_error(int sys_errno) {
case ERROR_SIGNAL_REFUSED: return UV_EIO;
case ERROR_FILE_NOT_FOUND: return UV_ENOENT;
case ERROR_INVALID_NAME: return UV_ENOENT;
case ERROR_INVALID_REPARSE_DATA: return UV_ENOENT;
case ERROR_MOD_NOT_FOUND: return UV_ENOENT;
case ERROR_PATH_NOT_FOUND: return UV_ENOENT;
case ERROR_ACCESS_DENIED: return UV_EPERM;
Expand Down Expand Up @@ -111,6 +112,7 @@ uv_err_code uv_translate_sys_error(int sys_errno) {
case ERROR_OPERATION_ABORTED: return UV_EINTR;
case WSAEINTR: return UV_EINTR;
case ERROR_INVALID_DATA: return UV_EINVAL;
case ERROR_SYMLINK_NOT_SUPPORTED: return UV_EINVAL;
case WSAEINVAL: return UV_EINVAL;
case ERROR_CANT_RESOLVE_FILENAME: return UV_ELOOP;
case ERROR_TOO_MANY_OPEN_FILES: return UV_EMFILE;
Expand Down
Loading

0 comments on commit b779a0d

Please sign in to comment.