mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
set tcp keepalive for tcp socket (#1045)
This commit is contained in:
parent
a6bc53cb85
commit
a6871052af
3 changed files with 12 additions and 0 deletions
|
@ -223,6 +223,16 @@ int SrsTcpListener::listen()
|
|||
}
|
||||
srs_verbose("setsockopt reuse-addr success. port=%d, fd=%d", port, _fd);
|
||||
|
||||
#ifdef SO_KEEPALIVE
|
||||
int tcp_keepalive = 1;
|
||||
if (setsockopt(_fd, SOL_SOCKET, SO_KEEPALIVE, &tcp_keepalive, sizeof(int)) == -1) {
|
||||
ret = ERROR_SOCKET_SETKEEPALIVE;
|
||||
srs_error("setsockopt SO_KEEPALIVE[%d]error. port=%d, ret=%d", tcp_keepalive, port, ret);
|
||||
return ret;
|
||||
}
|
||||
srs_verbose("setsockopt SO_KEEPALIVE[%d]success. port=%d", tcp_keepalive, port);
|
||||
#endif
|
||||
|
||||
sockaddr_in addr;
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(port);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue