diff options
Diffstat (limited to 'src/socket_util.c')
-rw-r--r-- | src/socket_util.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/socket_util.c b/src/socket_util.c index a89a67ed6..aa0a44e44 100644 --- a/src/socket_util.c +++ b/src/socket_util.c @@ -148,3 +148,18 @@ socket_bind_listen(int domain, int type, int protocol, return fd; } + +int +socket_keepalive(int fd) +{ + const int reuse = 1; + +#ifdef WIN32 + const char *optval = (const char *)&reuse; +#else + const void *optval = &reuse; +#endif + + return setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, + optval, sizeof(reuse)); +} |