From a6871052afa957d9114469f466fed56f6cbb7a7d Mon Sep 17 00:00:00 2001 From: juntaoliu Date: Sun, 7 Jan 2018 17:03:13 +0800 Subject: [PATCH 1/2] set tcp keepalive for tcp socket (#1045) --- AUTHORS.txt | 1 + trunk/src/app/srs_app_listener.cpp | 10 ++++++++++ trunk/src/kernel/srs_kernel_error.hpp | 1 + 3 files changed, 12 insertions(+) diff --git a/AUTHORS.txt b/AUTHORS.txt index d036b8d20..28b4c8526 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -26,4 +26,5 @@ CONTRIBUTORS ordered by first contribution. * lovecat "Bug fixed" * panda1986<542638787@qq.com> "Bug fixed" * YueHonghui "Bug fixed" +* JuntaoLiu "Bug fixed" diff --git a/trunk/src/app/srs_app_listener.cpp b/trunk/src/app/srs_app_listener.cpp index d2d853b8b..7516a79ca 100755 --- a/trunk/src/app/srs_app_listener.cpp +++ b/trunk/src/app/srs_app_listener.cpp @@ -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); diff --git a/trunk/src/kernel/srs_kernel_error.hpp b/trunk/src/kernel/srs_kernel_error.hpp index aa2cddfc6..cdc561a1e 100755 --- a/trunk/src/kernel/srs_kernel_error.hpp +++ b/trunk/src/kernel/srs_kernel_error.hpp @@ -98,6 +98,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define ERROR_SYSTEM_CREATE_DIR 1057 #define ERROR_SYSTEM_KILL 1058 #define ERROR_SYSTEM_DNS_RESOLVE 1059 +#define ERROR_SOCKET_SETKEEPALIVE 1060 /////////////////////////////////////////////////////// // RTMP protocol error. From 911cd448f14478c7fc9111d6b1a7c4530ad9925b Mon Sep 17 00:00:00 2001 From: winlin Date: Sun, 7 Jan 2018 17:18:43 +0800 Subject: [PATCH 2/2] Merge #1045, for #1044, TCP connection alive detection. 2.0.245 --- README.md | 3 +++ trunk/src/app/srs_app_listener.cpp | 2 +- trunk/src/core/srs_core.hpp | 2 +- trunk/src/core/srs_core_performance.hpp | 4 ++++ 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e28ca9d68..2049af95a 100755 --- a/README.md +++ b/README.md @@ -332,6 +332,7 @@ Remark: ## History +* v2.0, 2018-01-07, Merge [#1045][bug #1045], fix [#1044][bug #1044], TCP connection alive detection. 2.0.245 * v2.0, 2018-01-04, Merge [#1039][bug #1039], fix bug of init.d script. * v2.0, 2018-01-01, Merge [#1033][bug #1033], allow user to add some specific flags. 2.0.244 * v2.0, 2017-06-10, [2.0 release2(2.0.243)][r2.0r2] released. 86670 lines. @@ -1300,6 +1301,8 @@ Winlin [bug #899]: https://github.com/ossrs/srs/issues/899 [bug #1033]: https://github.com/ossrs/srs/issues/1033 [bug #1039]: https://github.com/ossrs/srs/issues/1039 +[bug #1044]: https://github.com/ossrs/srs/issues/1044 +[bug #1045]: https://github.com/ossrs/srs/issues/1045 [bug #xxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxx [exo #828]: https://github.com/google/ExoPlayer/pull/828 diff --git a/trunk/src/app/srs_app_listener.cpp b/trunk/src/app/srs_app_listener.cpp index 7516a79ca..2155629bf 100755 --- a/trunk/src/app/srs_app_listener.cpp +++ b/trunk/src/app/srs_app_listener.cpp @@ -223,7 +223,7 @@ int SrsTcpListener::listen() } srs_verbose("setsockopt reuse-addr success. port=%d, fd=%d", port, _fd); -#ifdef SO_KEEPALIVE +#ifdef SRS_PERF_SO_KEEPALIVE int tcp_keepalive = 1; if (setsockopt(_fd, SOL_SOCKET, SO_KEEPALIVE, &tcp_keepalive, sizeof(int)) == -1) { ret = ERROR_SOCKET_SETKEEPALIVE; diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp index 04d0bf928..baa61b928 100644 --- a/trunk/src/core/srs_core.hpp +++ b/trunk/src/core/srs_core.hpp @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // current release version #define VERSION_MAJOR 2 #define VERSION_MINOR 0 -#define VERSION_REVISION 244 +#define VERSION_REVISION 245 // generated by configure, only macros. #include diff --git a/trunk/src/core/srs_core_performance.hpp b/trunk/src/core/srs_core_performance.hpp index 7d5d55f07..b5a54447b 100644 --- a/trunk/src/core/srs_core_performance.hpp +++ b/trunk/src/core/srs_core_performance.hpp @@ -188,5 +188,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #undef SRS_PERF_FAST_FLV_ENCODER #define SRS_PERF_FAST_FLV_ENCODER +// Whether set SO_KEEPALIVE for TCP connection. +// @see https://github.com/ossrs/srs/issues/1044 +#undef SRS_PERF_SO_KEEPALIVE + #endif