From 6118ca382a68b3e292939611a9a308002608873e Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 17 Mar 2020 11:40:05 +0800 Subject: [PATCH] For #1638, #307, http api success with message, timeout as such --- trunk/src/app/srs_app_conn.cpp | 7 +++++++ trunk/src/app/srs_app_http_api.cpp | 5 +++++ trunk/src/kernel/srs_kernel_error.cpp | 29 +++++++++++++++++++++++---- trunk/src/kernel/srs_kernel_error.hpp | 4 ++++ 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/trunk/src/app/srs_app_conn.cpp b/trunk/src/app/srs_app_conn.cpp index adfa17fe5..aa3f8300a 100644 --- a/trunk/src/app/srs_app_conn.cpp +++ b/trunk/src/app/srs_app_conn.cpp @@ -178,6 +178,13 @@ srs_error_t SrsConnection::cycle() srs_trace("client finished."); return err; } + + // It maybe success with message. + if (srs_error_code(err) == ERROR_SUCCESS) { + srs_trace("client finished%s.", srs_error_summary(err).c_str()); + srs_freep(err); + return err; + } // client close peer. // TODO: FIXME: Only reset the error when client closed it. diff --git a/trunk/src/app/srs_app_http_api.cpp b/trunk/src/app/srs_app_http_api.cpp index 96cde96dd..cb8615d68 100644 --- a/trunk/src/app/srs_app_http_api.cpp +++ b/trunk/src/app/srs_app_http_api.cpp @@ -1431,6 +1431,11 @@ srs_error_t SrsHttpApi::do_cycle() // get a http message if ((err = parser->parse_message(skt, &req)) != srs_success) { + // For HTTP timeout, we think it's ok. + if (srs_error_code(err) == ERROR_SOCKET_TIMEOUT) { + srs_freep(err); + return srs_error_wrap(srs_success, "http api timeout"); + } return srs_error_wrap(err, "parse message"); } diff --git a/trunk/src/kernel/srs_kernel_error.cpp b/trunk/src/kernel/srs_kernel_error.cpp index 8b66f03d5..dd5efc35a 100644 --- a/trunk/src/kernel/srs_kernel_error.cpp +++ b/trunk/src/kernel/srs_kernel_error.cpp @@ -69,14 +69,14 @@ std::string SrsCplxError::description() { if (desc.empty()) { stringstream ss; ss << "code=" << code; - + SrsCplxError* next = this; while (next) { ss << " : " << next->msg; next = next->wrapped; } ss << endl; - + next = this; while (next) { ss << "thread [" << getpid() << "][" << next->cid << "]: " @@ -89,13 +89,29 @@ std::string SrsCplxError::description() { ss << endl; } } - + desc = ss.str(); } - + return desc; } +std::string SrsCplxError::summary() { + if (_summary.empty()) { + stringstream ss; + + SrsCplxError* next = this; + while (next) { + ss << " : " << next->msg; + next = next->wrapped; + } + + _summary = ss.str(); + } + + return _summary; +} + SrsCplxError* SrsCplxError::create(const char* func, const char* file, int line, int code, const char* fmt, ...) { int rerrno = (int)errno; @@ -178,6 +194,11 @@ string SrsCplxError::description(SrsCplxError* err) return err? err->description() : "Success"; } +string SrsCplxError::summary(SrsCplxError* err) +{ + return err? err->summary() : "Success"; +} + int SrsCplxError::error_code(SrsCplxError* err) { return err? err->code : ERROR_SUCCESS; diff --git a/trunk/src/kernel/srs_kernel_error.hpp b/trunk/src/kernel/srs_kernel_error.hpp index 7461ebbcc..6f9aa934e 100644 --- a/trunk/src/kernel/srs_kernel_error.hpp +++ b/trunk/src/kernel/srs_kernel_error.hpp @@ -380,18 +380,21 @@ private: int rerrno; std::string desc; + std::string _summary; private: SrsCplxError(); public: virtual ~SrsCplxError(); private: virtual std::string description(); + virtual std::string summary(); public: static SrsCplxError* create(const char* func, const char* file, int line, int code, const char* fmt, ...); static SrsCplxError* wrap(const char* func, const char* file, int line, SrsCplxError* err, const char* fmt, ...); static SrsCplxError* success(); static SrsCplxError* copy(SrsCplxError* from); static std::string description(SrsCplxError* err); + static std::string summary(SrsCplxError* err); static int error_code(SrsCplxError* err); }; @@ -401,6 +404,7 @@ public: #define srs_error_wrap(err, fmt, ...) SrsCplxError::wrap(__FUNCTION__, __FILE__, __LINE__, err, fmt, ##__VA_ARGS__) #define srs_error_copy(err) SrsCplxError::copy(err) #define srs_error_desc(err) SrsCplxError::description(err) +#define srs_error_summary(err) SrsCplxError::summary(err) #define srs_error_code(err) SrsCplxError::error_code(err) #define srs_error_reset(err) srs_freep(err); err = srs_success