summaryrefslogtreecommitdiff
path: root/async.c
diff options
context:
space:
mode:
authorOmriSteiner <51128928+OmriSteiner@users.noreply.github.com>2020-06-22 23:20:30 +0300
committerGitHub <noreply@github.com>2020-06-22 13:20:30 -0700
commit392de5d7f97353485df1237872cb682842e8d83f (patch)
treea45994c209909167bdb09e54cba8c733abb95930 /async.c
parenta28de70a0196275317642eb60f8387a2ee950330 (diff)
fix #785: defer TCP_NODELAY in async tcp connections (#836)
Co-authored-by: Omri Steiner <omri@insoundz.com>
Diffstat (limited to 'async.c')
-rw-r--r--async.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/async.c b/async.c
index 261fe24..2cff0b1 100644
--- a/async.c
+++ b/async.c
@@ -539,20 +539,31 @@ void redisProcessCallbacks(redisAsyncContext *ac) {
__redisAsyncDisconnect(ac);
}
+static void __redisAsyncHandleConnectFailure(redisAsyncContext *ac) {
+ if (ac->onConnect) ac->onConnect(ac, REDIS_ERR);
+ __redisAsyncDisconnect(ac);
+}
+
/* Internal helper function to detect socket status the first time a read or
* 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 (redisCheckConnectDone(c, &completed) == REDIS_ERR) {
/* Error! */
redisCheckSocketError(c);
- if (ac->onConnect) ac->onConnect(ac, REDIS_ERR);
- __redisAsyncDisconnect(ac);
+ __redisAsyncHandleConnectFailure(ac);
return REDIS_ERR;
} else if (completed == 1) {
/* connected! */
+ if (c->connection_type == REDIS_CONN_TCP &&
+ redisSetTcpNoDelay(c) == REDIS_ERR) {
+ __redisAsyncHandleConnectFailure(ac);
+ return REDIS_ERR;
+ }
+
if (ac->onConnect) ac->onConnect(ac, REDIS_OK);
c->flags |= REDIS_CONNECTED;
return REDIS_OK;