From 1e83da78125e14faa53fcc3f6c99344628d6f6ac Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 17 Dec 2019 16:37:00 +0800 Subject: [PATCH] Refactor HTTP recv request timeout to 15s. --- trunk/src/app/srs_app_http_conn.cpp | 12 ++++++------ trunk/src/app/srs_app_http_stream.cpp | 5 +++-- trunk/src/kernel/srs_kernel_consts.hpp | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/trunk/src/app/srs_app_http_conn.cpp b/trunk/src/app/srs_app_http_conn.cpp index f1289dfbd..68663cdb8 100644 --- a/trunk/src/app/srs_app_http_conn.cpp +++ b/trunk/src/app/srs_app_http_conn.cpp @@ -81,11 +81,9 @@ srs_error_t SrsHttpConn::do_cycle() { srs_error_t err = srs_success; - srs_trace("HTTP client ip=%s", ip.c_str()); - // initialize parser if ((err = parser->initialize(HTTP_REQUEST, false)) != srs_success) { - return srs_error_wrap(err, "init parser"); + return srs_error_wrap(err, "init parser for %s", ip.c_str()); } // set the recv timeout, for some clients never disconnect the connection. @@ -102,10 +100,12 @@ srs_error_t SrsHttpConn::do_cycle() } // process http messages. - while ((err = trd->pull()) == srs_success) { - ISrsHttpMessage* req = NULL; - + for (int req_id = 0; (err = trd->pull()) == srs_success; req_id++) { + // Try to receive a message from http. + srs_trace("HTTP client ip=%s, request=%d, to=%dms", ip.c_str(), req_id, srsu2ms(SRS_HTTP_RECV_TIMEOUT)); + // get a http message + ISrsHttpMessage* req = NULL; if ((err = parser->parse_message(skt, &req)) != srs_success) { break; } diff --git a/trunk/src/app/srs_app_http_stream.cpp b/trunk/src/app/srs_app_http_stream.cpp index 05cac25ef..64356c4df 100755 --- a/trunk/src/app/srs_app_http_stream.cpp +++ b/trunk/src/app/srs_app_http_stream.cpp @@ -597,7 +597,7 @@ srs_error_t SrsLiveStream::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess if ((err = hc->set_socket_buffer(mw_sleep)) != srs_success) { return srs_error_wrap(err, "set mw_sleep %" PRId64, mw_sleep); } - + SrsHttpRecvThread* trd = new SrsHttpRecvThread(hc); SrsAutoFree(SrsHttpRecvThread, trd); @@ -610,6 +610,7 @@ srs_error_t SrsLiveStream::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess enc->has_cache(), msgs.max); // TODO: free and erase the disabled entry after all related connections is closed. + // TODO: FXIME: Support timeout for player, quit infinite-loop. while (entry->enabled) { pprint->elapse(); @@ -659,7 +660,7 @@ srs_error_t SrsLiveStream::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess return srs_error_wrap(err, "send messages"); } } - + return err; } diff --git a/trunk/src/kernel/srs_kernel_consts.hpp b/trunk/src/kernel/srs_kernel_consts.hpp index 8df891fd2..9a75955c4 100644 --- a/trunk/src/kernel/srs_kernel_consts.hpp +++ b/trunk/src/kernel/srs_kernel_consts.hpp @@ -213,7 +213,7 @@ #define SRS_CONSTS_HTTP_QUERY_SEP '?' // The default recv timeout. -#define SRS_HTTP_RECV_TIMEOUT (60 * SRS_UTIME_SECONDS) +#define SRS_HTTP_RECV_TIMEOUT (15 * SRS_UTIME_SECONDS) // 6.1.1 Status Code and Reason Phrase #define SRS_CONSTS_HTTP_Continue 100