diff options
author | Eddy Jansson <eddy@scmcoord.com> | 2014-02-24 11:41:00 +0100 |
---|---|---|
committer | Matt Stancliff <matt@genges.com> | 2014-04-09 17:02:42 -0400 |
commit | ae30d58ff91061e0b0f889f60a9ab2062fa4e9d0 (patch) | |
tree | b51aac4c7f41b2ff02c99a731eabe6bc2c3b6dca /hiredis.c | |
parent | 37d25a392c9b9468e064a67c504939c9c4ea0031 (diff) |
Add redisConnectFd() and redisFreeKeepFd()
These allows for easier integration of hiredis with external
code that wants to manage its fds, say for instance in a pool.
Closes #223
Diffstat (limited to 'hiredis.c')
-rw-r--r-- | hiredis.c | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -1010,6 +1010,13 @@ void redisFree(redisContext *c) { free(c); } +int redisFreeKeepFd(redisContext *c) { + int fd = c->fd; + c->fd = -1; + redisFree(c); + return fd; +} + /* Connect to a Redis instance. On error the field error in the returned * context will be set to the return value of the error function. * When no set of reply functions is given, the default set will be used. */ @@ -1093,6 +1100,18 @@ redisContext *redisConnectUnixNonBlock(const char *path) { return c; } +redisContext *redisConnectFd(int fd) { + redisContext *c; + + c = redisContextInit(); + if (c == NULL) + return NULL; + + c->fd = fd; + c->flags |= REDIS_BLOCK | REDIS_CONNECTED; + return c; +} + /* Set read/write timeout on a blocking socket. */ int redisSetTimeout(redisContext *c, const struct timeval tv) { if (c->flags & REDIS_BLOCK) |