diff options
author | Michael Grunder <michael.grunder@gmail.com> | 2022-09-05 11:59:21 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-05 11:59:21 -0700 |
commit | 79ae5ffc693b57688b4c76141fd2c94868ebdbff (patch) | |
tree | 591fd768050a2270e46c7f5759d780d7b2a13d4a /net.c | |
parent | 61b5b299f0ac4f0efbe11a45716e06a9c35f37b7 (diff) |
Fix protocol error (#1106)
Fix ProtocolError
This commit attempts to fix hiredis such that a recoverable write error
will be retried rather than throwing a hard error.
Since our read/write functions are now behind function pointers, we
specify semantically that a return value of < 0 is a hard error, 0 a
recoverable error, and > 0 a success.
Our default `redisNetRead` function was already doing something similar
so this also improves code consistency.
Resolves #961
Co-authored-by: Maksim Tuleika <maksim.tuleika@appcast.io>
Diffstat (limited to 'net.c')
-rw-r--r-- | net.c | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -70,7 +70,7 @@ ssize_t redisNetRead(redisContext *c, char *buf, size_t bufcap) { __redisSetError(c, REDIS_ERR_TIMEOUT, "recv timeout"); return -1; } else { - __redisSetError(c, REDIS_ERR_IO, NULL); + __redisSetError(c, REDIS_ERR_IO, strerror(errno)); return -1; } } else if (nread == 0) { @@ -82,15 +82,19 @@ ssize_t redisNetRead(redisContext *c, char *buf, size_t bufcap) { } ssize_t redisNetWrite(redisContext *c) { - ssize_t nwritten = send(c->fd, c->obuf, sdslen(c->obuf), 0); + ssize_t nwritten; + + nwritten = send(c->fd, c->obuf, sdslen(c->obuf), 0); if (nwritten < 0) { if ((errno == EWOULDBLOCK && !(c->flags & REDIS_BLOCK)) || (errno == EINTR)) { - /* Try again later */ + /* Try again */ + return 0; } else { - __redisSetError(c, REDIS_ERR_IO, NULL); + __redisSetError(c, REDIS_ERR_IO, strerror(errno)); return -1; } } + return nwritten; } |