diff options
author | Pieter Noordhuis <pcnoordhuis@gmail.com> | 2010-11-04 23:52:47 +0100 |
---|---|---|
committer | Pieter Noordhuis <pcnoordhuis@gmail.com> | 2010-11-04 23:52:47 +0100 |
commit | 8ce0b3228dc4742b045cb471b145551d1afac337 (patch) | |
tree | bfcbcf93939751344790e9ae440d0077fe278e4c | |
parent | 8b616d3547dc8ba64182bf0fa1210de13e675a22 (diff) |
Finding \r\n without strstr is a little harder
-rw-r--r-- | hiredis.c | 11 | ||||
-rw-r--r-- | test.c | 11 |
2 files changed, 21 insertions, 1 deletions
@@ -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; } @@ -219,6 +219,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() { |