Co-authored-by: Omri Steiner <omri@insoundz.com>
This commit is contained in:
parent
a28de70a01
commit
392de5d7f9
15
async.c
15
async.c
@ -539,20 +539,31 @@ void redisProcessCallbacks(redisAsyncContext *ac) {
|
|||||||
__redisAsyncDisconnect(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
|
/* Internal helper function to detect socket status the first time a read or
|
||||||
* write event fires. When connecting was not successful, the connect callback
|
* write event fires. When connecting was not successful, the connect callback
|
||||||
* is called with a REDIS_ERR status and the context is free'd. */
|
* is called with a REDIS_ERR status and the context is free'd. */
|
||||||
static int __redisAsyncHandleConnect(redisAsyncContext *ac) {
|
static int __redisAsyncHandleConnect(redisAsyncContext *ac) {
|
||||||
int completed = 0;
|
int completed = 0;
|
||||||
redisContext *c = &(ac->c);
|
redisContext *c = &(ac->c);
|
||||||
|
|
||||||
if (redisCheckConnectDone(c, &completed) == REDIS_ERR) {
|
if (redisCheckConnectDone(c, &completed) == REDIS_ERR) {
|
||||||
/* Error! */
|
/* Error! */
|
||||||
redisCheckSocketError(c);
|
redisCheckSocketError(c);
|
||||||
if (ac->onConnect) ac->onConnect(ac, REDIS_ERR);
|
__redisAsyncHandleConnectFailure(ac);
|
||||||
__redisAsyncDisconnect(ac);
|
|
||||||
return REDIS_ERR;
|
return REDIS_ERR;
|
||||||
} else if (completed == 1) {
|
} else if (completed == 1) {
|
||||||
/* connected! */
|
/* 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);
|
if (ac->onConnect) ac->onConnect(ac, REDIS_OK);
|
||||||
c->flags |= REDIS_CONNECTED;
|
c->flags |= REDIS_CONNECTED;
|
||||||
return REDIS_OK;
|
return REDIS_OK;
|
||||||
|
6
net.c
6
net.c
@ -203,7 +203,7 @@ int redisKeepAlive(redisContext *c, int interval) {
|
|||||||
return REDIS_OK;
|
return REDIS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int redisSetTcpNoDelay(redisContext *c) {
|
int redisSetTcpNoDelay(redisContext *c) {
|
||||||
int yes = 1;
|
int yes = 1;
|
||||||
if (setsockopt(c->fd, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes)) == -1) {
|
if (setsockopt(c->fd, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes)) == -1) {
|
||||||
__redisSetErrorFromErrno(c,REDIS_ERR_IO,"setsockopt(TCP_NODELAY)");
|
__redisSetErrorFromErrno(c,REDIS_ERR_IO,"setsockopt(TCP_NODELAY)");
|
||||||
@ -487,12 +487,12 @@ addrretry:
|
|||||||
wait_for_ready:
|
wait_for_ready:
|
||||||
if (redisContextWaitReady(c,timeout_msec) != REDIS_OK)
|
if (redisContextWaitReady(c,timeout_msec) != REDIS_OK)
|
||||||
goto error;
|
goto error;
|
||||||
|
if (redisSetTcpNoDelay(c) != REDIS_OK)
|
||||||
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (blocking && redisSetBlocking(c,1) != REDIS_OK)
|
if (blocking && redisSetBlocking(c,1) != REDIS_OK)
|
||||||
goto error;
|
goto error;
|
||||||
if (redisSetTcpNoDelay(c) != REDIS_OK)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
c->flags |= REDIS_CONNECTED;
|
c->flags |= REDIS_CONNECTED;
|
||||||
rv = REDIS_OK;
|
rv = REDIS_OK;
|
||||||
|
2
net.h
2
net.h
@ -51,4 +51,6 @@ int redisContextConnectUnix(redisContext *c, const char *path, const struct time
|
|||||||
int redisKeepAlive(redisContext *c, int interval);
|
int redisKeepAlive(redisContext *c, int interval);
|
||||||
int redisCheckConnectDone(redisContext *c, int *completed);
|
int redisCheckConnectDone(redisContext *c, int *completed);
|
||||||
|
|
||||||
|
int redisSetTcpNoDelay(redisContext *c);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user