1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-15 04:42:04 +00:00

For #1638, #307, http api success with message, timeout as such

This commit is contained in:
winlin 2020-03-17 11:40:05 +08:00
parent b5dd502103
commit 6118ca382a
4 changed files with 41 additions and 4 deletions

View file

@ -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.

View file

@ -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");
}

View file

@ -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;

View file

@ -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