Skip to content

Commit

Permalink
For #913, refine server utility
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Jun 10, 2017
1 parent ca9f0bd commit a20e2c3
Show file tree
Hide file tree
Showing 15 changed files with 222 additions and 244 deletions.
7 changes: 6 additions & 1 deletion trunk/src/app/srs_app_caster_flv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,13 @@ SrsAppCasterFlv::~SrsAppCasterFlv()
int SrsAppCasterFlv::initialize()
{
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success;

if ((ret = http_mux->handle("/", this)) != ERROR_SUCCESS) {
if ((err = http_mux->handle("/", this)) != srs_success) {
// TODO: FIXME: Use error.
ret = srs_error_code(err);
srs_freep(err);

return ret;
}

Expand Down
5 changes: 2 additions & 3 deletions trunk/src/app/srs_app_http_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,11 @@ SrsHttpServer::~SrsHttpServer()

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 srs_error_new(ret, "handle versin");
if ((err = http_static->mux.handle("/api/v1/versions", new SrsGoApiVersion())) != srs_success) {
return srs_error_wrap(err, "handle versin");
}

if ((err = http_stream->initialize()) != srs_success) {
Expand Down
11 changes: 8 additions & 3 deletions trunk/src/app/srs_app_http_static.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ srs_error_t SrsHttpStaticServer::initialize()
if (!default_root_exists) {
// add root
std::string dir = _srs_config->get_http_stream_dir();
if ((ret = mux.handle("/", new SrsVodStream(dir))) != ERROR_SUCCESS) {
return srs_error_new(ret, "mount root dir=%s", dir.c_str());
if ((err = mux.handle("/", new SrsVodStream(dir))) != srs_success) {
return srs_error_wrap(err, "mount root dir=%s", dir.c_str());
}
srs_trace("http: root mount to %s", dir.c_str());
}
Expand All @@ -252,6 +252,7 @@ srs_error_t SrsHttpStaticServer::initialize()
int SrsHttpStaticServer::mount_vhost(string vhost, string& pmount)
{
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success;

// when vhost disabled, ignore.
if (!_srs_config->get_vhost_enabled(vhost)) {
Expand Down Expand Up @@ -279,7 +280,11 @@ int SrsHttpStaticServer::mount_vhost(string vhost, string& pmount)
}

// mount the http of vhost.
if ((ret = mux.handle(mount, new SrsVodStream(dir))) != ERROR_SUCCESS) {
if ((err = mux.handle(mount, new SrsVodStream(dir))) != srs_success) {
// TODO: FIXME: Use error.
ret = srs_error_code(err);
srs_freep(err);

srs_error("http: mount dir=%s for vhost=%s failed. ret=%d", dir.c_str(), vhost.c_str(), ret);
return ret;
}
Expand Down
7 changes: 6 additions & 1 deletion trunk/src/app/srs_app_http_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,7 @@ srs_error_t SrsHttpStreamServer::initialize()
int SrsHttpStreamServer::http_mount(SrsSource* s, SrsRequest* r)
{
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success;

// the id to identify stream.
std::string sid = r->get_stream_url();
Expand Down Expand Up @@ -767,7 +768,11 @@ int SrsHttpStreamServer::http_mount(SrsSource* s, SrsRequest* r)
// we must register the handler, then start the thread,
// for the thread will cause thread switch context.
// @see https://github.com/ossrs/srs/issues/404
if ((ret = mux.handle(mount, entry->stream)) != ERROR_SUCCESS) {
if ((err = mux.handle(mount, entry->stream)) != srs_success) {
// TODO: FIXME: Use error.
ret = srs_error_code(err);
srs_freep(err);

srs_error("http: mount flv stream for vhost=%s failed. ret=%d", sid.c_str(), ret);
return ret;
}
Expand Down
20 changes: 8 additions & 12 deletions trunk/src/app/srs_app_kafka.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,24 +330,23 @@ ISrsKafkaCluster::~ISrsKafkaCluster()
// @global kafka event producer, user must use srs_initialize_kafka to initialize it.
ISrsKafkaCluster* _srs_kafka = NULL;

int srs_initialize_kafka()
srs_error_t srs_initialize_kafka()
{
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success;

SrsKafkaProducer* kafka = new SrsKafkaProducer();
_srs_kafka = kafka;

if ((ret = kafka->initialize()) != ERROR_SUCCESS) {
srs_error("initialize the kafka producer failed. ret=%d", ret);
return ret;
if ((err = kafka->initialize()) != srs_success) {
return srs_error_wrap(err, "initialize kafka producer");
}

if ((ret = kafka->start()) != ERROR_SUCCESS) {
srs_error("start kafka failed. ret=%d", ret);
return ret;
return srs_error_new(ret, "start kafka producer");
}

return ret;
return err;
}

void srs_dispose_kafka()
Expand Down Expand Up @@ -390,14 +389,11 @@ SrsKafkaProducer::~SrsKafkaProducer()
srs_cond_destroy(metadata_expired);
}

int SrsKafkaProducer::initialize()
srs_error_t SrsKafkaProducer::initialize()
{
int ret = ERROR_SUCCESS;

enabled = _srs_config->get_kafka_enabled();
srs_info("initialize kafka ok, enabled=%d.", enabled);

return ret;
return srs_success;
}

int SrsKafkaProducer::start()
Expand Down
4 changes: 2 additions & 2 deletions trunk/src/app/srs_app_kafka.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class ISrsKafkaCluster
// @global kafka event producer.
extern ISrsKafkaCluster* _srs_kafka;
// kafka initialize and disposer for global object.
extern int srs_initialize_kafka();
extern srs_error_t srs_initialize_kafka();
extern void srs_dispose_kafka();

/**
Expand All @@ -178,7 +178,7 @@ class SrsKafkaProducer : virtual public ISrsCoroutineHandler, virtual public ISr
SrsKafkaProducer();
virtual ~SrsKafkaProducer();
public:
virtual int initialize();
virtual srs_error_t initialize();
virtual int start();
virtual void stop();
// internal: for worker to call task to send object.
Expand Down
Loading

0 comments on commit a20e2c3

Please sign in to comment.