From 96e0e699dda76e0d4029b0b8e3202601b16c98e9 Mon Sep 17 00:00:00 2001 From: winlin Date: Fri, 18 Jul 2014 10:21:34 +0800 Subject: [PATCH] refine the get port, return a vector contains ports. --- trunk/src/app/srs_app_config.cpp | 31 ++++++++++++++++++++----------- trunk/src/app/srs_app_config.hpp | 17 +++++++++++++---- trunk/src/app/srs_app_ingest.cpp | 6 +++--- trunk/src/app/srs_app_server.cpp | 8 ++++---- 4 files changed, 40 insertions(+), 22 deletions(-) diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 505ffa403..04d012e19 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -1175,15 +1175,6 @@ int SrsConfig::parse_buffer(_srs_internal::SrsConfigBuffer* buffer) return ret; } - SrsConfDirective* conf = NULL; - // check rtmp port specified by directive listen. - if ((conf = get_listen()) == NULL || conf->args.size() == 0) { - ret = ERROR_SYSTEM_CONFIG_INVALID; - srs_error("line %d: conf error, " - "directive \"listen\" is empty, ret=%d", (conf? conf->conf_line:0), ret); - return ret; - } - // check root directives. for (int i = 0; i < (int)root->directives.size(); i++) { SrsConfDirective* conf = root->at(i); @@ -1200,6 +1191,13 @@ int SrsConfig::parse_buffer(_srs_internal::SrsConfigBuffer* buffer) } } + // check rtmp port specified by directive listen. + if (_srs_config->get_listen().size() <= 0) { + ret = ERROR_SYSTEM_CONFIG_INVALID; + srs_error("directive \"listen\" is empty, ret=%d", ret); + return ret; + } + // TODO: FIXME: check others. // check log @@ -1259,9 +1257,20 @@ int SrsConfig::get_max_connections() return ::atoi(conf->arg0().c_str()); } -SrsConfDirective* SrsConfig::get_listen() +vector SrsConfig::get_listen() { - return root->get("listen"); + std::vector ports; + + SrsConfDirective* conf = root->get("listen"); + if (!conf) { + return ports; + } + + for (int i = 0; i < (int)conf->args.size(); i++) { + ports.push_back(conf->args.at(i)); + } + + return ports; } string SrsConfig::get_pid_file() diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index 5efdc1d1a..5a34c27d9 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -345,17 +345,26 @@ public: */ virtual SrsConfDirective* get_root(); /** - * + * get the deamon config. + * if true, SRS will run in deamon mode, fork and fork to reap the + * grand-child process to init process. */ virtual bool get_deamon(); /** - * + * get the max connections limit of system. + * if exceed the max connection, SRS will disconnect the connection. + * @remark, linux will limit the connections of each process, + * for example, when you need SRS to service 10000+ connections, + * user must use "ulimit -HSn 10000" and config the max connections + * of SRS. */ virtual int get_max_connections(); /** - * + * get the listen port of SRS. + * user can specifies multiple listen ports, + * each args of directive is a listen port. */ - virtual SrsConfDirective* get_listen(); + virtual std::vector get_listen(); /** * */ diff --git a/trunk/src/app/srs_app_ingest.cpp b/trunk/src/app/srs_app_ingest.cpp index 8d60e7001..16f80208f 100644 --- a/trunk/src/app/srs_app_ingest.cpp +++ b/trunk/src/app/srs_app_ingest.cpp @@ -232,9 +232,9 @@ int SrsIngester::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective* vhost, S { int ret = ERROR_SUCCESS; - SrsConfDirective* listen = _srs_config->get_listen(); - srs_assert(listen->args.size() > 0); - std::string port = listen->arg0(); + std::vector ports = _srs_config->get_listen(); + srs_assert(ports.size() > 0); + std::string port = ports[0]; std::string output = _srs_config->get_engine_output(engine); // output stream, to other/self server diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index bdea60094..3b06bedcf 100644 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -759,16 +759,16 @@ int SrsServer::listen_rtmp() int ret = ERROR_SUCCESS; // stream service port. - SrsConfDirective* conf = _srs_config->get_listen(); - srs_assert(conf); + std::vector ports = _srs_config->get_listen(); + srs_assert((int)ports.size() > 0); close_listeners(SrsListenerRtmpStream); - for (int i = 0; i < (int)conf->args.size(); i++) { + for (int i = 0; i < (int)ports.size(); i++) { SrsListener* listener = new SrsListener(this, SrsListenerRtmpStream); listeners.push_back(listener); - int port = ::atoi(conf->args.at(i).c_str()); + int port = ::atoi(ports[i].c_str()); if ((ret = listener->listen(port)) != ERROR_SUCCESS) { srs_error("RTMP stream listen at port %d failed. ret=%d", port, ret); return ret;