Make setError receive an sds

This commit is contained in:
Pieter Noordhuis 2010-11-02 17:14:03 +01:00
parent b8b296654d
commit e51ddd7c2c
2 changed files with 7 additions and 6 deletions

View File

@ -614,10 +614,10 @@ int redisFormatCommandArgv(char **target, int argc, const char **argv, const siz
return totlen; return totlen;
} }
void __redisSetError(redisContext *c, int type, const char *str) { void __redisSetError(redisContext *c, int type, const sds errstr) {
c->err = type; c->err = type;
if (str) { if (errstr != NULL) {
c->errstr = sdsnew(str); c->errstr = errstr;
} else { } else {
/* Only REDIS_ERR_IO may lack a description! */ /* Only REDIS_ERR_IO may lack a description! */
assert(type == REDIS_ERR_IO); assert(type == REDIS_ERR_IO);
@ -700,7 +700,7 @@ int redisBufferRead(redisContext *c) {
} }
} else if (nread == 0) { } else if (nread == 0) {
__redisSetError(c,REDIS_ERR_EOF, __redisSetError(c,REDIS_ERR_EOF,
"Server closed the connection"); sdsnew("Server closed the connection"));
return REDIS_ERR; return REDIS_ERR;
} else { } else {
__redisCreateReplyReader(c); __redisCreateReplyReader(c);
@ -747,7 +747,8 @@ int redisBufferWrite(redisContext *c, int *done) {
static int __redisGetReply(redisContext *c, void **reply) { static int __redisGetReply(redisContext *c, void **reply) {
__redisCreateReplyReader(c); __redisCreateReplyReader(c);
if (redisReplyReaderGetReply(c->reader,reply) == REDIS_ERR) { if (redisReplyReaderGetReply(c->reader,reply) == REDIS_ERR) {
__redisSetError(c,REDIS_ERR_PROTOCOL,((redisReader*)c->reader)->error); __redisSetError(c,REDIS_ERR_PROTOCOL,
sdsnew(((redisReader*)c->reader)->error));
return REDIS_ERR; return REDIS_ERR;
} }
return REDIS_OK; return REDIS_OK;

2
net.c
View File

@ -46,7 +46,7 @@
#include "sds.h" #include "sds.h"
/* Forward declaration */ /* Forward declaration */
void __redisSetError(redisContext *c, int type, const char *err); void __redisSetError(redisContext *c, int type, sds err);
static int redisSetNonBlock(redisContext *c, int fd) { static int redisSetNonBlock(redisContext *c, int fd) {
int flags; int flags;