Permalink
Browse files

Update hiredis

  • Loading branch information...
1 parent abc3ff4 commit 57c9babd819339544a8c7447a7cbae7e70f64678 @pietern pietern committed Nov 5, 2010
Showing with 24 additions and 3 deletions.
  1. +11 −2 deps/hiredis/hiredis.c
  2. +1 −1 deps/hiredis/hiredis.h
  3. +12 −0 deps/hiredis/test.c
View
@@ -164,8 +164,17 @@ static char *readBytes(redisReader *r, unsigned int bytes) {
static char *seekNewline(char *s) {
/* Find pointer to \r\n without strstr */
- while(s != NULL && s[0] != '\r' && s[1] != '\n')
+ while (s != NULL) {
s = strchr(s,'\r');
+ if (s != NULL) {
+ if (s[1] == '\n')
+ break;
+ else
+ s++;
+ } else {
+ break;
+ }
+ }
return s;
}
@@ -424,7 +433,7 @@ char *redisReplyReaderGetError(void *reader) {
return r->error;
}
-void redisReplyReaderFeed(void *reader, char *buf, int len) {
+void redisReplyReaderFeed(void *reader, char *buf, size_t len) {
redisReader *r = reader;
/* Copy the provided buffer. */
View
@@ -115,7 +115,7 @@ int redisReplyReaderSetReplyObjectFunctions(void *reader, redisReplyObjectFuncti
void *redisReplyReaderGetObject(void *reader);
char *redisReplyReaderGetError(void *reader);
void redisReplyReaderFree(void *ptr);
-void redisReplyReaderFeed(void *reader, char *buf, int len);
+void redisReplyReaderFeed(void *reader, char *buf, size_t len);
int redisReplyReaderGetReply(void *reader, void **reply);
/* Functions to format a command according to the protocol. */
View
@@ -5,6 +5,7 @@
#include <sys/time.h>
#include <assert.h>
#include <unistd.h>
+#include <signal.h>
#include "hiredis.h"
@@ -219,6 +220,17 @@ static void test_reply_reader() {
ret = redisReplyReaderGetReply(reader,&reply);
test_cond(ret == REDIS_OK && reply == (void*)REDIS_REPLY_STATUS);
redisReplyReaderFree(reader);
+
+ test("Works when a single newline (\\r\\n) covers two calls to feed: ");
+ reader = redisReplyReaderCreate();
+ redisReplyReaderSetReplyObjectFunctions(reader,NULL);
+ redisReplyReaderFeed(reader,(char*)"+OK\r",4);
+ ret = redisReplyReaderGetReply(reader,&reply);
+ assert(ret == REDIS_OK && reply == NULL);
+ redisReplyReaderFeed(reader,(char*)"\n",1);
+ ret = redisReplyReaderGetReply(reader,&reply);
+ test_cond(ret == REDIS_OK && reply == (void*)REDIS_REPLY_STATUS);
+ redisReplyReaderFree(reader);
}
static void test_throughput() {

0 comments on commit 57c9bab

Please sign in to comment.