ext/libuv/src/unix/tcp.c in libuv-2.0.8 vs ext/libuv/src/unix/tcp.c in libuv-2.0.9
- old
+ new
@@ -156,15 +156,21 @@
if (err)
return err;
handle->delayed_error = 0;
- do
+ do {
+ errno = 0;
r = connect(uv__stream_fd(handle), addr, addrlen);
- while (r == -1 && errno == EINTR);
+ } while (r == -1 && errno == EINTR);
- if (r == -1) {
+ /* We not only check the return value, but also check the errno != 0.
+ * Because in rare cases connect() will return -1 but the errno
+ * is 0 (for example, on Android 4.3, OnePlus phone A0001_12_150227)
+ * and actually the tcp three-way handshake is completed.
+ */
+ if (r == -1 && errno != 0) {
if (errno == EINPROGRESS)
; /* not an error */
else if (errno == ECONNREFUSED)
/* If we get a ECONNREFUSED wait until the next tick to report the
* error. Solaris wants to report immediately--other unixes want to
@@ -179,11 +185,11 @@
req->cb = cb;
req->handle = (uv_stream_t*) handle;
QUEUE_INIT(&req->queue);
handle->connect_req = req;
- uv__io_start(handle->loop, &handle->io_watcher, UV__POLLOUT);
+ uv__io_start(handle->loop, &handle->io_watcher, POLLOUT);
if (handle->delayed_error)
uv__io_feed(handle->loop, &handle->io_watcher);
return 0;
@@ -271,10 +277,10 @@
tcp->connection_cb = cb;
/* Start listening for connections. */
tcp->io_watcher.cb = uv__server_io;
- uv__io_start(tcp->loop, &tcp->io_watcher, UV__POLLIN);
+ uv__io_start(tcp->loop, &tcp->io_watcher, POLLIN);
return 0;
}