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 26806e2
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Nov 10, 2011
1 parent 8dd4fcb commit e34a2c1
Show file tree
Hide file tree
Showing 10 changed files with 223 additions and 247 deletions.
106 changes: 56 additions & 50 deletions deps/uv/include/uv.h
Expand Up @@ -67,58 +67,64 @@ typedef intptr_t ssize_t;
#endif

/* Expand this list if necessary. */
#define UV_ERRNO_MAP(XX) \
XX( -1, UNKNOWN, "unknown error") \
XX( 0, OK, "success") \
XX( 1, EOF, "end of file") \
XX( 2, EADDRINFO, "getaddrinfo error") \
XX( 3, EACCES, "permission denied") \
XX( 4, EAGAIN, "no more processes") \
XX( 5, EADDRINUSE, "address already in use") \
XX( 6, EADDRNOTAVAIL, "") \
XX( 7, EAFNOSUPPORT, "") \
XX( 8, EALREADY, "") \
XX( 9, EBADF, "bad file descriptor") \
XX( 10, EBUSY, "mount device busy") \
XX( 11, ECONNABORTED, "software caused connection abort") \
XX( 12, ECONNREFUSED, "connection refused") \
XX( 13, ECONNRESET, "connection reset by peer") \
XX( 14, EDESTADDRREQ, "destination address required") \
XX( 15, EFAULT, "bad address in system call argument") \
XX( 16, EHOSTUNREACH, "host is unreachable") \
XX( 17, EINTR, "interrupted system call") \
XX( 18, EINVAL, "invalid argument") \
XX( 19, EISCONN, "socket is already connected") \
XX( 20, EMFILE, "too many open files") \
XX( 21, EMSGSIZE, "message too long") \
XX( 22, ENETDOWN, "network is down") \
XX( 23, ENETUNREACH, "network is unreachable") \
XX( 24, ENFILE, "file table overflow") \
XX( 25, ENOBUFS, "no buffer space available") \
XX( 26, ENOMEM, "not enough memory") \
XX( 27, ENOTDIR, "not a directory") \
XX( 28, EISDIR, "illegal operation on a directory") \
XX( 29, ENONET, "machine is not on the network") \
XX( 31, ENOTCONN, "socket is not connected") \
XX( 32, ENOTSOCK, "socket operation on non-socket") \
XX( 33, ENOTSUP, "operation not supported on socket") \
XX( 34, ENOENT, "no such file or directory") \
XX( 35, ENOSYS, "function not implemented") \
XX( 36, EPIPE, "broken pipe") \
XX( 37, EPROTO, "protocol error") \
XX( 38, EPROTONOSUPPORT, "protocol not suppored") \
XX( 39, EPROTOTYPE, "protocol wrong type for socket") \
XX( 40, ETIMEDOUT, "connection timed out") \
XX( 41, ECHARSET, "") \
XX( 42, EAIFAMNOSUPPORT, "") \
XX( 43, EAINONAME, "") \
XX( 44, EAISERVICE, "") \
XX( 45, EAISOCKTYPE, "") \
XX( 46, ESHUTDOWN, "") \
XX( 47, EEXIST, "file already exists") \
XX( 48, ESRCH, "no such process")


#define UV_ERRNO_GEN(val, name, s) UV_##name = val,
typedef enum {
UV_UNKNOWN = -1,
UV_OK = 0,
UV_EOF,
UV_EADDRINFO,
UV_EACCES,
UV_EAGAIN,
UV_EADDRINUSE,
UV_EADDRNOTAVAIL,
UV_EAFNOSUPPORT,
UV_EALREADY,
UV_EBADF,
UV_EBUSY,
UV_ECONNABORTED,
UV_ECONNREFUSED,
UV_ECONNRESET,
UV_EDESTADDRREQ,
UV_EFAULT,
UV_EHOSTUNREACH,
UV_EINTR,
UV_EINVAL,
UV_EISCONN,
UV_EMFILE,
UV_EMSGSIZE,
UV_ENETDOWN,
UV_ENETUNREACH,
UV_ENFILE,
UV_ENOBUFS,
UV_ENOMEM,
UV_ENOTDIR,
UV_EISDIR,
UV_ENONET,
UV_ENOPROTOOPT,
UV_ENOTCONN,
UV_ENOTSOCK,
UV_ENOTSUP,
UV_ENOENT,
UV_ENOSYS,
UV_EPIPE,
UV_EPROTO,
UV_EPROTONOSUPPORT,
UV_EPROTOTYPE,
UV_ETIMEDOUT,
UV_ECHARSET,
UV_EAIFAMNOSUPPORT,
UV_EAINONAME,
UV_EAISERVICE,
UV_EAISOCKTYPE,
UV_ESHUTDOWN,
UV_EEXIST,
UV_ESRCH
UV_ERRNO_MAP(UV_ERRNO_GEN)
UV_MAX_ERRORS
} uv_err_code;
#undef UV_ERRNO_GEN

