summaryrefslogtreecommitdiff
path: root/async.c
diff options
context:
space:
mode:
authorMark Nunberg <mnunberg@haskalah.org>2018-03-04 18:17:16 +0200
committerMark Nunberg <mnunberg@haskalah.org>2018-09-25 20:21:37 -0400
commit49974c9359ad6b58cea15106cf6511bdb31d31a9 (patch)
tree5cfbe5664581f331404fde52c5b169d5af2397dc /async.c
parent685030652cd98c5414ce554ff5b356dfe8437870 (diff)
Call connect(2) again for non-blocking connect
This retrieves the actual error which occurred, as getsockopt is not always reliable in this regard.
Diffstat (limited to 'async.c')
-rw-r--r--async.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/async.c b/async.c
index cb5b841..7309344 100644
--- a/async.c
+++ b/async.c
@@ -506,22 +506,22 @@ void redisProcessCallbacks(redisAsyncContext *ac) {
* write event fires. When connecting was not successful, the connect callback
* is called with a REDIS_ERR status and the context is free'd. */
static int __redisAsyncHandleConnect(redisAsyncContext *ac) {
+ int completed = 0;
redisContext *c = &(ac->c);
-
- if (redisCheckSocketError(c) == REDIS_ERR) {
- /* Try again later when connect(2) is still in progress. */
- if (errno == EINPROGRESS)
- return REDIS_OK;
-
- if (ac->onConnect) ac->onConnect(ac,REDIS_ERR);
+ if (redisFinishAsyncConnect(c, &completed) == REDIS_ERR) {
+ /* Error! */
+ redisCheckSocketError(c);
+ if (ac->onConnect) ac->onConnect(ac, REDIS_ERR);
__redisAsyncDisconnect(ac);
return REDIS_ERR;
+ } else if (completed == 1) {
+ /* connected! */
+ if (ac->onConnect) ac->onConnect(ac, REDIS_OK);
+ c->flags |= REDIS_CONNECTED;
+ return REDIS_OK;
+ } else {
+ return REDIS_OK;
}
-
- /* Mark context as connected. */
- c->flags |= REDIS_CONNECTED;
- if (ac->onConnect) ac->onConnect(ac,REDIS_OK);
- return REDIS_OK;
}
/* This function should be called when the socket is readable.