1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

For #913, refine the error mechanism

This commit is contained in:
winlin 2017-06-09 13:29:23 +08:00
parent bb200b5d2d
commit 93710c7489
11 changed files with 38 additions and 31 deletions

View file

@ -265,24 +265,25 @@ SrsHttpServer::~SrsHttpServer()
srs_freep(http_static); srs_freep(http_static);
} }
int SrsHttpServer::initialize() srs_error_t SrsHttpServer::initialize()
{ {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;
srs_error_t err = srs_success;
// for SRS go-sharp to detect the status of HTTP server of SRS HTTP FLV Cluster. // for SRS go-sharp to detect the status of HTTP server of SRS HTTP FLV Cluster.
if ((ret = http_static->mux.handle("/api/v1/versions", new SrsGoApiVersion())) != ERROR_SUCCESS) { if ((ret = http_static->mux.handle("/api/v1/versions", new SrsGoApiVersion())) != ERROR_SUCCESS) {
return ret; return srs_error_new(ret, "handle versin");
} }
if ((ret = http_stream->initialize()) != ERROR_SUCCESS) { if ((err = http_stream->initialize()) != srs_success) {
return ret; return srs_error_wrap(err, "http stream");
} }
if ((ret = http_static->initialize()) != ERROR_SUCCESS) { if ((err = http_static->initialize()) != srs_success) {
return ret; return srs_error_wrap(err, "http static");
} }
return ret; return err;
} }
int SrsHttpServer::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) int SrsHttpServer::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)

View file

@ -125,7 +125,7 @@ public:
SrsHttpServer(SrsServer* svr); SrsHttpServer(SrsServer* svr);
virtual ~SrsHttpServer(); virtual ~SrsHttpServer();
public: public:
virtual int initialize(); virtual srs_error_t initialize();
// ISrsHttpServeMux // ISrsHttpServeMux
public: public:
virtual int serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r); virtual int serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);

View file

@ -208,9 +208,10 @@ SrsHttpStaticServer::~SrsHttpStaticServer()
_srs_config->unsubscribe(this); _srs_config->unsubscribe(this);
} }
int SrsHttpStaticServer::initialize() srs_error_t SrsHttpStaticServer::initialize()
{ {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;
srs_error_t err = srs_success;
bool default_root_exists = false; bool default_root_exists = false;
@ -226,7 +227,7 @@ int SrsHttpStaticServer::initialize()
string pmount; string pmount;
string vhost = conf->arg0(); string vhost = conf->arg0();
if ((ret = mount_vhost(vhost, pmount)) != ERROR_SUCCESS) { if ((ret = mount_vhost(vhost, pmount)) != ERROR_SUCCESS) {
return ret; return srs_error_new(ret, "mount vhost");
} }
if (pmount == "/") { if (pmount == "/") {
@ -240,13 +241,12 @@ int SrsHttpStaticServer::initialize()
// add root // add root
std::string dir = _srs_config->get_http_stream_dir(); std::string dir = _srs_config->get_http_stream_dir();
if ((ret = mux.handle("/", new SrsVodStream(dir))) != ERROR_SUCCESS) { if ((ret = mux.handle("/", new SrsVodStream(dir))) != ERROR_SUCCESS) {
srs_error("http: mount root dir=%s failed. ret=%d", dir.c_str(), ret); return srs_error_new(ret, "mount root dir=%s", dir.c_str());
return ret;
} }
srs_trace("http: root mount to %s", dir.c_str()); srs_trace("http: root mount to %s", dir.c_str());
} }
return ret; return err;
} }
int SrsHttpStaticServer::mount_vhost(string vhost, string& pmount) int SrsHttpStaticServer::mount_vhost(string vhost, string& pmount)

View file

@ -58,7 +58,7 @@ public:
SrsHttpStaticServer(SrsServer* svr); SrsHttpStaticServer(SrsServer* svr);
virtual ~SrsHttpStaticServer(); virtual ~SrsHttpStaticServer();
public: public:
virtual int initialize(); virtual srs_error_t initialize();
private: private:
virtual int mount_vhost(std::string vhost, std::string& pmount); virtual int mount_vhost(std::string vhost, std::string& pmount);
// interface ISrsReloadHandler. // interface ISrsReloadHandler.

View file