typedef enum {
UV_UNKNOWN_HANDLE = 0,
Expand Down
69 changes: 50 additions & 19 deletions deps/uv/src/unix/core.c
Expand Up @@ -589,6 +589,10 @@ int64_t uv_timer_get_repeat(uv_timer_t* timer) {
static int uv_getaddrinfo_done(eio_req* req) {
uv_getaddrinfo_t* handle = req->data;
struct addrinfo *res = handle->res;
#if __sun
size_t hostlen = strlen(handle->hostname);
#endif

handle->res = NULL;

uv_unref(handle->loop);
Expand All @@ -605,6 +609,10 @@ static int uv_getaddrinfo_done(eio_req* req) {
} else if (handle->retcode == EAI_NONAME) {
#endif
uv__set_sys_error(handle->loop, ENOENT); /* FIXME compatibility hack */
#if __sun
} else if (handle->retcode == EAI_MEMORY && hostlen >= MAXHOSTNAMELEN) {
uv__set_sys_error(handle->loop, ENOENT);
#endif
} else {
handle->loop->last_err.code = UV_EADDRINFO;
handle->loop->last_err.sys_errno_ = handle->retcode;
Expand Down Expand Up @@ -686,22 +694,30 @@ void uv_freeaddrinfo(struct addrinfo* ai) {

/* Open a socket in non-blocking close-on-exec mode, atomically if possible. */
int uv__socket(int domain, int type, int protocol) {
#if defined(SOCK_NONBLOCK) && defined(SOCK_CLOEXEC)
return socket(domain, type | SOCK_NONBLOCK | SOCK_CLOEXEC, protocol);
#else
int sockfd;

if ((sockfd = socket(domain, type, protocol)) == -1) {
return -1;
}
#if defined(SOCK_NONBLOCK) && defined(SOCK_CLOEXEC)
sockfd = socket(domain, type | SOCK_NONBLOCK | SOCK_CLOEXEC, protocol);

if (uv__nonblock(sockfd, 1) == -1 || uv__cloexec(sockfd, 1) == -1) {
if (sockfd != -1)
goto out;

if (errno != EINVAL)
goto out;
#endif

sockfd = socket(domain, type, protocol);

if (sockfd == -1)
goto out;

if (uv__nonblock(sockfd, 1) || uv__cloexec(sockfd, 1)) {
uv__close(sockfd);
return -1;
sockfd = -1;
}

out:
return sockfd;
#endif
}


Expand All @@ -710,19 +726,34 @@ int uv__accept(int sockfd, struct sockaddr* saddr, socklen_t slen) {

assert(sockfd >= 0);

do {
#if defined(HAVE_ACCEPT4)
while (1) {
#if HAVE_ACCEPT4
peerfd = accept4(sockfd, saddr, &slen, SOCK_NONBLOCK | SOCK_CLOEXEC);
#else
if ((peerfd = accept(sockfd, saddr, &slen)) != -1) {
if (uv__cloexec(peerfd, 1) == -1 || uv__nonblock(peerfd, 1) == -1) {
uv__close(peerfd);
return -1;
}
}

if (peerfd != -1)
break;

if (errno == EINTR)
continue;

if (errno != ENOSYS)
break;
#endif

if ((peerfd = accept(sockfd, saddr, &slen)) == -1) {
if (errno == EINTR)
continue;
else
break;
}

if (uv__cloexec(peerfd, 1) || uv__nonblock(peerfd, 1)) {
uv__close(peerfd);
peerfd = -1;
}

break;
}
while (peerfd == -1 && errno == EINTR);

return peerfd;
}
Expand Down
54 changes: 0 additions & 54 deletions deps/uv/src/unix/error.c
Expand Up @@ -56,38 +56,6 @@ void uv_fatal_error(const int errorno, const char* syscall) {
}


static int uv__translate_lib_error(int code) {
switch (code) {
case UV_ENOSYS: return ENOSYS;
case UV_ENOTSOCK: return ENOTSOCK;
case UV_ENOENT: return ENOENT;
case UV_EACCES: return EACCES;
case UV_EAFNOSUPPORT: return EAFNOSUPPORT;
case UV_EBADF: return EBADF;
case UV_EPIPE: return EPIPE;
case UV_EAGAIN: return EAGAIN;
case UV_ECONNRESET: return ECONNRESET;
case UV_EFAULT: return EFAULT;
case UV_EMFILE: return EMFILE;
case UV_EMSGSIZE: return EMSGSIZE;
case UV_EINVAL: return EINVAL;
case UV_ECONNREFUSED: return ECONNREFUSED;
case UV_EADDRINUSE: return EADDRINUSE;
case UV_EADDRNOTAVAIL: return EADDRNOTAVAIL;
case UV_ENOTDIR: return ENOTDIR;
case UV_EISDIR: return EISDIR;
case UV_ENOTCONN: return ENOTCONN;
case UV_EEXIST: return EEXIST;
case UV_EHOSTUNREACH: return EHOSTUNREACH;
case UV_ESRCH: return ESRCH;
default: return -1;
}

assert(0 && "unreachable");
return -1;
}


uv_err_code uv_translate_sys_error(int sys_errno) {
switch (sys_errno) {
case 0: return UV_OK;
Expand Down Expand Up @@ -120,25 +88,3 @@ uv_err_code uv_translate_sys_error(int sys_errno) {
assert(0 && "unreachable");
return -1;
}


/* TODO Pull in error messages so we don't have to
* a) rely on what the system provides us
* b) reverse-map the error codes
*/
const char* uv_strerror(uv_err_t err) {
int errorno;

if (err.sys_errno_)
errorno = err.sys_errno_;
else
errorno = uv__translate_lib_error(err.code);

if (err.code == UV_EADDRINFO)
return gai_strerror(errorno);

if (errorno == -1)
return "Unknown error";
else
return strerror(errorno);
}
4 changes: 0 additions & 4 deletions deps/uv/src/unix/freebsd.c
Expand Up @@ -43,10 +43,6 @@ uint64_t uv_hrtime(void) {


int uv_exepath(char* buffer, size_t* size) {
uint32_t usize;
int result;
char* path;
char* fullpath;
int mib[4];
size_t cb;

Expand Down

0 comments on commit e34a2c1

Please sign in to comment.