From b1fa529cf973247ba79f23b1b5c9249582fc1bfe Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Mon, 20 Sep 2010 15:26:18 +0200 Subject: [PATCH] Add function to check if the reply reader is empty --- hiredis.c | 9 +++++++++ hiredis.h | 1 + 2 files changed, 10 insertions(+) diff --git a/hiredis.c b/hiredis.c index 664cc44..0b7a17e 100644 --- a/hiredis.c +++ b/hiredis.c @@ -326,6 +326,15 @@ void redisFreeReplyReader(void *reader) { free(r); } +int redisIsReplyReaderEmpty(void *reader) { + redisReader *r = reader; + if (r->buf != NULL && sdslen(r->buf) > 0) + return 0; + if (r->rlist != NULL && r->rpos < r->rlen) + return 0; + return 1; +} + static void redisSetReplyReaderError(redisReader *r, redisReply *error) { /* Clear remaining buffer when we see a protocol error. */ if (r->buf != NULL) { diff --git a/hiredis.h b/hiredis.h index 85fc540..482072e 100644 --- a/hiredis.h +++ b/hiredis.h @@ -54,6 +54,7 @@ void freeReplyObject(redisReply *r); redisReply *redisCommand(int fd, const char *format, ...); void *redisCreateReplyReader(); void redisFreeReplyReader(void *ptr); +int redisIsReplyReaderEmpty(void *ptr); void *redisFeedReplyReader(void *reader, char *buf, int len); #endif