-
-
Save haithemsekri/89ad630179c6d5208043edfc46141718 to your computer and use it in GitHub Desktop.
SO_KEEPALIVE
This file contains hidden or 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