Skip to content

Commit

Permalink
For #913, refine the error mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Jun 9, 2017
1 parent bb200b5 commit 93710c7
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 31 deletions.
15 changes: 8 additions & 7 deletions trunk/src/app/srs_app_http_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,24 +265,25 @@ SrsHttpServer::~SrsHttpServer()
srs_freep(http_static);
}

int SrsHttpServer::initialize()
srs_error_t SrsHttpServer::initialize()
{
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.
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) {
return ret;
if ((err = http_stream->initialize()) != srs_success) {
return srs_error_wrap(err, "http stream");
}

if ((ret = http_static->initialize()) != ERROR_SUCCESS) {
return ret;
if ((err = http_static->initialize()) != srs_success) {
return srs_error_wrap(err, "http static");
}

return ret;
return err;
}

int SrsHttpServer::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_http_conn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class SrsHttpServer : public ISrsHttpServeMux
SrsHttpServer(SrsServer* svr);
virtual ~SrsHttpServer();
public:
virtual int initialize();
virtual srs_error_t initialize();
// ISrsHttpServeMux
public:
virtual int serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
Expand Down
10 changes: 5 additions & 5 deletions trunk/src/app/srs_app_http_static.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,10 @@ SrsHttpStaticServer::~SrsHttpStaticServer()
_srs_config->unsubscribe(this);
}

int SrsHttpStaticServer::initialize()
srs_error_t SrsHttpStaticServer::initialize()
{
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success;

bool default_root_exists = false;

Expand All @@ -226,7 +227,7 @@ int SrsHttpStaticServer::initialize()
string pmount;
string vhost = conf->arg0();
if ((ret = mount_vhost(vhost, pmount)) != ERROR_SUCCESS) {
return ret;
return srs_error_new(ret, "mount vhost");
}

if (pmount == "/") {
Expand All @@ -240,13 +241,12 @@ int SrsHttpStaticServer::initialize()
// add root
std::string dir = _srs_config->get_http_stream_dir();
if ((ret = mux.handle("/", new SrsVodStream(dir))) != ERROR_SUCCESS) {
srs_error("http: mount root dir=%s failed. ret=%d", dir.c_str(), ret);
return ret;
return srs_error_new(ret, "mount root dir=%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)
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_http_static.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class SrsHttpStaticServer : virtual public ISrsReloadHandler
SrsHttpStaticServer(SrsServer* svr);
virtual ~SrsHttpStaticServer();
public:
virtual int initialize();
virtual srs_error_t initialize();
private:
virtual int mount_vhost(std::string vhost, std::string& pmount);
// interface ISrsReloadHandler.
Expand Down
7 changes: 4 additions & 3 deletions trunk/src/app/srs_app_http_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,16 +704,17 @@ SrsHttpStreamServer::~SrsHttpStreamServer()
}
}

int SrsHttpStreamServer::initialize()
srs_error_t SrsHttpStreamServer::initialize()
{
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success;

// remux rtmp to flv live streaming
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.
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_http_stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class SrsHttpStreamServer : virtual public ISrsReloadHandler
SrsHttpStreamServer(SrsServer* svr);
virtual ~SrsHttpStreamServer();
public:
virtual int initialize();
virtual srs_error_t initialize();
// http flv/ts/mp3/aac stream
public:
virtual int http_mount(SrsSource* s, SrsRequest* r);
Expand Down
4 changes: 4 additions & 0 deletions trunk/src/app/srs_app_kafka.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@ int srs_initialize_kafka()
void srs_dispose_kafka()
{
SrsKafkaProducer* kafka = dynamic_cast<SrsKafkaProducer*>(_srs_kafka);
if (!kafka) {
return;
}

kafka->stop();

srs_freep(kafka);
Expand Down
13 changes: 6 additions & 7 deletions trunk/src/app/srs_app_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,6 @@ void SrsServer::dispose()

srs_error_t SrsServer::initialize(ISrsServerCycle* cycle_handler)
{
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success;

// ensure the time is ok.
Expand All @@ -575,16 +574,16 @@ srs_error_t SrsServer::initialize(ISrsServerCycle* cycle_handler)
signal_manager = new SrsSignalManager(this);

handler = cycle_handler;
if(handler && (ret = handler->initialize()) != ERROR_SUCCESS){
return srs_error_new(ret, "handler initialize");
if(handler && (err = handler->initialize()) != srs_success){
return srs_error_wrap(err, "handler initialize");
}

if ((ret = http_api_mux->initialize()) != ERROR_SUCCESS) {
return srs_error_new(ret, "http api initialize");
if ((err = http_api_mux->initialize()) != srs_success) {
return srs_error_wrap(err, "http api initialize");
}

if ((ret = http_server->initialize()) != ERROR_SUCCESS) {
return srs_error_new(ret, "http server initialize");
if ((err = http_server->initialize()) != srs_success) {
return srs_error_wrap(err, "http server initialize");
}

http_heartbeat = new SrsHttpHeartbeat();
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class ISrsServerCycle
/**
* initialize the cycle handler.
*/
virtual int initialize() = 0;
virtual srs_error_t initialize() = 0;
/**
* do on_cycle while server doing cycle.
*/
Expand Down
10 changes: 6 additions & 4 deletions trunk/src/protocol/srs_http_stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,11 +533,13 @@ SrsHttpServeMux::~SrsHttpServeMux()
hijackers.clear();
}

int SrsHttpServeMux::initialize()
srs_error_t SrsHttpServeMux::initialize()
{
int ret = ERROR_SUCCESS;
// TODO: FIXME: implements it.
return ret;
srs_error_t err = srs_success;

// TODO: FIXME: Implements it.

return err;
}

void SrsHttpServeMux::hijack(ISrsHttpMatchHijacker* h)
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/protocol/srs_http_stack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ class SrsHttpServeMux : public ISrsHttpServeMux
/**
* initialize the http serve mux.
*/
virtual int initialize();
virtual srs_error_t initialize();
/**
* hijack the http match.
*/
Expand Down

0 comments on commit 93710c7

Please sign in to comment.