diff --git a/src/unix/core.c b/src/unix/core.c index 55c75152..75c01054 100644 --- a/src/unix/core.c +++ b/src/unix/core.c @@ -790,23 +790,6 @@ int uv__accept(int sockfd, struct sockaddr* saddr, socklen_t slen) { } -int uv__close(int fd) { - int status; - - /* - * Retry on EINTR. You may think this is academic but on linux - * and probably other Unices too, close(2) is interruptible. - * Failing to handle EINTR is a common source of fd leaks. - */ - do { - status = close(fd); - } - while (status == -1 && errno == EINTR); - - return status; -} - - int uv__nonblock(int fd, int set) { #if FIONBIO return ioctl(fd, FIONBIO, &set); diff --git a/src/unix/internal.h b/src/unix/internal.h index 70dca5da..084d2d5c 100644 --- a/src/unix/internal.h +++ b/src/unix/internal.h @@ -154,14 +154,19 @@ enum { UV_TCP_KEEPALIVE = 0x100 /* Turn on keep-alive. */ }; -int uv__close(int fd); +/* core */ void uv__handle_init(uv_loop_t* loop, uv_handle_t* handle, uv_handle_type type); - - int uv__nonblock(int fd, int set) __attribute__((unused)); int uv__cloexec(int fd, int set) __attribute__((unused)); int uv__socket(int domain, int type, int protocol); +/* We used to handle EINTR in uv__close() but linux 2.6 will have closed the + * file descriptor anyway, even on EINTR. Retrying in that case isn't merely + * useless, it's actively harmful - the file descriptor may have been acquired + * by another thread. + */ +#define uv__close(fd) close(fd) + /* error */ uv_err_code uv_translate_sys_error(int sys_errno); void uv_fatal_error(const int errorno, const char* syscall);