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;
}
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. */
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. */
#include <sys/time.h>
#include <assert.h>
#include <unistd.h>
+#include <signal.h>
#include "hiredis.h"
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() {