提交 57c9babd 编写于 作者: P Pieter Noordhuis

Update hiredis

上级 abc3ff4d
...@@ -164,8 +164,17 @@ static char *readBytes(redisReader *r, unsigned int bytes) { ...@@ -164,8 +164,17 @@ static char *readBytes(redisReader *r, unsigned int bytes) {
static char *seekNewline(char *s) { static char *seekNewline(char *s) {
/* Find pointer to \r\n without strstr */ /* Find pointer to \r\n without strstr */
while(s != NULL && s[0] != '\r' && s[1] != '\n') while (s != NULL) {
s = strchr(s,'\r'); s = strchr(s,'\r');
if (s != NULL) {
if (s[1] == '\n')
break;
else
s++;
} else {
break;
}
}
return s; return s;
} }
...@@ -424,7 +433,7 @@ char *redisReplyReaderGetError(void *reader) { ...@@ -424,7 +433,7 @@ char *redisReplyReaderGetError(void *reader) {
return r->error; return r->error;
} }
void redisReplyReaderFeed(void *reader, char *buf, int len) { void redisReplyReaderFeed(void *reader, char *buf, size_t len) {
redisReader *r = reader; redisReader *r = reader;
/* Copy the provided buffer. */ /* Copy the provided buffer. */
......
...@@ -115,7 +115,7 @@ int redisReplyReaderSetReplyObjectFunctions(void *reader, redisReplyObjectFuncti ...@@ -115,7 +115,7 @@ int redisReplyReaderSetReplyObjectFunctions(void *reader, redisReplyObjectFuncti
void *redisReplyReaderGetObject(void *reader); void *redisReplyReaderGetObject(void *reader);
char *redisReplyReaderGetError(void *reader); char *redisReplyReaderGetError(void *reader);
void redisReplyReaderFree(void *ptr); 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); int redisReplyReaderGetReply(void *reader, void **reply);
/* Functions to format a command according to the protocol. */ /* Functions to format a command according to the protocol. */
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <sys/time.h> #include <sys/time.h>
#include <assert.h> #include <assert.h>
#include <unistd.h> #include <unistd.h>
#include <signal.h>
#include "hiredis.h" #include "hiredis.h"
...@@ -219,6 +220,17 @@ static void test_reply_reader() { ...@@ -219,6 +220,17 @@ static void test_reply_reader() {
ret = redisReplyReaderGetReply(reader,&reply); ret = redisReplyReaderGetReply(reader,&reply);
test_cond(ret == REDIS_OK && reply == (void*)REDIS_REPLY_STATUS); test_cond(ret == REDIS_OK && reply == (void*)REDIS_REPLY_STATUS);
redisReplyReaderFree(reader); 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() { static void test_throughput() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册