winlin

refine the get port, return a vector<string> contains ports.

... ... @@ -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<string> SrsConfig::get_listen()
{
return root->get("listen");
std::vector<string> 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()
... ...
... ... @@ -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<std::string> get_listen();
/**
*
*/
... ...
... ... @@ -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<std::string> 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
... ...
... ... @@ -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<std::string> 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;
... ...