mirror of
https://github.com/ossrs/srs.git
synced 2025-02-15 04:42:04 +00:00
For #913, use complex error for reload utc time
This commit is contained in:
parent
5c9a12e72a
commit
661eb8b37c
9 changed files with 86 additions and 48 deletions
|
@ -1195,7 +1195,6 @@ void SrsConfig::unsubscribe(ISrsReloadHandler* handler)
|
|||
|
||||
srs_error_t SrsConfig::reload()
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
SrsConfig conf;
|
||||
|
@ -1214,8 +1213,8 @@ srs_error_t SrsConfig::reload()
|
|||
return srs_error_wrap(err, "check config");
|
||||
}
|
||||
|
||||
if ((ret = reload_conf(&conf)) != ERROR_SUCCESS) {
|
||||
return srs_error_new(ret, "reload config");
|
||||
if ((err = reload_conf(&conf)) != srs_success) {
|
||||
return srs_error_wrap(err, "reload config");
|
||||
}
|
||||
|
||||
return err;
|
||||
|
@ -1485,9 +1484,10 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int SrsConfig::reload_conf(SrsConfig* conf)
|
||||
srs_error_t SrsConfig::reload_conf(SrsConfig* conf)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
SrsConfDirective* old_root = root;
|
||||
SrsAutoFree(SrsConfDirective, old_root);
|
||||
|
@ -1509,67 +1509,67 @@ int SrsConfig::reload_conf(SrsConfig* conf)
|
|||
// merge config: listen
|
||||
if (!srs_directive_equals(root->get("listen"), old_root->get("listen"))) {
|
||||
if ((ret = do_reload_listen()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
return srs_error_new(ret, "listen");
|
||||
}
|
||||
}
|
||||
|
||||
// merge config: pid
|
||||
if (!srs_directive_equals(root->get("pid"), old_root->get("pid"))) {
|
||||
if ((ret = do_reload_pid()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
return srs_error_new(ret, "pid");;
|
||||
}
|
||||
}
|
||||
|
||||
// merge config: srs_log_tank
|
||||
if (!srs_directive_equals(root->get("srs_log_tank"), old_root->get("srs_log_tank"))) {
|
||||
if ((ret = do_reload_srs_log_tank()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
return srs_error_new(ret, "log tank");;
|
||||
}
|
||||
}
|
||||
|
||||
// merge config: srs_log_level
|
||||
if (!srs_directive_equals(root->get("srs_log_level"), old_root->get("srs_log_level"))) {
|
||||
if ((ret = do_reload_srs_log_level()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
return srs_error_new(ret, "log level");;
|
||||
}
|
||||
}
|
||||
|
||||
// merge config: srs_log_file
|
||||
if (!srs_directive_equals(root->get("srs_log_file"), old_root->get("srs_log_file"))) {
|
||||
if ((ret = do_reload_srs_log_file()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
return srs_error_new(ret, "log file");;
|
||||
}
|
||||
}
|
||||
|
||||
// merge config: max_connections
|
||||
if (!srs_directive_equals(root->get("max_connections"), old_root->get("max_connections"))) {
|
||||
if ((ret = do_reload_max_connections()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
return srs_error_new(ret, "max connections");;
|
||||
}
|
||||
}
|
||||
|
||||
// merge config: utc_time
|
||||
if (!srs_directive_equals(root->get("utc_time"), old_root->get("utc_time"))) {
|
||||
if ((ret = do_reload_utc_time()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
if ((err = do_reload_utc_time()) != srs_success) {
|
||||
return srs_error_wrap(err, "utc time");;
|
||||
}
|
||||
}
|
||||
|
||||
// merge config: pithy_print_ms
|
||||
if (!srs_directive_equals(root->get("pithy_print_ms"), old_root->get("pithy_print_ms"))) {
|
||||
if ((ret = do_reload_pithy_print_ms()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
return srs_error_new(ret, "pithy print ms");;
|
||||
}
|
||||
}
|
||||
|
||||
// merge config: http_api
|
||||
if ((ret = reload_http_api(old_root)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
return srs_error_new(ret, "http api");;
|
||||
}
|
||||
|
||||
// merge config: http_stream
|
||||
if ((ret = reload_http_stream(old_root)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
return srs_error_new(ret, "http steram");;
|
||||
}
|
||||
|
||||
// TODO: FIXME: support reload stream_caster.
|
||||
|
@ -1577,10 +1577,10 @@ int SrsConfig::reload_conf(SrsConfig* conf)
|
|||
|
||||
// merge config: vhost
|
||||
if ((ret = reload_vhost(old_root)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
return srs_error_new(ret, "vhost");;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return err;
|
||||
}
|
||||
|
||||
int SrsConfig::reload_http_api(SrsConfDirective* old_root)
|
||||
|
@ -3015,28 +3015,28 @@ int SrsConfig::raw_set_max_connections(string max_connections, bool& applied)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int SrsConfig::raw_set_utc_time(string utc_time, bool& applied)
|
||||
srs_error_t SrsConfig::raw_set_utc_time(string utc_time, bool& applied)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
applied = false;
|
||||
|
||||
SrsConfDirective* conf = root->get_or_create("utc_time");
|
||||
|
||||
if (conf->arg0() == utc_time) {
|
||||
return ret;
|
||||
return err;
|
||||
}
|
||||
|
||||
conf->args.clear();
|
||||
conf->args.push_back(utc_time);
|
||||
|
||||
if ((ret = do_reload_utc_time()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
if ((err = do_reload_utc_time()) != srs_success) {
|
||||
return srs_error_wrap(err, "reload");
|
||||
}
|
||||
|
||||
applied = true;
|
||||
|
||||
return ret;
|
||||
return err;
|
||||
}
|
||||
|
||||
int SrsConfig::raw_set_pithy_print_ms(string pithy_print_ms, bool& applied)
|
||||
|
@ -3307,21 +3307,20 @@ int SrsConfig::do_reload_max_connections()
|
|||
return ret;
|
||||
}
|
||||
|
||||
int SrsConfig::do_reload_utc_time()
|
||||
srs_error_t SrsConfig::do_reload_utc_time()
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
vector<ISrsReloadHandler*>::iterator it;
|
||||
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
||||
ISrsReloadHandler* subscribe = *it;
|
||||
if ((ret = subscribe->on_reload_utc_time()) != ERROR_SUCCESS) {
|
||||
srs_error("notify subscribes utc_time failed. ret=%d", ret);
|
||||
return ret;
|
||||
if ((err = subscribe->on_reload_utc_time()) != srs_success) {
|
||||
return srs_error_wrap(err, "utc_time");
|
||||
}
|
||||
}
|
||||
srs_trace("reload utc_time success.");
|
||||
|
||||
return ret;
|
||||
return err;
|
||||
}
|
||||
|
||||
int SrsConfig::do_reload_pithy_print_ms()
|
||||
|
|
|
@ -388,7 +388,7 @@ protected:
|
|||
* reload from the config.
|
||||
* @remark, use protected for the utest to override with mock.
|
||||
*/
|
||||
virtual int reload_conf(SrsConfig* conf);
|
||||
virtual srs_error_t reload_conf(SrsConfig* conf);
|
||||
private:
|
||||
/**
|
||||
* reload the http_api section of config.
|
||||
|
@ -476,7 +476,7 @@ public:
|
|||
/**
|
||||
* raw set the global whether use utc time.
|
||||
*/
|
||||
virtual int raw_set_utc_time(std::string utc_time, bool& applied);
|
||||
virtual srs_error_t raw_set_utc_time(std::string utc_time, bool& applied);
|
||||
/**
|
||||
* raw set the global pithy print interval in ms.
|
||||
*/
|
||||
|
@ -516,7 +516,7 @@ private:
|
|||
virtual int do_reload_srs_log_level();
|
||||
virtual int do_reload_srs_log_file();
|
||||
virtual int do_reload_max_connections();
|
||||
virtual int do_reload_utc_time();
|
||||
virtual srs_error_t do_reload_utc_time();
|
||||
virtual int do_reload_pithy_print_ms();
|
||||
virtual int do_reload_vhost_added(std::string vhost);
|
||||
virtual int do_reload_vhost_removed(std::string vhost);
|
||||
|
|
|
@ -85,6 +85,16 @@ int srs_api_response_jsonp_code(ISrsHttpResponseWriter* w, string callback, int
|
|||
return srs_api_response_jsonp(w, callback, obj->dumps());
|
||||
}
|
||||
|
||||
int srs_api_response_jsonp_code(ISrsHttpResponseWriter* w, string callback, srs_error_t err)
|
||||
{
|
||||
SrsJsonObject* obj = SrsJsonAny::object();
|
||||
SrsAutoFree(SrsJsonObject, obj);
|
||||
|
||||
obj->set("code", SrsJsonAny::integer(srs_error_code(err)));
|
||||
|
||||
return srs_api_response_jsonp(w, callback, obj->dumps());
|
||||
}
|
||||
|
||||
int srs_api_response_json(ISrsHttpResponseWriter* w, string data)
|
||||
{
|
||||
SrsHttpHeader* h = w->header();
|
||||
|
@ -105,6 +115,16 @@ int srs_api_response_json_code(ISrsHttpResponseWriter* w, int code)
|
|||
return srs_api_response_json(w, obj->dumps());
|
||||
}
|
||||
|
||||
int srs_api_response_json_code(ISrsHttpResponseWriter* w, srs_error_t err)
|
||||
{
|
||||
SrsJsonObject* obj = SrsJsonAny::object();
|
||||
SrsAutoFree(SrsJsonObject, obj);
|
||||
|
||||
obj->set("code", SrsJsonAny::integer(srs_error_code(err)));
|
||||
|
||||
return srs_api_response_json(w, obj->dumps());
|
||||
}
|
||||
|
||||
int srs_api_response(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string json)
|
||||
{
|
||||
// no jsonp, directly response.
|
||||
|
@ -129,6 +149,26 @@ int srs_api_response_code(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, int cod
|
|||
return srs_api_response_jsonp_code(w, callback, code);
|
||||
}
|
||||
|
||||
int srs_api_response_code(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, srs_error_t err)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
// no jsonp, directly response.
|
||||
if (!r->is_jsonp()) {
|
||||
ret = srs_api_response_json_code(w, err);
|
||||
} else {
|
||||
// jsonp, get function name from query("callback")
|
||||
string callback = r->query_get("callback");
|
||||
ret = srs_api_response_jsonp_code(w, callback, err);
|
||||
}
|
||||
|
||||
if (err != srs_success) {
|
||||
srs_warn("error %s", srs_error_desc(err).c_str());
|
||||
srs_freep(err);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
SrsGoApiRoot::SrsGoApiRoot()
|
||||
{
|
||||
}
|
||||
|
@ -852,6 +892,7 @@ SrsGoApiRaw::~SrsGoApiRaw()
|
|||
int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
std::string rpc = r->query_get("rpc");
|
||||
|
||||
|
@ -1126,9 +1167,8 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
|||
return srs_api_response_code(w, r, ret);
|
||||
}
|
||||
|
||||
if ((ret = _srs_config->raw_set_utc_time(srs_config_bool2switch(value), applied)) != ERROR_SUCCESS) {
|
||||
srs_error("raw api update utc_time=%s failed. ret=%d", value.c_str(), ret);
|
||||
return srs_api_response_code(w, r, ret);
|
||||
if ((err = _srs_config->raw_set_utc_time(srs_config_bool2switch(value), applied)) != srs_success) {
|
||||
return srs_api_response_code(w, r, srs_error_wrap(err, "raw api update utc_time=%s", value.c_str()));
|
||||
}
|
||||
} else if (scope == "pithy_print_ms") {
|
||||
int ppmv = ::atoi(value.c_str());
|
||||
|
|
|
@ -199,11 +199,11 @@ void SrsFastLog::error(const char* tag, int context_id, const char* fmt, ...)
|
|||
write_log(fd, log_data, size, SrsLogLevelError);
|
||||
}
|
||||
|
||||
int SrsFastLog::on_reload_utc_time()
|
||||
srs_error_t SrsFastLog::on_reload_utc_time()
|
||||
{
|
||||
utc = _srs_config->get_utc_time();
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
return srs_success;
|
||||
}
|
||||
|
||||
int SrsFastLog::on_reload_log_tank()
|
||||
|
|
|
@ -65,7 +65,7 @@ public:
|
|||
virtual void error(const char* tag, int context_id, const char* fmt, ...);
|
||||
// interface ISrsReloadHandler.
|
||||
public:
|
||||
virtual int on_reload_utc_time();
|
||||
virtual srs_error_t on_reload_utc_time();
|
||||
virtual int on_reload_log_tank();
|
||||
virtual int on_reload_log_level();
|
||||
virtual int on_reload_log_file();
|
||||
|
|
|
@ -40,9 +40,9 @@ int ISrsReloadHandler::on_reload_listen()
|
|||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
int ISrsReloadHandler::on_reload_utc_time()
|
||||
srs_error_t ISrsReloadHandler::on_reload_utc_time()
|
||||
{
|
||||
return ERROR_SUCCESS;
|
||||
return srs_success;
|
||||
}
|
||||
|
||||
int ISrsReloadHandler::on_reload_max_conns()
|
||||
|
|
|
@ -41,7 +41,7 @@ public:
|
|||
ISrsReloadHandler();
|
||||
virtual ~ISrsReloadHandler();
|
||||
public:
|
||||
virtual int on_reload_utc_time();
|
||||
virtual srs_error_t on_reload_utc_time();
|
||||
virtual int on_reload_max_conns();
|
||||
virtual int on_reload_listen();
|
||||
virtual int on_reload_pid();
|
||||
|
|
|
@ -150,7 +150,7 @@ srs_error_t SrsBufferListener::listen(string i, int p)
|
|||
listener = new SrsTcpListener(this, ip, port);
|
||||
|
||||
if ((err = listener->listen()) != srs_success) {
|
||||
return srs_error_wrap(err, "buffer tcp listen %s:%d", ip.c_str(), port);
|
||||
return srs_error_wrap(err, "buffered tcp listen");
|
||||
}
|
||||
|
||||
string v = srs_listener_type2string(type);
|
||||
|
@ -1227,7 +1227,8 @@ srs_error_t SrsServer::fd2conn(SrsListenerType type, srs_netfd_t stfd, SrsConnec
|
|||
fd, max_connections, (int)conns.size(), srs_error_desc(err).c_str());
|
||||
}
|
||||
if ((int)conns.size() >= max_connections) {
|
||||
return srs_error_new(ERROR_EXCEED_CONNECTIONS, "drop fd=%d, max=%d, cur=%d for exceed connection limits",
|
||||
return srs_error_new(ERROR_EXCEED_CONNECTIONS,
|
||||
"drop fd=%d, max=%d, cur=%d for exceed connection limits",
|
||||
fd, max_connections, (int)conns.size());
|
||||
}
|
||||
|
||||
|
@ -1278,8 +1279,7 @@ void SrsServer::remove(ISrsConnection* c)
|
|||
stat->kbps_add_delta(conn);
|
||||
stat->on_disconnect(conn->srs_id());
|
||||
|
||||
// all connections are created by server,
|
||||
// so we free it here.
|
||||
// use manager to free it async.
|
||||
conn_manager->remove(c);
|
||||
}
|
||||
|
||||
|
|
|
@ -285,7 +285,6 @@ MockSrsReloadConfig::~MockSrsReloadConfig()
|
|||
|
||||
srs_error_t MockSrsReloadConfig::do_reload(string buf)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
MockSrsReloadConfig conf;
|
||||
|
@ -293,8 +292,8 @@ srs_error_t MockSrsReloadConfig::do_reload(string buf)
|
|||
return srs_error_wrap(err, "parse");
|
||||
}
|
||||
|
||||
if ((ret = MockSrsConfig::reload_conf(&conf)) != ERROR_SUCCESS) {
|
||||
return srs_error_new(ret, "reload conf");
|
||||
if ((err = MockSrsConfig::reload_conf(&conf)) != srs_success) {
|
||||
return srs_error_wrap(err, "reload conf");
|
||||
}
|
||||
|
||||
return err;
|
||||
|
|
Loading…
Reference in a new issue