Skip to content

Commit 401c073

Browse files
bnoordhuisry
authored andcommitted
uv: upgrade to ec825ff
1 parent 493d3b9 commit 401c073

File tree

9 files changed

+185
-14
lines changed

9 files changed

+185
-14
lines changed

deps/uv/include/uv.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,15 @@ struct uv_tcp_s {
448448

449449
int uv_tcp_init(uv_loop_t*, uv_tcp_t* handle);
450450

451+
/* Enable/disable Nagle's algorithm. */
452+
int uv_tcp_nodelay(uv_tcp_t* handle, int enable);
453+
454+
/* Enable/disable TCP keep-alive.
455+
*
456+
* `ms` is the initial delay in seconds, ignored when `enable` is zero.
457+
*/
458+
int uv_tcp_keepalive(uv_tcp_t* handle, int enable, unsigned int delay);
459+
451460
int uv_tcp_bind(uv_tcp_t* handle, struct sockaddr_in);
452461
int uv_tcp_bind6(uv_tcp_t* handle, struct sockaddr_in6);
453462
int uv_tcp_getsockname(uv_tcp_t* handle, struct sockaddr* name, int* namelen);

deps/uv/src/unix/core.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,8 @@ int uv_getaddrinfo(uv_loop_t* loop,
667667

668668

669669
void uv_freeaddrinfo(struct addrinfo* ai) {
670-
freeaddrinfo(ai);
670+
if (ai)
671+
freeaddrinfo(ai);
671672
}
672673

673674

deps/uv/src/unix/internal.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,15 @@
7474

7575
/* flags */
7676
enum {
77-
UV_CLOSING = 0x00000001, /* uv_close() called but not finished. */
78-
UV_CLOSED = 0x00000002, /* close(2) finished. */
79-
UV_READING = 0x00000004, /* uv_read_start() called. */
80-
UV_SHUTTING = 0x00000008, /* uv_shutdown() called but not complete. */
81-
UV_SHUT = 0x00000010, /* Write side closed. */
82-
UV_READABLE = 0x00000020, /* The stream is readable */
83-
UV_WRITABLE = 0x00000040 /* The stream is writable */
77+
UV_CLOSING = 0x01, /* uv_close() called but not finished. */
78+
UV_CLOSED = 0x02, /* close(2) finished. */
79+
UV_READING = 0x04, /* uv_read_start() called. */
80+
UV_SHUTTING = 0x08, /* uv_shutdown() called but not complete. */
81+
UV_SHUT = 0x10, /* Write side closed. */
82+
UV_READABLE = 0x20, /* The stream is readable */
83+
UV_WRITABLE = 0x40, /* The stream is writable */
84+
UV_TCP_NODELAY = 0x080, /* Disable Nagle. */
85+
UV_TCP_KEEPALIVE = 0x100 /* Turn on keep-alive. */
8486
};
8587

8688
size_t uv__strlcpy(char* dst, const char* src, size_t size);
@@ -111,6 +113,8 @@ int uv__connect(uv_connect_t* req, uv_stream_t* stream, struct sockaddr* addr,
111113

112114
/* tcp */
113115
int uv_tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb);
116+
int uv__tcp_nodelay(uv_tcp_t* handle, int enable);
117+
int uv__tcp_keepalive(uv_tcp_t* handle, int enable, unsigned int delay);
114118

115119
/* pipe */
116120
int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb);

deps/uv/src/unix/stream.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,24 @@ int uv__stream_open(uv_stream_t* stream, int fd, int flags) {
8686

8787
stream->flags |= flags;
8888

89-
/* Reuse the port address if applicable. */
90-
yes = 1;
91-
if (stream->type == UV_TCP
92-
&& setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1) {
93-
uv__set_sys_error(stream->loop, errno);
94-
return -1;
89+
if (stream->type == UV_TCP) {
90+
/* Reuse the port address if applicable. */
91+
yes = 1;
92+
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof yes) == -1) {
93+
uv__set_sys_error(stream->loop, errno);
94+
return -1;
95+
}
96+
97+
if ((stream->flags & UV_TCP_NODELAY) &&
98+
uv__tcp_nodelay((uv_tcp_t*)stream, 1)) {
99+
return -1;
100+
}
101+
102+
/* TODO Use delay the user passed in. */
103+
if ((stream->flags & UV_TCP_KEEPALIVE) &&
104+
uv__tcp_keepalive((uv_tcp_t*)stream, 1, 60)) {
105+
return -1;
106+
}
95107
}
96108

97109
/* Associate the fd with each ev_io watcher. */

deps/uv/src/unix/tcp.c

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,82 @@ int uv__tcp_connect6(uv_connect_t* req,
240240
errno = saved_errno;
241241
return status;
242242
}
243+
244+
245+
int uv__tcp_nodelay(uv_tcp_t* handle, int enable) {
246+
if (setsockopt(handle->fd,
247+
IPPROTO_TCP,
248+
TCP_NODELAY,
249+
&enable,
250+
sizeof enable) == -1) {
251+
uv__set_sys_error(handle->loop, errno);
252+
return -1;
253+
}
254+
return 0;
255+
}
256+
257+
258+
int uv__tcp_keepalive(uv_tcp_t* handle, int enable, unsigned int delay) {
259+
if (setsockopt(handle->fd,
260+
SOL_SOCKET,
261+
SO_KEEPALIVE,
262+
&enable,
263+
sizeof enable) == -1) {
264+
uv__set_sys_error(handle->loop, errno);
265+
return -1;
266+
}
267+
268+
#ifdef TCP_KEEPIDLE
269+
if (enable && setsockopt(handle->fd,
270+
IPPROTO_TCP,
271+
TCP_KEEPIDLE,
272+
&delay,
273+
sizeof delay) == -1) {
274+
uv__set_sys_error(handle->loop, errno);
275+
return -1;
276+
}
277+
#endif
278+
279+
#ifdef TCP_KEEPALIVE
280+
if (enable && setsockopt(handle->fd,
281+
IPPROTO_TCP,
282+
TCP_KEEPALIVE,
283+
&delay,
284+
sizeof delay) == -1) {
285+
uv__set_sys_error(handle->loop, errno);
286+
return -1;
287+
}
288+
#endif
289+
290+
return 0;
291+
}
292+
293+
294+
int uv_tcp_nodelay(uv_tcp_t* handle, int enable) {
295+
if (handle->fd != -1 && uv__tcp_nodelay(handle, enable))
296+
return -1;
297+
298+
if (enable)
299+
handle->flags |= UV_TCP_NODELAY;
300+
else
301+
handle->flags &= ~UV_TCP_NODELAY;
302+
303+
return 0;
304+
}
305+
306+
307+
int uv_tcp_keepalive(uv_tcp_t* handle, int enable, unsigned int delay) {
308+
if (handle->fd != -1 && uv__tcp_keepalive(handle, enable, delay))
309+
return -1;
310+
311+
if (enable)
312+
handle->flags |= UV_TCP_KEEPALIVE;
313+
else
314+
handle->flags &= ~UV_TCP_KEEPALIVE;
315+
316+
/* TODO Store delay if handle->fd == -1 but don't want to enlarge
317+
* uv_tcp_t with an int that's almost never used...
318+
*/
319+
320+
return 0;
321+
}

deps/uv/src/win/tcp.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,3 +956,15 @@ int uv_tcp_import(uv_tcp_t* tcp, WSAPROTOCOL_INFOW* socket_protocol_info) {
956956

957957
return uv_tcp_set_socket(tcp->loop, tcp, socket, 1);
958958
}
959+
960+
961+
int uv_tcp_nodelay(uv_tcp_t* handle, int enable) {
962+
uv__set_artificial_error(handle->loop, UV_ENOSYS);
963+
return -1;
964+
}
965+
966+
967+
int uv_tcp_keepalive(uv_tcp_t* handle, int enable, int delay) {
968+
uv__set_artificial_error(handle->loop, UV_ENOSYS);
969+
return -1;
970+
}

deps/uv/test/test-list.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ TEST_DECLARE (tcp_bind_error_inval)
3737
TEST_DECLARE (tcp_bind_localhost_ok)
3838
TEST_DECLARE (tcp_listen_without_bind)
3939
TEST_DECLARE (tcp_close)
40+
TEST_DECLARE (tcp_flags)
4041
TEST_DECLARE (tcp_write_error)
4142
TEST_DECLARE (tcp_bind6_error_addrinuse)
4243
TEST_DECLARE (tcp_bind6_error_addrnotavail)
@@ -149,6 +150,7 @@ TASK_LIST_START
149150
TEST_ENTRY (tcp_bind_localhost_ok)
150151
TEST_ENTRY (tcp_listen_without_bind)
151152
TEST_ENTRY (tcp_close)
153+
TEST_ENTRY (tcp_flags)
152154
TEST_ENTRY (tcp_write_error)
153155

154156
TEST_ENTRY (tcp_bind6_error_addrinuse)

deps/uv/test/test-tcp-flags.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
2+
*
3+
* Permission is hereby granted, free of charge, to any person obtaining a copy
4+
* of this software and associated documentation files (the "Software"), to
5+
* deal in the Software without restriction, including without limitation the
6+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7+
* sell copies of the Software, and to permit persons to whom the Software is
8+
* furnished to do so, subject to the following conditions:
9+
*
10+
* The above copyright notice and this permission notice shall be included in
11+
* all copies or substantial portions of the Software.
12+
*
13+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19+
* IN THE SOFTWARE.
20+
*/
21+
22+
#include "uv.h"
23+
#include "task.h"
24+
25+
#include <stdio.h>
26+
#include <stdlib.h>
27+
28+
29+
TEST_IMPL(tcp_flags) {
30+
uv_loop_t* loop;
31+
uv_tcp_t handle;
32+
int r;
33+
34+
loop = uv_default_loop();
35+
36+
r = uv_tcp_init(loop, &handle);
37+
ASSERT(r == 0);
38+
39+
r = uv_tcp_nodelay(&handle, 1);
40+
ASSERT(r == 0);
41+
42+
r = uv_tcp_keepalive(&handle, 1, 60);
43+
ASSERT(r == 0);
44+
45+
uv_close((uv_handle_t*)&handle, NULL);
46+
47+
r = uv_run(loop);
48+
ASSERT(r == 0);
49+
50+
return 0;
51+
}

deps/uv/uv.gyp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@
290290
'test/test-tcp-bind-error.c',
291291
'test/test-tcp-bind6-error.c',
292292
'test/test-tcp-close.c',
293+
'test/test-tcp-flags.c',
293294
'test/test-tcp-connect-error.c',
294295
'test/test-tcp-connect6-error.c',
295296
'test/test-tcp-write-error.c',

0 commit comments

Comments
 (0)