Created
June 12, 2015 06:55
-
-
Save fffaraz/fbcf45308ee57e898657 to your computer and use it in GitHub Desktop.
SO_KEEPALIVE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sys/socket.h> | |
#include <netinet/in.h> | |
#include <netinet/tcp.h> | |
int enableKeepAlive = 1; | |
int fd = tcpSocket->socketDescriptor(); | |
setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &enableKeepAlive, sizeof(enableKeepAlive)); | |
int maxIdle = 300; | |
setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &maxIdle, sizeof(maxIdle)); | |
int count = 4; | |
setsockopt(fd, SOL_TCP, TCP_KEEPCNT, &count, sizeof(count)); | |
int interval = 4; | |
setsockopt(fd, SOL_TCP, TCP_KEEPINTVL, &interval, sizeof(interval)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment