summaryrefslogtreecommitdiff
path: root/net.c
diff options
context:
space:
mode:
authorm <m@bitsnbites.eu>2019-03-31 18:05:32 +0200
committerMarcus Geelnard <marcus.geelnard@smarteye.se>2019-04-01 11:52:24 +0200
commite84086cb92bfcab88e7dfd7760351e3d2a65950d (patch)
tree795d60a35ed74ecb0eff74438f33e7228d0a2ad4 /net.c
parent1788f41f168e7fe19a79908a58fc1841b60ab170 (diff)
Introduce a redisFD type
The redisFD type should be equal to the system native socket file desciptor type (for POSIX, this is a plain int). We also introduce the REDIS_INVALID_FD value, which maps to -1 on POSIX systems.
Diffstat (limited to 'net.c')
-rw-r--r--net.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/net.c b/net.c
index a1913cd..87b7fbb 100644
--- a/net.c
+++ b/net.c
@@ -58,9 +58,9 @@
void __redisSetError(redisContext *c, int type, const char *str);
void redisNetClose(redisContext *c) {
- if (c && c->fd >= 0) {
+ if (c && c->fd != REDIS_INVALID_FD) {
close(c->fd);
- c->fd = -1;
+ c->fd = REDIS_INVALID_FD;
}
}
@@ -117,8 +117,8 @@ static int redisSetReuseAddr(redisContext *c) {
}
static int redisCreateSocket(redisContext *c, int type) {
- int s;
- if ((s = socket(type, SOCK_STREAM, 0)) == -1) {
+ redisFD s;
+ if ((s = socket(type, SOCK_STREAM, 0)) == REDIS_INVALID_FD) {
__redisSetErrorFromErrno(c,REDIS_ERR_IO,NULL);
return REDIS_ERR;
}
@@ -158,7 +158,7 @@ static int redisSetBlocking(redisContext *c, int blocking) {
int redisKeepAlive(redisContext *c, int interval) {
int val = 1;
- int fd = c->fd;
+ redisFD fd = c->fd;
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &val, sizeof(val)) == -1){
__redisSetError(c,REDIS_ERR_OTHER,strerror(errno));
@@ -322,7 +322,8 @@ int redisContextSetTimeout(redisContext *c, const struct timeval tv) {
static int _redisContextConnectTcp(redisContext *c, const char *addr, int port,
const struct timeval *timeout,
const char *source_addr) {
- int s, rv, n;
+ redisFD s;
+ int rv, n;
char _port[6]; /* strlen("65535"); */
struct addrinfo hints, *servinfo, *bservinfo, *p, *b;
int blocking = (c->flags & REDIS_BLOCK);
@@ -391,7 +392,7 @@ static int _redisContextConnectTcp(redisContext *c, const char *addr, int port,
}
for (p = servinfo; p != NULL; p = p->ai_next) {
addrretry:
- if ((s = socket(p->ai_family,p->ai_socktype,p->ai_protocol)) == -1)
+ if ((s = socket(p->ai_family,p->ai_socktype,p->ai_protocol)) == REDIS_INVALID_FD)
continue;
c->fd = s;