mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
For #913, use complex error for listener
This commit is contained in:
parent
b88265fc78
commit
5c9a12e72a
19 changed files with 245 additions and 268 deletions
|
@ -44,23 +44,23 @@ bool srs_is_client_gracefully_close(int error_code)
|
|||
|| error_code == ERROR_SOCKET_WRITE;
|
||||
}
|
||||
|
||||
SrsError::SrsError()
|
||||
SrsCplxError::SrsCplxError()
|
||||
{
|
||||
code = ERROR_SUCCESS;
|
||||
wrapped = NULL;
|
||||
cid = rerrno = line = 0;
|
||||
}
|
||||
|
||||
SrsError::~SrsError()
|
||||
SrsCplxError::~SrsCplxError()
|
||||
{
|
||||
}
|
||||
|
||||
std::string SrsError::description() {
|
||||
std::string SrsCplxError::description() {
|
||||
if (desc.empty()) {
|
||||
stringstream ss;
|
||||
ss << "code=" << code;
|
||||
|
||||
SrsError* next = this;
|
||||
SrsCplxError* next = this;
|
||||
while (next) {
|
||||
ss << " : " << next->msg;
|
||||
next = next->wrapped;
|
||||
|
@ -82,7 +82,7 @@ std::string SrsError::description() {
|
|||
return desc;
|
||||
}
|
||||
|
||||
SrsError* SrsError::create(const char* func, const char* file, int line, int code, const char* fmt, ...) {
|
||||
SrsCplxError* SrsCplxError::create(const char* func, const char* file, int line, int code, const char* fmt, ...) {
|
||||
int rerrno = (int)errno;
|
||||
|
||||
va_list ap;
|
||||
|
@ -91,7 +91,7 @@ SrsError* SrsError::create(const char* func, const char* file, int line, int cod
|
|||
vsnprintf(buffer, sizeof(buffer), fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
SrsError* err = new SrsError();
|
||||
SrsCplxError* err = new SrsCplxError();
|
||||
|
||||
err->func = func;
|
||||
err->file = file;
|
||||
|
@ -107,7 +107,7 @@ SrsError* SrsError::create(const char* func, const char* file, int line, int cod
|
|||
return err;
|
||||
}
|
||||
|
||||
SrsError* SrsError::wrap(const char* func, const char* file, int line, SrsError* v, const char* fmt, ...) {
|
||||
SrsCplxError* SrsCplxError::wrap(const char* func, const char* file, int line, SrsCplxError* v, const char* fmt, ...) {
|
||||
int rerrno = (int)errno;
|
||||
|
||||
va_list ap;
|
||||
|
@ -116,7 +116,7 @@ SrsError* SrsError::wrap(const char* func, const char* file, int line, SrsError*
|
|||
vsnprintf(buffer, sizeof(buffer), fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
SrsError* err = new SrsError();
|
||||
SrsCplxError* err = new SrsCplxError();
|
||||
|
||||
err->func = func;
|
||||
err->file = file;
|
||||
|
@ -132,17 +132,17 @@ SrsError* SrsError::wrap(const char* func, const char* file, int line, SrsError*
|
|||
return err;
|
||||
}
|
||||
|
||||
SrsError* SrsError::success() {
|
||||
SrsCplxError* SrsCplxError::success() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SrsError* SrsError::copy(SrsError* from)
|
||||
SrsCplxError* SrsCplxError::copy(SrsCplxError* from)
|
||||
{
|
||||
if (from == srs_success) {
|
||||
return srs_success;
|
||||
}
|
||||
|
||||
SrsError* err = new SrsError();
|
||||
SrsCplxError* err = new SrsCplxError();
|
||||
|
||||
err->code = from->code;
|
||||
err->wrapped = srs_error_copy(from->wrapped);
|
||||
|
@ -157,12 +157,12 @@ SrsError* SrsError::copy(SrsError* from)
|
|||
return err;
|
||||
}
|
||||
|
||||
string SrsError::description(SrsError* err)
|
||||
string SrsCplxError::description(SrsCplxError* err)
|
||||
{
|
||||
return err? err->description() : "Success";
|
||||
}
|
||||
|
||||
int SrsError::error_code(SrsError* err)
|
||||
int SrsCplxError::error_code(SrsCplxError* err)
|
||||
{
|
||||
return err? err->code : ERROR_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -336,11 +336,11 @@ extern bool srs_is_system_control_error(int error_code);
|
|||
extern bool srs_is_client_gracefully_close(int error_code);
|
||||
|
||||
// Use complex errors, @read https://github.com/ossrs/srs/issues/913
|
||||
class SrsError
|
||||
class SrsCplxError
|
||||
{
|
||||
private:
|
||||
int code;
|
||||
SrsError* wrapped;
|
||||
SrsCplxError* wrapped;
|
||||
std::string msg;
|
||||
|
||||
std::string func;
|
||||
|
@ -352,27 +352,27 @@ private:
|
|||
|
||||
std::string desc;
|
||||
private:
|
||||
SrsError();
|
||||
SrsCplxError();
|
||||
public:
|
||||
virtual ~SrsError();
|
||||
virtual ~SrsCplxError();
|
||||
private:
|
||||
virtual std::string description();
|
||||
public:
|
||||
static SrsError* create(const char* func, const char* file, int line, int code, const char* fmt, ...);
|
||||
static SrsError* wrap(const char* func, const char* file, int line, SrsError* err, const char* fmt, ...);
|
||||
static SrsError* success();
|
||||
static SrsError* copy(SrsError* from);
|
||||
static std::string description(SrsError* err);
|
||||
static int error_code(SrsError* err);
|
||||
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 int error_code(SrsCplxError* err);
|
||||
};
|
||||
|
||||
// Error helpers, should use these functions to new or wrap an error.
|
||||
#define srs_success SrsError::success()
|
||||
#define srs_error_new(ret, fmt, ...) SrsError::create(__FUNCTION__, __FILE__, __LINE__, ret, fmt, ##__VA_ARGS__)
|
||||
#define srs_error_wrap(err, fmt, ...) SrsError::wrap(__FUNCTION__, __FILE__, __LINE__, err, fmt, ##__VA_ARGS__)
|
||||
#define srs_error_copy(err) SrsError::copy(err)
|
||||
#define srs_error_desc(err) SrsError::description(err)
|
||||
#define srs_error_code(err) SrsError::error_code(err)
|
||||
#define srs_success SrsCplxError::success()
|
||||
#define srs_error_new(ret, fmt, ...) SrsCplxError::create(__FUNCTION__, __FILE__, __LINE__, ret, fmt, ##__VA_ARGS__)
|
||||
#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_code(err) SrsCplxError::error_code(err)
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue