Commit e6d997a9 authored by Pieter Noordhuis's avatar Pieter Noordhuis
Browse files

Extract function to check a socket for errors

parent 026d5ae7
...@@ -117,8 +117,6 @@ static int redisContextWaitReady(redisContext *c, int fd, const struct timeval * ...@@ -117,8 +117,6 @@ static int redisContextWaitReady(redisContext *c, int fd, const struct timeval *
struct timeval to; struct timeval to;
struct timeval *toptr = NULL; struct timeval *toptr = NULL;
fd_set wfd; fd_set wfd;
int err;
socklen_t errlen;
/* Only use timeout when not NULL. */ /* Only use timeout when not NULL. */
if (timeout != NULL) { if (timeout != NULL) {
...@@ -143,8 +141,18 @@ static int redisContextWaitReady(redisContext *c, int fd, const struct timeval * ...@@ -143,8 +141,18 @@ static int redisContextWaitReady(redisContext *c, int fd, const struct timeval *
return REDIS_ERR; return REDIS_ERR;
} }
err = 0; return REDIS_OK;
errlen = sizeof(err); }
__redisSetErrorFromErrno(c,REDIS_ERR_IO,NULL);
close(fd);
return REDIS_ERR;
}
int redisCheckSocketError(redisContext *c, int fd) {
int err = 0;
socklen_t errlen = sizeof(err);
if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &errlen) == -1) { if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &errlen) == -1) {
__redisSetErrorFromErrno(c,REDIS_ERR_IO,"getsockopt(SO_ERROR)"); __redisSetErrorFromErrno(c,REDIS_ERR_IO,"getsockopt(SO_ERROR)");
close(fd); close(fd);
...@@ -159,11 +167,6 @@ static int redisContextWaitReady(redisContext *c, int fd, const struct timeval * ...@@ -159,11 +167,6 @@ static int redisContextWaitReady(redisContext *c, int fd, const struct timeval *
} }
return REDIS_OK; return REDIS_OK;
}
__redisSetErrorFromErrno(c,REDIS_ERR_IO,NULL);
close(fd);
return REDIS_ERR;
} }
int redisContextSetTimeout(redisContext *c, struct timeval tv) { int redisContextSetTimeout(redisContext *c, struct timeval tv) {
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#define AF_LOCAL AF_UNIX #define AF_LOCAL AF_UNIX
#endif #endif
int redisCheckSocketError(redisContext *c, int fd);
int redisContextSetTimeout(redisContext *c, struct timeval tv); int redisContextSetTimeout(redisContext *c, struct timeval tv);
int redisContextConnectTcp(redisContext *c, const char *addr, int port, struct timeval *timeout); int redisContextConnectTcp(redisContext *c, const char *addr, int port, struct timeval *timeout);
int redisContextConnectUnix(redisContext *c, const char *path, struct timeval *timeout); int redisContextConnectUnix(redisContext *c, const char *path, struct timeval *timeout);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment