Skip to content

Instantly share code, notes, and snippets.

@fffaraz
Created June 12, 2015 06:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fffaraz/fbcf45308ee57e898657 to your computer and use it in GitHub Desktop.
Save fffaraz/fbcf45308ee57e898657 to your computer and use it in GitHub Desktop.
SO_KEEPALIVE
#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