@ -704,16 +704,17 @@ SrsHttpStreamServer::~SrsHttpStreamServer()
} }
} }
int SrsHttpStreamServer::initialize() srs_error_t SrsHttpStreamServer::initialize()
{ {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;
srs_error_t err = srs_success;
// remux rtmp to flv live streaming // remux rtmp to flv live streaming
if ((ret = initialize_flv_streaming()) != ERROR_SUCCESS) { if ((ret = initialize_flv_streaming()) != ERROR_SUCCESS) {
return ret; return srs_error_new(ret, "http flv stream");
} }
return ret; return err;
} }
// TODO: FIXME: rename for HTTP FLV mount. // TODO: FIXME: rename for HTTP FLV mount.

View file

@ -283,7 +283,7 @@ public:
SrsHttpStreamServer(SrsServer* svr); SrsHttpStreamServer(SrsServer* svr);
virtual ~SrsHttpStreamServer(); virtual ~SrsHttpStreamServer();
public: public:
virtual int initialize(); virtual srs_error_t initialize();
// http flv/ts/mp3/aac stream // http flv/ts/mp3/aac stream
public: public:
virtual int http_mount(SrsSource* s, SrsRequest* r); virtual int http_mount(SrsSource* s, SrsRequest* r);

View file

@ -353,6 +353,10 @@ int srs_initialize_kafka()
void srs_dispose_kafka() void srs_dispose_kafka()
{ {
SrsKafkaProducer* kafka = dynamic_cast<SrsKafkaProducer*>(_srs_kafka); SrsKafkaProducer* kafka = dynamic_cast<SrsKafkaProducer*>(_srs_kafka);
if (!kafka) {
return;
}
kafka->stop(); kafka->stop();
srs_freep(kafka); srs_freep(kafka);

View file

@ -559,7 +559,6 @@ void SrsServer::dispose()
srs_error_t SrsServer::initialize(ISrsServerCycle* cycle_handler) srs_error_t SrsServer::initialize(ISrsServerCycle* cycle_handler)
{ {
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success; srs_error_t err = srs_success;
// ensure the time is ok. // ensure the time is ok.
@ -575,16 +574,16 @@ srs_error_t SrsServer::initialize(ISrsServerCycle* cycle_handler)
signal_manager = new SrsSignalManager(this); signal_manager = new SrsSignalManager(this);
handler = cycle_handler; handler = cycle_handler;
if(handler && (ret = handler->initialize()) != ERROR_SUCCESS){ if(handler && (err = handler->initialize()) != srs_success){
return srs_error_new(ret, "handler initialize"); return srs_error_wrap(err, "handler initialize");
} }
if ((ret = http_api_mux->initialize()) != ERROR_SUCCESS) { if ((err = http_api_mux->initialize()) != srs_success) {
return srs_error_new(ret, "http api initialize"); return srs_error_wrap(err, "http api initialize");
} }
if ((ret = http_server->initialize()) != ERROR_SUCCESS) { if ((err = http_server->initialize()) != srs_success) {
return srs_error_new(ret, "http server initialize"); return srs_error_wrap(err, "http server initialize");
} }
http_heartbeat = new SrsHttpHeartbeat(); http_heartbeat = new SrsHttpHeartbeat();

View file

@ -219,7 +219,7 @@ public:
/** /**
* initialize the cycle handler. * initialize the cycle handler.
*/ */
virtual int initialize() = 0; virtual srs_error_t initialize() = 0;
/** /**
* do on_cycle while server doing cycle. * do on_cycle while server doing cycle.
*/ */

View file

@ -533,11 +533,13 @@ SrsHttpServeMux::~SrsHttpServeMux()
hijackers.clear(); hijackers.clear();
} }
int SrsHttpServeMux::initialize() srs_error_t SrsHttpServeMux::initialize()
{ {
int ret = ERROR_SUCCESS; srs_error_t err = srs_success;
// TODO: FIXME: implements it.
return ret; // TODO: FIXME: Implements it.
return err;
} }
void SrsHttpServeMux::hijack(ISrsHttpMatchHijacker* h) void SrsHttpServeMux::hijack(ISrsHttpMatchHijacker* h)

View file

@ -417,7 +417,7 @@ public:
/** /**
* initialize the http serve mux. * initialize the http serve mux.
*/ */
virtual int initialize(); virtual srs_error_t initialize();
/** /**
* hijack the http match. * hijack the http match.
*/ */