unix: fix errno and retval conflict

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.

PR-URL: https://github.com/libuv/libuv/pull/936
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Imran Iqbal <imran@imraniqbal.org>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
This commit is contained in:
liuxiaobo 2016-07-04 17:08:46 +08:00 committed by Saúl Ibarra Corretgé
parent 00dab91ce5
commit 3a4f2d3155

View File

@ -158,11 +158,17 @@ int uv__tcp_connect(uv_connect_t* req,
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)