From 46a81372e7bc133f58607fbf077d431fad17a131 Mon Sep 17 00:00:00 2001 From: winlin Date: Fri, 22 May 2015 13:57:04 +0800 Subject: [PATCH] fix #398, set recv timeout for http connection. --- trunk/src/app/srs_app_http_api.cpp | 4 ++++ trunk/src/app/srs_app_http_conn.cpp | 4 ++++ trunk/src/kernel/srs_kernel_consts.hpp | 3 +++ trunk/src/kernel/srs_kernel_error.cpp | 3 ++- 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/trunk/src/app/srs_app_http_api.cpp b/trunk/src/app/srs_app_http_api.cpp index d4e3ea5fc..5b2f169d6 100644 --- a/trunk/src/app/srs_app_http_api.cpp +++ b/trunk/src/app/srs_app_http_api.cpp @@ -523,6 +523,10 @@ int SrsHttpApi::do_cycle() // underlayer socket SrsStSocket skt(stfd); + // set the recv timeout, for some clients never disconnect the connection. + // @see https://github.com/simple-rtmp-server/srs/issues/398 + skt.set_recv_timeout(SRS_HTTP_RECV_TIMEOUT_US); + // process http messages. for (;;) { SrsHttpMessage* req = NULL; diff --git a/trunk/src/app/srs_app_http_conn.cpp b/trunk/src/app/srs_app_http_conn.cpp index bdf8e2dc0..4350cd15d 100644 --- a/trunk/src/app/srs_app_http_conn.cpp +++ b/trunk/src/app/srs_app_http_conn.cpp @@ -1383,6 +1383,10 @@ int SrsHttpConn::do_cycle() // underlayer socket SrsStSocket skt(stfd); + // set the recv timeout, for some clients never disconnect the connection. + // @see https://github.com/simple-rtmp-server/srs/issues/398 + skt.set_recv_timeout(SRS_HTTP_RECV_TIMEOUT_US); + // process http messages. for (;;) { SrsHttpMessage* req = NULL; diff --git a/trunk/src/kernel/srs_kernel_consts.hpp b/trunk/src/kernel/srs_kernel_consts.hpp index c4a09831d..ee1142dc6 100644 --- a/trunk/src/kernel/srs_kernel_consts.hpp +++ b/trunk/src/kernel/srs_kernel_consts.hpp @@ -201,6 +201,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // query string seprator #define SRS_CONSTS_HTTP_QUERY_SEP '?' +// the default recv timeout. +#define SRS_HTTP_RECV_TIMEOUT_US 60 * 1000 * 1000 + // 6.1.1 Status Code and Reason Phrase #define SRS_CONSTS_HTTP_Continue 100 #define SRS_CONSTS_HTTP_SwitchingProtocols 101 diff --git a/trunk/src/kernel/srs_kernel_error.cpp b/trunk/src/kernel/srs_kernel_error.cpp index 0118ef935..dce0c54f0 100644 --- a/trunk/src/kernel/srs_kernel_error.cpp +++ b/trunk/src/kernel/srs_kernel_error.cpp @@ -33,6 +33,7 @@ bool srs_is_client_gracefully_close(int error_code) { return error_code == ERROR_SOCKET_READ || error_code == ERROR_SOCKET_READ_FULLY - || error_code == ERROR_SOCKET_WRITE; + || error_code == ERROR_SOCKET_WRITE + || error_code == ERROR_SOCKET_TIMEOUT; }