Skip to content

Commit 917c4e2

Browse files
committed
Sync libuv up to db413f3806356a632774b8a589546fc6788debd6
1 parent ebd89aa commit 917c4e2

30 files changed

+756
-181
lines changed

src/libuv/dist-files

+2
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@
264264
./test/test-getsockname.c
265265
./test/test-hrtime.c
266266
./test/test-idle.c
267+
./test/test-ipc-send-recv.c
267268
./test/test-ipc.c
268269
./test/test-list.h
269270
./test/test-loop-handles.c
@@ -277,6 +278,7 @@
277278
./test/test-process-title.c
278279
./test/test-ref.c
279280
./test/test-run-once.c
281+
./test/test-shutdown-close.c
280282
./test/test-shutdown-eof.c
281283
./test/test-spawn.c
282284
./test/test-stdio-over-pipes.c

src/libuv/include/uv.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ typedef intptr_t ssize_t;
8080
XX( 7, EAFNOSUPPORT, "") \
8181
XX( 8, EALREADY, "") \
8282
XX( 9, EBADF, "bad file descriptor") \
83-
XX( 10, EBUSY, "mount device busy") \
83+
XX( 10, EBUSY, "resource busy or locked") \
8484
XX( 11, ECONNABORTED, "software caused connection abort") \
8585
XX( 12, ECONNREFUSED, "connection refused") \
8686
XX( 13, ECONNRESET, "connection reset by peer") \
@@ -120,7 +120,8 @@ typedef intptr_t ssize_t;
120120
XX( 49, ENAMETOOLONG, "name too long") \
121121
XX( 50, EPERM, "operation not permitted") \
122122
XX( 51, ELOOP, "too many symbolic links encountered") \
123-
XX( 52, EXDEV, "cross-device link not permitted")
123+
XX( 52, EXDEV, "cross-device link not permitted") \
124+
XX( 53, ENOTEMPTY, "directory not empty")
124125

125126

126127
#define UV_ERRNO_GEN(val, name, s) UV_##name = val,

src/libuv/src/unix/error.c

+2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ uv_err_code uv_translate_sys_error(int sys_errno) {
8888
case ESRCH: return UV_ESRCH;
8989
case ETIMEDOUT: return UV_ETIMEDOUT;
9090
case EXDEV: return UV_EXDEV;
91+
case EBUSY: return UV_EBUSY;
92+
case ENOTEMPTY: return UV_ENOTEMPTY;
9193
default: return UV_UNKNOWN;
9294
}
9395
UNREACHABLE();

src/libuv/src/unix/stream.c

+32-6
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@
2222
#include "uv.h"
2323
#include "internal.h"
2424

25-
#include <assert.h>
26-
#include <errno.h>
27-
#include <unistd.h>
25+
#include <stdio.h>
2826
#include <stdlib.h>
2927
#include <string.h>
30-
#include <sys/uio.h>
28+
#include <assert.h>
29+
#include <errno.h>
3130

32-
#include <stdio.h>
31+
#include <sys/types.h>
32+
#include <sys/socket.h>
33+
#include <sys/uio.h>
34+
#include <sys/un.h>
35+
#include <unistd.h>
3336

3437

3538
static void uv__stream_connect(uv_stream_t*);
@@ -513,6 +516,28 @@ static void uv__write_callbacks(uv_stream_t* stream) {
513516
}
514517

515518

