Skip to content

Commit 7e5aeac

Browse files
committed
deps: upgrade libuv to 3b8c0da
1 parent b9abb64 commit 7e5aeac

File tree

7 files changed

+233
-145
lines changed

7 files changed

+233
-145
lines changed

deps/uv/src/unix/internal.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ enum {
9393
UV_STREAM_WRITABLE = 0x40, /* The stream is writable */
9494
UV_STREAM_BLOCKING = 0x80, /* Synchronous writes. */
9595
UV_TCP_NODELAY = 0x100, /* Disable Nagle. */
96-
UV_TCP_KEEPALIVE = 0x200 /* Turn on keep-alive. */
96+
UV_TCP_KEEPALIVE = 0x200, /* Turn on keep-alive. */
97+
UV_TCP_CONNECTING = 0x400 /* Not alway set. See uv_connect() in tcp.c */
9798
};
9899

99100
inline static void uv__req_init(uv_loop_t* loop,
@@ -139,8 +140,6 @@ int uv__stream_open(uv_stream_t*, int fd, int flags);
139140
void uv__stream_destroy(uv_stream_t* stream);
140141
void uv__server_io(uv_loop_t* loop, uv__io_t* watcher, int events);
141142
int uv__accept(int sockfd);
142-
int uv__connect(uv_connect_t* req, uv_stream_t* stream, struct sockaddr* addr,
143-
socklen_t addrlen, uv_connect_cb cb);
144143

145144
/* tcp */
146145
int uv_tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb);

deps/uv/src/unix/stream.c

Lines changed: 6 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -784,78 +784,22 @@ static void uv__stream_connect(uv_stream_t* stream) {
784784
if (error == EINPROGRESS)
785785
return;
786786

787-
if (error == 0)
788-
uv__io_start(stream->loop, &stream->read_watcher);
789-
790787
stream->connect_req = NULL;
791788
uv__req_unregister(stream->loop, req);
792789

790+
/* Hack. See uv__connect() in tcp.c */
791+
if (stream->flags & UV_TCP_CONNECTING) {
792+
assert(stream->type == UV_TCP);
793+
uv__handle_stop(stream);
794+
}
795+
793796
if (req->cb) {
794797
uv__set_sys_error(stream->loop, error);
795798
req->cb(req, error ? -1 : 0);
796799
}
797800
}
798801

799802

