summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormichael-grunder <michael.grunder@gmail.com>2020-12-18 09:26:36 -0800
committermichael-grunder <michael.grunder@gmail.com>2021-04-02 09:34:09 -0700
commitdfa33e60b07c13328133a16065d88d171a2a61d4 (patch)
tree7d3c9d596e8fceedb0263a46e2495614a153293b
parent6204182aae71ca321418c069eac907936eeaa33a (diff)
Change order independant push logic to not change behavior.
Since redisGetReplyFromReader is exposed in a header file, we probably shouldn't modify how it behaves in any way. For this reason, handle the changed logic in an internal static helper method.
-rw-r--r--hiredis.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/hiredis.c b/hiredis.c
index f23ff45..5825174 100644
--- a/hiredis.c
+++ b/hiredis.c
@@ -1005,14 +1005,23 @@ static int redisHandledPushReply(redisContext *c, void *reply) {
return 0;
}
-/* Internal helper function to try and get a reply from the reader,
- * or set an error in the context otherwise. */
+/* Get a reply from our reader or set an error in the context. */
int redisGetReplyFromReader(redisContext *c, void **reply) {
+ if (redisReaderGetReply(c->reader, reply) == REDIS_ERR) {
+ __redisSetError(c,c->reader->err,c->reader->errstr);
+ return REDIS_ERR;
+ }
+
+ return REDIS_OK;
+}
+
+/* Internal helper to get the next reply from our reader while handling
+ * any PUSH messages we encounter along the way. This is separate from
+ * redisGetReplyFromReader so as to not change its behavior. */
+static int redisNextInBandReplyFromReader(redisContext *c, void **reply) {
do {
- if (redisReaderGetReply(c->reader,reply) == REDIS_ERR) {
- __redisSetError(c,c->reader->err,c->reader->errstr);
+ if (redisGetReplyFromReader(c, reply) == REDIS_ERR)
return REDIS_ERR;
- }
} while (redisHandledPushReply(c, *reply));
return REDIS_OK;
@@ -1023,7 +1032,7 @@ int redisGetReply(redisContext *c, void **reply) {
void *aux = NULL;
/* Try to read pending replies */
- if (redisGetReplyFromReader(c,&aux) == REDIS_ERR)
+ if (redisNextInBandReplyFromReader(c,&aux) == REDIS_ERR)
return REDIS_ERR;
/* For the blocking context, flush output buffer and read reply */
@@ -1039,7 +1048,7 @@ int redisGetReply(redisContext *c, void **reply) {
if (redisBufferRead(c) == REDIS_ERR)
return REDIS_ERR;
- if (redisGetReplyFromReader(c,&aux) == REDIS_ERR)
+ if (redisNextInBandReplyFromReader(c,&aux) == REDIS_ERR)
return REDIS_ERR;
} while (aux == NULL);
}