1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

Merge #1044, for #1045, set TCP SO_KEEPALIVE

This commit is contained in:
winlin 2018-01-07 17:23:36 +08:00
commit 049e7c82c0
5 changed files with 16 additions and 0 deletions

View file

@ -227,6 +227,13 @@ srs_error_t SrsTcpListener::listen()
if ((_fd = socket(r->ai_family, r->ai_socktype, r->ai_protocol)) == -1) {
return srs_error_new(ERROR_SOCKET_CREATE, "create socket. ip=%s, port=%d", ip.c_str(), port);
}
#ifdef SRS_PERF_SO_KEEPALIVE
int tcp_keepalive = 1;
if (setsockopt(_fd, SOL_SOCKET, SO_KEEPALIVE, &tcp_keepalive, sizeof(int)) == -1) {
return srs_error_new(ERROR_SOCKET_SETKEEPALIVE, "setsockopt SO_KEEPALIVE[%d]error. port=%d", tcp_keepalive, port);
}
#endif
srs_fd_close_exec(_fd);
srs_socket_reuse_addr(_fd);

View file

@ -190,5 +190,9 @@
#define SRS_PERF_GLIBC_MEMORY_CHECK
#undef SRS_PERF_GLIBC_MEMORY_CHECK
// Whether set SO_KEEPALIVE for TCP connection.
// @see https://github.com/ossrs/srs/issues/1044
#undef SRS_PERF_SO_KEEPALIVE
#endif

View file

@ -111,6 +111,7 @@
#define ERROR_THREAD_DUMMY 1072
#define ERROR_ASPROCESS_PPID 1073
#define ERROR_EXCEED_CONNECTIONS 1074
#define ERROR_SOCKET_SETKEEPALIVE 1075
///////////////////////////////////////////////////////
// RTMP protocol error.