800-
int uv__connect(uv_connect_t* req, uv_stream_t* stream, struct sockaddr* addr,
801-
socklen_t addrlen, uv_connect_cb cb) {
802-
int sockfd;
803-
int r;
804-
805-
if (stream->type != UV_TCP)
806-
return uv__set_sys_error(stream->loop, ENOTSOCK);
807-
808-
if (stream->connect_req)
809-
return uv__set_sys_error(stream->loop, EALREADY);
810-
811-
if (stream->fd <= 0) {
812-
sockfd = uv__socket(addr->sa_family, SOCK_STREAM, 0);
813-
814-
if (sockfd == -1)
815-
return uv__set_sys_error(stream->loop, errno);
816-
817-
if (uv__stream_open(stream,
818-
sockfd,
819-
UV_STREAM_READABLE | UV_STREAM_WRITABLE)) {
820-
close(sockfd);
821-
return -1;
822-
}
823-
}
824-
825-
stream->delayed_error = 0;
826-
827-
do
828-
r = connect(stream->fd, addr, addrlen);
829-
while (r == -1 && errno == EINTR);
830-
831-
if (r == -1) {
832-
if (errno == EINPROGRESS)
833-
; /* not an error */
834-
else if (errno == ECONNREFUSED)
835-
/* If we get a ECONNREFUSED wait until the next tick to report the
836-
* error. Solaris wants to report immediately--other unixes want to
837-
* wait.
838-
*/
839-
stream->delayed_error = errno;
840-
else
841-
return uv__set_sys_error(stream->loop, errno);
842-
}
843-
844-
uv__req_init(stream->loop, req, UV_CONNECT);
845-
req->cb = cb;
846-
req->handle = stream;
847-
ngx_queue_init(&req->queue);
848-
stream->connect_req = req;
849-
850-
uv__io_start(stream->loop, &stream->write_watcher);
851-
852-
if (stream->delayed_error)
853-
uv__io_feed(stream->loop, &stream->write_watcher, UV__IO_WRITE);
854-
855-
return 0;
856-
}
857-
858-
859803
int uv_write2(uv_write_t* req, uv_stream_t* stream, uv_buf_t bufs[], int bufcnt,
860804
uv_stream_t* send_handle, uv_write_cb cb) {
861805
int empty_queue;

deps/uv/src/unix/tcp.c

Lines changed: 102 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,26 @@ int uv_tcp_init(uv_loop_t* loop, uv_tcp_t* tcp) {
3434
}
3535

3636

37+
static int maybe_new_socket(uv_tcp_t* handle, int domain, int flags) {
38+
int sockfd;
39+
40+
if (handle->fd != -1)
41+
return 0;
42+
43+
sockfd = uv__socket(domain, SOCK_STREAM, 0);
44+
45+
if (sockfd == -1)
46+
return uv__set_sys_error(handle->loop, errno);
47+
48+
if (uv__stream_open((uv_stream_t*)handle, sockfd, flags)) {
49+
close(sockfd);
50+
return -1;
51+
}
52+
53+
return 0;
54+
}
55+
56+
3757
static int uv__bind(uv_tcp_t* tcp,
3858
int domain,
3959
struct sockaddr* addr,
@@ -44,23 +64,8 @@ static int uv__bind(uv_tcp_t* tcp,
4464
saved_errno = errno;
4565
status = -1;
4666

47-
if (tcp->fd < 0) {
48-
if ((tcp->fd = uv__socket(domain, SOCK_STREAM, 0)) == -1) {
49-
uv__set_sys_error(tcp->loop, errno);
50-
goto out;
51-
}
52-
53-
if (uv__stream_open((uv_stream_t*)tcp,
54-
tcp->fd,
55-
UV_STREAM_READABLE | UV_STREAM_WRITABLE)) {
56-
close(tcp->fd);
57-
tcp->fd = -1;
58-
status = -2;
59-
goto out;
60-
}
61-
}
62-
63-
assert(tcp->fd >= 0);
67+
if (maybe_new_socket(tcp, domain, UV_STREAM_READABLE|UV_STREAM_WRITABLE))
68+
return -1;
6469

6570
tcp->delayed_error = 0;
6671
if (bind(tcp->fd, addr, addrsize) == -1) {
@@ -79,6 +84,67 @@ static int uv__bind(uv_tcp_t* tcp,
7984
}
8085

8186

87+
static int uv__connect(uv_connect_t* req,
88+
uv_tcp_t* handle,
89+
struct sockaddr* addr,
90+
socklen_t addrlen,
91+
uv_connect_cb cb) {
92+
int r;
93+
94+
assert(handle->type == UV_TCP);
95+
96+
if (handle->connect_req)
97+
return uv__set_sys_error(handle->loop, EALREADY);
98+
99+
if (maybe_new_socket(handle,
100+
addr->sa_family,
101+
UV_STREAM_READABLE|UV_STREAM_WRITABLE)) {
102+
return -1;
103+
}
104+
105+
handle->delayed_error = 0;
106+
107+
do
108+
r = connect(handle->fd, addr, addrlen);
109+
while (r == -1 && errno == EINTR);
110+
111+
if (r == -1) {
112+
if (errno == EINPROGRESS) {
113+
/* Not an error. However, we need to keep the event loop from spinning
114+
* while the connection is in progress. Artificially start the handle
115+
* and stop it again in uv__stream_connect() in stream.c. Yes, it's a
116+
* hack but there's no good alternative, the v0.8 ABI is frozen.
117+
*/
118+
if (!uv__is_active(handle)) {
119+
handle->flags |= UV_TCP_CONNECTING;
120+
uv__handle_start(handle);
121+
}
122+
}
123+
else if (errno == ECONNREFUSED)
124+
/* If we get a ECONNREFUSED wait until the next tick to report the
125+
* error. Solaris wants to report immediately--other unixes want to
126+
* wait.
127+
*/
128+
handle->delayed_error = errno;
129+
else
130+
return uv__set_sys_error(handle->loop, errno);
131+
}
132+
133+
uv__req_init(handle->loop, req, UV_CONNECT);
134+
req->cb = cb;
135+
req->handle = (uv_stream_t*) handle;
136+
ngx_queue_init(&req->queue);
137+
handle->connect_req = req;
138+
139+
uv__io_start(handle->loop, &handle->write_watcher);
140+
141+
if (handle->delayed_error)
142+
uv__io_feed(handle->loop, &handle->write_watcher, UV__IO_WRITE);
143+
144+
return 0;
145+
}
146+
147+
82148
int uv__tcp_bind(uv_tcp_t* handle, struct sockaddr_in addr) {
83149
return uv__bind(handle,
84150
AF_INET,
@@ -170,33 +236,14 @@ int uv_tcp_getpeername(uv_tcp_t* handle, struct sockaddr* name,
170236

171237

172238
int uv_tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb) {
173-
int r;
239+
if (tcp->delayed_error)
240+
return uv__set_sys_error(tcp->loop, tcp->delayed_error);
174241

175-
if (tcp->delayed_error) {
176-
uv__set_sys_error(tcp->loop, tcp->delayed_error);
242+
if (maybe_new_socket(tcp, AF_INET, UV_STREAM_READABLE))
177243
return -1;
178-
}
179-
180-
if (tcp->fd < 0) {
181-
if ((tcp->fd = uv__socket(AF_INET, SOCK_STREAM, 0)) == -1) {
182-
uv__set_sys_error(tcp->loop, errno);
183-
return -1;
184-
}
185-
186-
if (uv__stream_open((uv_stream_t*)tcp, tcp->fd, UV_STREAM_READABLE)) {
187-
close(tcp->fd);
188-
tcp->fd = -1;
189-
return -1;
190-
}
191-
}
192244

193-
assert(tcp->fd >= 0);
194-
195-
r = listen(tcp->fd, backlog);
196-
if (r < 0) {
197-
uv__set_sys_error(tcp->loop, errno);
198-
return -1;
199-
}
245+
if (listen(tcp->fd, backlog))
246+
return uv__set_sys_error(tcp->loop, errno);
200247

201248
tcp->connection_cb = cb;
202249

@@ -209,37 +256,31 @@ int uv_tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb) {
209256

210257

211258
int uv__tcp_connect(uv_connect_t* req,
212-
uv_tcp_t* handle,
213-
struct sockaddr_in address,
214-
uv_connect_cb cb) {
215-
int saved_errno = errno;
259+
uv_tcp_t* handle,
260+
struct sockaddr_in addr,
261+
uv_connect_cb cb) {
262+
int saved_errno;
216263
int status;
217264

218-
status = uv__connect(req,
219-
(uv_stream_t*)handle,
220-
(struct sockaddr*)&address,
221-
sizeof address,
222-
cb);
223-
265+
saved_errno = errno;
266+
status = uv__connect(req, handle, (struct sockaddr*)&addr, sizeof addr, cb);
224267
errno = saved_errno;
268+
225269
return status;
226270
}
227271

228272

229273
int uv__tcp_connect6(uv_connect_t* req,
230-
uv_tcp_t* handle,
231-
struct sockaddr_in6 address,
232-
uv_connect_cb cb) {
233-
int saved_errno = errno;
274+
uv_tcp_t* handle,
275+
struct sockaddr_in6 addr,
276+
uv_connect_cb cb) {
277+
int saved_errno;
234278
int status;
235279

236-
status = uv__connect(req,
237-
(uv_stream_t*)handle,
238-
(struct sockaddr*)&address,
239-
sizeof address,
240-
cb);
241-
280+
saved_errno = errno;
281+
status = uv__connect(req, handle, (struct sockaddr*)&addr, sizeof addr, cb);
242282
errno = saved_errno;
283+
243284
return status;
244285
}
245286

deps/uv/test/test-gethostbyname.c

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
#include <string.h> /* strlen */
2828

2929
static ares_channel channel;
30-
static struct ares_options options;
31-
static int optmask;
3230

3331
static int ares_bynamecallbacks;
3432
static int bynamecallbacksig;
@@ -63,19 +61,12 @@ static void aresbyaddrcallback( void *arg,
6361
}
6462

6563

66-
static void prep_tcploopback() {
67-
/* for test, use echo server - TCP port TEST_PORT on loopback */
68-
struct sockaddr_in test_server = uv_ip4_addr("127.0.0.1", 0);
69-
int rc;
70-
71-
optmask = ARES_OPT_SERVERS | ARES_OPT_TCP_PORT | ARES_OPT_FLAGS;
72-
options.servers = &test_server.sin_addr;
73-
options.nservers = 1;
74-
options.tcp_port = htons(TEST_PORT);
75-
options.flags = ARES_FLAG_USEVC;
76-
77-
rc = uv_ares_init_options(uv_default_loop(), &channel, &options, optmask);
78-
ASSERT(rc == ARES_SUCCESS);
64+
static void setup_cares() {
65+
int r;
66+
struct ares_options options;
67+
memset(&options, 0, sizeof options);
68+
r = uv_ares_init_options(uv_default_loop(), &channel, &options, 0);
69+
ASSERT(r == ARES_SUCCESS);
7970
}
8071

8172

@@ -91,7 +82,7 @@ TEST_IMPL(gethostbyname) {
9182
}
9283

9384
printf("Start basic gethostbyname test\n");
94-
prep_tcploopback();
85+
setup_cares();
9586

9687
ares_bynamecallbacks = 0;
9788
bynamecallbacksig = 7;
@@ -112,7 +103,7 @@ TEST_IMPL(gethostbyname) {
112103
/* two sequential call on new channel */
113104

114105
printf("Start gethostbyname and gethostbyaddr sequential test\n");
115-
prep_tcploopback();
106+
setup_cares();
116107

117108
ares_bynamecallbacks = 0;
118109
bynamecallbacksig = 7;
@@ -151,7 +142,7 @@ TEST_IMPL(gethostbyname) {
151142
/* two simultaneous calls on new channel */
152143

153144
printf("Start gethostbyname and gethostbyaddr concurrent test\n");
154-
prep_tcploopback();
145+
setup_cares();
155146

156147
ares_bynamecallbacks = 0;
157148
bynamecallbacksig = 7;

0 commit comments

Comments
 (0)