diff options
author | Mark Nunberg <mnunberg@haskalah.org> | 2018-03-05 12:17:49 +0200 |
---|---|---|
committer | Mark Nunberg <mnunberg@haskalah.org> | 2018-09-25 20:21:40 -0400 |
commit | cbe4ae63aecee40674509a2bf23bc5db067e7f3d (patch) | |
tree | 28e437188b572e9df2b5f58cf11245ce86cdbbc4 /net.c | |
parent | 5e6bbf8c6075ce6406d424e7ed031c7a6c676fb2 (diff) |
Handle connection errors better in blocking mode as well
Diffstat (limited to 'net.c')
-rw-r--r-- | net.c | 17 |
1 files changed, 13 insertions, 4 deletions
@@ -221,8 +221,10 @@ static int redisContextWaitReady(redisContext *c, long msec) { return REDIS_ERR; } - if (redisCheckSocketError(c) != REDIS_OK) + if (redisCheckConnectDone(c, &res) != REDIS_OK || res == 0) { + redisCheckSocketError(c); return REDIS_ERR; + } return REDIS_OK; } @@ -232,7 +234,7 @@ static int redisContextWaitReady(redisContext *c, long msec) { return REDIS_ERR; } -int redisFinishAsyncConnect(redisContext *c, int *completed) { +int redisCheckConnectDone(redisContext *c, int *completed) { int rc = connect(c->fd, (const struct sockaddr *)c->saddr, c->addrlen); if (rc == 0) { *completed = 1; @@ -410,8 +412,14 @@ addrretry: if (errno == EHOSTUNREACH) { redisContextCloseFd(c); continue; - } else if (errno == EINPROGRESS && !blocking) { - /* This is ok. */ + } else if (errno == EINPROGRESS) { + if (blocking) { + goto wait_for_ready; + } + /* This is ok. + * Note that even when it's in blocking mode, we unset blocking + * for `connect()` + */ } else if (errno == EADDRNOTAVAIL && reuseaddr) { if (++reuses >= REDIS_CONNECT_RETRIES) { goto error; @@ -420,6 +428,7 @@ addrretry: goto addrretry; } } else { + wait_for_ready: if (redisContextWaitReady(c,timeout_msec) != REDIS_OK) goto error; } |