519+
static uv_handle_type uv__handle_type(int fd) {
520+
struct sockaddr_storage ss;
521+
socklen_t len;
522+
523+
memset(&ss, 0, sizeof(ss));
524+
len = sizeof(ss);
525+
526+
if (getsockname(fd, (struct sockaddr*)&ss, &len))
527+
return UV_UNKNOWN_HANDLE;
528+
529+
switch (ss.ss_family) {
530+
case AF_UNIX:
531+
return UV_NAMED_PIPE;
532+
case AF_INET:
533+
case AF_INET6:
534+
return UV_TCP;
535+
}
536+
537+
return UV_UNKNOWN_HANDLE;
538+
}
539+
540+
516541
static void uv__read(uv_stream_t* stream) {
517542
uv_buf_t buf;
518543
ssize_t nread;
@@ -633,7 +658,8 @@ static void uv__read(uv_stream_t* stream) {
633658

634659

635660
if (stream->accepted_fd >= 0) {
636-
stream->read2_cb((uv_pipe_t*)stream, nread, buf, UV_TCP);
661+
stream->read2_cb((uv_pipe_t*)stream, nread, buf,
662+
uv__handle_type(stream->accepted_fd));
637663
} else {
638664
stream->read2_cb((uv_pipe_t*)stream, nread, buf, UV_UNKNOWN_HANDLE);
639665
}

src/libuv/src/win/error.c

+5
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ uv_err_code uv_translate_sys_error(int sys_errno) {
7878
case WSAEAFNOSUPPORT: return UV_EAFNOSUPPORT;
7979
case WSAEWOULDBLOCK: return UV_EAGAIN;
8080
case WSAEALREADY: return UV_EALREADY;
81+
case ERROR_LOCK_VIOLATION: return UV_EBUSY;
82+
case ERROR_SHARING_VIOLATION: return UV_EBUSY;
8183
case ERROR_CONNECTION_ABORTED: return UV_ECONNABORTED;
8284
case WSAECONNABORTED: return UV_ECONNABORTED;
8385
case ERROR_CONNECTION_REFUSED: return UV_ECONNREFUSED;
@@ -89,6 +91,8 @@ uv_err_code uv_translate_sys_error(int sys_errno) {
8991
case WSAEFAULT: return UV_EFAULT;
9092
case ERROR_HOST_UNREACHABLE: return UV_EHOSTUNREACH;
9193
case WSAEHOSTUNREACH: return UV_EHOSTUNREACH;
94+
case ERROR_OPERATION_ABORTED: return UV_EINTR;
95+
case WSAEINTR: return UV_EINTR;
9296
case ERROR_INVALID_DATA: return UV_EINVAL;
9397
case WSAEINVAL: return UV_EINVAL;
9498
case ERROR_CANT_RESOLVE_FILENAME: return UV_ELOOP;
@@ -102,6 +106,7 @@ uv_err_code uv_translate_sys_error(int sys_errno) {
102106
case ERROR_OUTOFMEMORY: return UV_ENOMEM;
103107
case ERROR_NOT_CONNECTED: return UV_ENOTCONN;
104108
case WSAENOTCONN: return UV_ENOTCONN;
109+
case ERROR_DIR_NOT_EMPTY: return UV_ENOTEMPTY;
105110
case ERROR_NOT_SUPPORTED: return UV_ENOTSUP;
106111
case ERROR_INSUFFICIENT_BUFFER: return UV_EINVAL;
107112
case ERROR_INVALID_FLAGS: return UV_EBADF;

src/libuv/src/win/fs.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,8 @@ static void fs__stat(uv_fs_t* req, const wchar_t* path) {
541541
req->stat.st_size = ((int64_t) info.nFileSizeHigh << 32) +
542542
(int64_t) info.nFileSizeLow;
543543

544-
req->stat.st_nlink = info.nNumberOfLinks;
544+
req->stat.st_nlink = (info.nNumberOfLinks <= SHRT_MAX) ?
545+
(short) info.nNumberOfLinks : SHRT_MAX;
545546

546547
req->ptr = &req->stat;
547548
req->result = 0;

src/libuv/src/win/handle.c

+11-4
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,15 @@
2727

2828

2929
uv_handle_type uv_guess_handle(uv_file file) {
30-
HANDLE handle = (HANDLE) _get_osfhandle(file);
30+
HANDLE handle;
3131
DWORD mode;
3232

33+
if (file < 0) {
34+
return UV_UNKNOWN_HANDLE;
35+
}
36+
37+
handle = (HANDLE) _get_osfhandle(file);
38+
3339
switch (GetFileType(handle)) {
3440
case FILE_TYPE_CHAR:
3541
if (GetConsoleMode(handle, &mode)) {
@@ -85,9 +91,10 @@ void uv_close(uv_handle_t* handle, uv_close_cb cb) {
8591
tcp = (uv_tcp_t*)handle;
8692
/* If we don't shutdown before calling closesocket, windows will */
8793
/* silently discard the kernel send buffer and reset the connection. */
88-
if (!(tcp->flags & UV_HANDLE_SHUT)) {
94+
if ((tcp->flags & UV_HANDLE_CONNECTION) &&
95+
!(tcp->flags & UV_HANDLE_SHUT)) {
8996
shutdown(tcp->socket, SD_SEND);
90-
tcp->flags |= UV_HANDLE_SHUT;
97+
tcp->flags |= UV_HANDLE_SHUTTING | UV_HANDLE_SHUT;
9198
}
9299
tcp->flags &= ~(UV_HANDLE_READING | UV_HANDLE_LISTENING);
93100
closesocket(tcp->socket);
@@ -173,7 +180,7 @@ void uv_want_endgame(uv_loop_t* loop, uv_handle_t* handle) {
173180
void uv_process_endgames(uv_loop_t* loop) {
174181
uv_handle_t* handle;
175182

176-
while (loop->endgame_handles) {
183+
while (loop->endgame_handles && loop->refs > 0) {
177184
handle = loop->endgame_handles;
178185
loop->endgame_handles = handle->endgame_next;
179186

0 commit comments

Comments
 (0)