For #913, config and log support complex error.

pull/978/head
winlin 8 years ago
parent 860aac3e50
commit b5c14938d9

File diff suppressed because it is too large Load Diff

@ -73,7 +73,7 @@ namespace _srs_internal
/**
* fullfill the buffer with content of file specified by filename.
*/
virtual int fullfill(const char* filename);
virtual srs_error_t fullfill(const char* filename);
/**
* whether buffer is empty.
*/
@ -119,7 +119,7 @@ extern std::string srs_config_bool2switch(const std::string& sbool);
* so we must transform the vhost directive anytime load the config.
* @param root the root directive to transform, in and out parameter.
*/
extern int srs_config_transform_vhost(SrsConfDirective* root);
extern srs_error_t srs_config_transform_vhost(SrsConfDirective* root);
// @global config object.
extern SrsConfig* _srs_config;
@ -239,7 +239,7 @@ public:
/**
* parse config directive from file buffer.
*/
virtual int parse(_srs_internal::SrsConfigBuffer* buffer);
virtual srs_error_t parse(_srs_internal::SrsConfigBuffer* buffer);
/**
* persistence the directive to writer.
* @param level, the root is level0, all its directives are level1, and so on.
@ -277,7 +277,7 @@ private:
* 2. initialize the directive by args, args[0] is name, args[1-N] is args of directive,
* 3. if ret flag indicates there are child-directives, read_conf(directive, block) recursively.
*/
virtual int parse_conf(_srs_internal::SrsConfigBuffer* buffer, SrsDirectiveType type);
virtual srs_error_t parse_conf(_srs_internal::SrsConfigBuffer* buffer, SrsDirectiveType type);
/**
* read a token from buffer.
* a token, is the directive args and a flag indicates whether has child-directives.
@ -285,7 +285,7 @@ private:
* @param line_start, the actual start line of directive.
* @return, an error code indicates error or has child-directives.
*/
virtual int read_token(_srs_internal::SrsConfigBuffer* buffer, std::vector<std::string>& args, int& line_start);
virtual srs_error_t read_token(_srs_internal::SrsConfigBuffer* buffer, std::vector<std::string>& args, int& line_start);
};
/**
@ -412,12 +412,12 @@ public:
/**
* parse the cli, the main(argc,argv) function.
*/
virtual int parse_options(int argc, char** argv);
virtual srs_error_t parse_options(int argc, char** argv);
/**
* initialize the cwd for server,
* because we may change the workdir.
*/
virtual int initialize_cwd();
virtual srs_error_t initialize_cwd();
/**
* persistence current config to file.
*/
@ -530,7 +530,7 @@ private:
/**
* parse each argv.
*/
virtual int parse_argv(int& i, char** argv);
virtual srs_error_t parse_argv(int& i, char** argv);
/**
* print help and exit.
*/
@ -539,21 +539,21 @@ public:
/**
* parse the config file, which is specified by cli.
*/
virtual int parse_file(const char* filename);
virtual srs_error_t parse_file(const char* filename);
/**
* check the parsed config.
*/
virtual int check_config();
virtual srs_error_t check_config();
protected:
virtual int check_normal_config();
virtual int check_number_connections();
virtual srs_error_t check_normal_config();
virtual srs_error_t check_number_connections();
protected:
/**
* parse config from the buffer.
* @param buffer, the config buffer, user must delete it.
* @remark, use protected for the utest to override with mock.
*/
virtual int parse_buffer(_srs_internal::SrsConfigBuffer* buffer);
virtual srs_error_t parse_buffer(_srs_internal::SrsConfigBuffer* buffer);
// global env
public:
/**

@ -68,10 +68,8 @@ SrsFastLog::~SrsFastLog()
}
}
int SrsFastLog::initialize()
srs_error_t SrsFastLog::initialize()
{
int ret = ERROR_SUCCESS;
if (_srs_config) {
_srs_config->subscribe(this);
@ -80,7 +78,7 @@ int SrsFastLog::initialize()
utc = _srs_config->get_utc_time();
}
return ret;
return srs_success;
}
void SrsFastLog::reopen()

@ -56,7 +56,7 @@ public:
virtual ~SrsFastLog();
// interface ISrsLog
public:
virtual int initialize();
virtual srs_error_t initialize();
virtual void reopen();
virtual void verbose(const char* tag, int context_id, const char* fmt, ...);
virtual void info(const char* tag, int context_id, const char* fmt, ...);

@ -33,9 +33,9 @@ ISrsLog::~ISrsLog()
{
}
int ISrsLog::initialize()
srs_error_t ISrsLog::initialize()
{
return ERROR_SUCCESS;
return srs_success;
}
void ISrsLog::reopen()

@ -65,7 +65,7 @@ public:
/**
* initialize log utilities.
*/
virtual int initialize();
virtual srs_error_t initialize();
/**
* reopen the log file for log rotate.
*/

