summaryrefslogtreecommitdiff
path: root/net.c
diff options
context:
space:
mode:
authorViktor Söderqvist <viktor.soderqvist@est.tech>2023-05-29 22:25:34 +0200
committerGitHub <noreply@github.com>2023-05-29 13:25:34 -0700
commitb6a052fe0959dae69e16b9d74449faeb1b70dbe1 (patch)
tree9bf6d4456e0d2e0cc73f55fea5b6c764eb3ab156 /net.c
parent3fa9b69443aa306b8219fc47aaffecd76e13a9ab (diff)
Helper for setting TCP_USER_TIMEOUT socket option (#1188)
* Implement redisSetTcpUserTimeout to set socket option TCP_USER_TIMEOUT * Documentation for redisSetTcpUserTimeout and some more undocumented functions Documentation for redisReconnect() and the setters of socket options: * redisKeepAlive() * redisEnableKeepAliveWithInterval() * redisSetTcpUserTimeout()
Diffstat (limited to 'net.c')
-rw-r--r--net.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/net.c b/net.c
index ec96412..ccd7f16 100644
--- a/net.c
+++ b/net.c
@@ -228,6 +228,22 @@ int redisSetTcpNoDelay(redisContext *c) {
return REDIS_OK;
}
+int redisContextSetTcpUserTimeout(redisContext *c, unsigned int timeout) {
+ int res;
+#ifdef TCP_USER_TIMEOUT
+ res = setsockopt(c->fd, IPPROTO_TCP, TCP_USER_TIMEOUT, &timeout, sizeof(timeout));
+#else
+ res = -1;
+ (void)timeout;
+#endif
+ if (res == -1); {
+ __redisSetErrorFromErrno(c,REDIS_ERR_IO,"setsockopt(TCP_USER_TIMEOUT)");
+ redisNetClose(c);
+ return REDIS_ERR;
+ }
+ return REDIS_OK;
+}
+
#define __MAX_MSEC (((LONG_MAX) - 999) / 1000)
static int redisContextTimeoutMsec(redisContext *c, long *result)