@ -67,9 +67,9 @@ extern const char* _srs_version;
/**
* main entrance.
*/
int main(int argc, char** argv)
srs_error_t do_main(int argc, char** argv)
{
int ret = ERROR_SUCCESS;
srs_error_t err= srs_success;
// TODO: support both little and big endian.
srs_assert(srs_is_little_endian());
@ -98,23 +98,23 @@ int main(int argc, char** argv)
// never use srs log(srs_trace, srs_error, etc) before config parse the option,
// which will load the log config and apply it.
if ((ret = _srs_config->parse_options(argc, argv)) != ERROR_SUCCESS) {
return ret;
if ((err = _srs_config->parse_options(argc, argv)) != srs_success) {
return srs_error_wrap(err, "config parse options");
}
// change the work dir and set cwd.
int r0 = 0;
string cwd = _srs_config->get_work_dir();
if (!cwd.empty() && cwd != "./" && (ret = chdir(cwd.c_str())) != ERROR_SUCCESS) {
srs_error("change cwd to %s failed. ret=%d", cwd.c_str(), ret);
return ret;
if (!cwd.empty() && cwd != "./" && (r0 = chdir(cwd.c_str())) == -1) {
return srs_error_new(-1, "chdir to %s, r0=%d", cwd.c_str(), r0);
}
if ((ret = _srs_config->initialize_cwd()) != ERROR_SUCCESS) {
return ret;
if ((err = _srs_config->initialize_cwd()) != srs_success) {
return srs_error_wrap(err, "config cwd");
}
// config parsed, initialize log.
if ((ret = _srs_log->initialize()) != ERROR_SUCCESS) {
return ret;
if ((err = _srs_log->initialize()) != srs_success) {
return srs_error_wrap(err, "log initialize");
}
// config already applied to log.
@ -172,8 +172,8 @@ int main(int argc, char** argv)
}
// we check the config when the log initialized.
if ((ret = _srs_config->check_config()) != ERROR_SUCCESS) {
return ret;
if ((err = _srs_config->check_config()) != srs_success) {
return srs_error_wrap(err, "check config");
}
// features
@ -182,12 +182,21 @@ int main(int argc, char** argv)
SrsServer* svr = new SrsServer();
SrsAutoFree(SrsServer, svr);
srs_error_t err = run(svr);
if ((err = run(svr)) != srs_success) {
return srs_error_wrap(err, "run");
}
return err;
}
int main(int argc, char** argv) {
srs_error_t err = do_main(argc, argv);
if (err != srs_success) {
srs_error("Failed, %s", srs_error_desc(err).c_str());
}
ret = srs_error_code(err);
int ret = srs_error_code(err);
srs_freep(err);
return ret;
}

@ -91,9 +91,9 @@ SrsConsoleLog::~SrsConsoleLog()
srs_freepa(buffer);
}
int SrsConsoleLog::initialize()
srs_error_t SrsConsoleLog::initialize()
{
return ERROR_SUCCESS;
return srs_success;
}
void SrsConsoleLog::reopen()

@ -65,7 +65,7 @@ public:
virtual ~SrsConsoleLog();
// interface ISrsLog
public:
virtual int initialize();
virtual srs_error_t initialize();
virtual void reopen();
virtual void verbose(const char* tag, int context_id, const char* fmt, ...);
virtual void info(const char* tag, int context_id, const char* fmt, ...);

@ -50,9 +50,9 @@ MockSrsConfigBuffer::~MockSrsConfigBuffer()
{
}
int MockSrsConfigBuffer::fullfill(const char* /*filename*/)
srs_error_t MockSrsConfigBuffer::fullfill(const char* /*filename*/)
{
return ERROR_SUCCESS;
return srs_success;
}
MockSrsConfig::MockSrsConfig()
@ -63,22 +63,25 @@ MockSrsConfig::~MockSrsConfig()
{
}
int MockSrsConfig::parse(string buf)
srs_error_t MockSrsConfig::parse(string buf)
{
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success;
MockSrsConfigBuffer buffer(buf);
if ((ret = parse_buffer(&buffer)) != ERROR_SUCCESS) {
return ret;
if ((err = parse_buffer(&buffer)) != srs_success) {
return srs_error_wrap(err, "parse buffer");
}
if ((ret = srs_config_transform_vhost(root)) != ERROR_SUCCESS) {
srs_error("transform config failed. ret=%d", ret);
return ret;
if ((err = srs_config_transform_vhost(root)) != srs_success) {
return srs_error_wrap(err, "transform config");
}
return check_normal_config();
if ((err = check_normal_config()) != srs_success) {
return srs_error_wrap(err, "check normal config");
}
return err;
}
#ifdef ENABLE_UTEST_CONFIG

@ -41,7 +41,7 @@ public:
MockSrsConfigBuffer(std::string buf);
virtual ~MockSrsConfigBuffer();
public:
virtual int fullfill(const char* filename);
virtual srs_error_t fullfill(const char* filename);
};
class MockSrsConfig : public SrsConfig
@ -50,7 +50,7 @@ public:
MockSrsConfig();
virtual ~MockSrsConfig();
public:
virtual int parse(std::string buf);
virtual srs_error_t parse(std::string buf);
};
#endif

@ -283,16 +283,21 @@ MockSrsReloadConfig::~MockSrsReloadConfig()
{
}
int MockSrsReloadConfig::do_reload(string buf)
srs_error_t MockSrsReloadConfig::do_reload(string buf)
{
int ret = ERROR_SUCCESS;
srs_error_t err = srs_success;
MockSrsReloadConfig conf;
if ((ret = conf.parse(buf)) != ERROR_SUCCESS) {
return ret;
if ((err = conf.parse(buf)) != srs_success) {
return srs_error_wrap(err, "parse");
}
if ((ret = MockSrsConfig::reload_conf(&conf)) != ERROR_SUCCESS) {
return srs_error_new(ret, "reload conf");
}
return MockSrsConfig::reload_conf(&conf);
return err;
}
#ifdef ENABLE_UTEST_RELOAD

@ -99,7 +99,7 @@ public:
MockSrsReloadConfig();
virtual ~MockSrsReloadConfig();
public:
virtual int do_reload(std::string buf);
virtual srs_error_t do_reload(std::string buf);
};
#endif

Loading…
Cancel
Save