winlin

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

@@ -1175,15 +1175,6 @@ int SrsConfig::parse_buffer(_srs_internal::SrsConfigBuffer* buffer) @@ -1175,15 +1175,6 @@ int SrsConfig::parse_buffer(_srs_internal::SrsConfigBuffer* buffer)
1175 return ret; 1175 return ret;
1176 } 1176 }
1177 1177
1178 - SrsConfDirective* conf = NULL;  
1179 - // check rtmp port specified by directive listen.  
1180 - if ((conf = get_listen()) == NULL || conf->args.size() == 0) {  
1181 - ret = ERROR_SYSTEM_CONFIG_INVALID;  
1182 - srs_error("line %d: conf error, "  
1183 - "directive \"listen\" is empty, ret=%d", (conf? conf->conf_line:0), ret);  
1184 - return ret;  
1185 - }  
1186 -  
1187 // check root directives. 1178 // check root directives.
1188 for (int i = 0; i < (int)root->directives.size(); i++) { 1179 for (int i = 0; i < (int)root->directives.size(); i++) {
1189 SrsConfDirective* conf = root->at(i); 1180 SrsConfDirective* conf = root->at(i);
@@ -1200,6 +1191,13 @@ int SrsConfig::parse_buffer(_srs_internal::SrsConfigBuffer* buffer) @@ -1200,6 +1191,13 @@ int SrsConfig::parse_buffer(_srs_internal::SrsConfigBuffer* buffer)
1200 } 1191 }
1201 } 1192 }
1202 1193
  1194 + // check rtmp port specified by directive listen.
  1195 + if (_srs_config->get_listen().size() <= 0) {
  1196 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1197 + srs_error("directive \"listen\" is empty, ret=%d", ret);
  1198 + return ret;
  1199 + }
  1200 +
1203 // TODO: FIXME: check others. 1201 // TODO: FIXME: check others.
1204 1202
1205 // check log 1203 // check log
@@ -1259,9 +1257,20 @@ int SrsConfig::get_max_connections() @@ -1259,9 +1257,20 @@ int SrsConfig::get_max_connections()
1259 return ::atoi(conf->arg0().c_str()); 1257 return ::atoi(conf->arg0().c_str());
1260 } 1258 }
1261 1259
1262 -SrsConfDirective* SrsConfig::get_listen() 1260 +vector<string> SrsConfig::get_listen()
1263 { 1261 {
1264 - return root->get("listen"); 1262 + std::vector<string> ports;
  1263 +
  1264 + SrsConfDirective* conf = root->get("listen");
  1265 + if (!conf) {
  1266 + return ports;
  1267 + }
  1268 +
  1269 + for (int i = 0; i < (int)conf->args.size(); i++) {
  1270 + ports.push_back(conf->args.at(i));
  1271 + }
  1272 +
  1273 + return ports;
1265 } 1274 }
1266 1275
1267 string SrsConfig::get_pid_file() 1276 string SrsConfig::get_pid_file()
@@ -345,17 +345,26 @@ public: @@ -345,17 +345,26 @@ public:
345 */ 345 */
346 virtual SrsConfDirective* get_root(); 346 virtual SrsConfDirective* get_root();
347 /** 347 /**
348 - * 348 + * get the deamon config.
  349 + * if true, SRS will run in deamon mode, fork and fork to reap the
  350 + * grand-child process to init process.
349 */ 351 */
350 virtual bool get_deamon(); 352 virtual bool get_deamon();
351 /** 353 /**
352 - * 354 + * get the max connections limit of system.
  355 + * if exceed the max connection, SRS will disconnect the connection.
  356 + * @remark, linux will limit the connections of each process,
  357 + * for example, when you need SRS to service 10000+ connections,
  358 + * user must use "ulimit -HSn 10000" and config the max connections
  359 + * of SRS.
353 */ 360 */
354 virtual int get_max_connections(); 361 virtual int get_max_connections();
355 /** 362 /**
356 - * 363 + * get the listen port of SRS.
  364 + * user can specifies multiple listen ports,
  365 + * each args of directive is a listen port.
357 */ 366 */
358 - virtual SrsConfDirective* get_listen(); 367 + virtual std::vector<std::string> get_listen();
359 /** 368 /**
360 * 369 *
361 */ 370 */
@@ -232,9 +232,9 @@ int SrsIngester::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective* vhost, S @@ -232,9 +232,9 @@ int SrsIngester::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective* vhost, S
232 { 232 {
233 int ret = ERROR_SUCCESS; 233 int ret = ERROR_SUCCESS;
234 234
235 - SrsConfDirective* listen = _srs_config->get_listen();  
236 - srs_assert(listen->args.size() > 0);  
237 - std::string port = listen->arg0(); 235 + std::vector<std::string> ports = _srs_config->get_listen();
  236 + srs_assert(ports.size() > 0);
  237 + std::string port = ports[0];
238 238
239 std::string output = _srs_config->get_engine_output(engine); 239 std::string output = _srs_config->get_engine_output(engine);
240 // output stream, to other/self server 240 // output stream, to other/self server
@@ -759,16 +759,16 @@ int SrsServer::listen_rtmp() @@ -759,16 +759,16 @@ int SrsServer::listen_rtmp()
759 int ret = ERROR_SUCCESS; 759 int ret = ERROR_SUCCESS;
760 760
761 // stream service port. 761 // stream service port.
762 - SrsConfDirective* conf = _srs_config->get_listen();  
763 - srs_assert(conf); 762 + std::vector<std::string> ports = _srs_config->get_listen();
  763 + srs_assert((int)ports.size() > 0);
764 764
765 close_listeners(SrsListenerRtmpStream); 765 close_listeners(SrsListenerRtmpStream);
766 766
767 - for (int i = 0; i < (int)conf->args.size(); i++) { 767 + for (int i = 0; i < (int)ports.size(); i++) {
768 SrsListener* listener = new SrsListener(this, SrsListenerRtmpStream); 768 SrsListener* listener = new SrsListener(this, SrsListenerRtmpStream);
769 listeners.push_back(listener); 769 listeners.push_back(listener);
770 770
771 - int port = ::atoi(conf->args.at(i).c_str()); 771 + int port = ::atoi(ports[i].c_str());
772 if ((ret = listener->listen(port)) != ERROR_SUCCESS) { 772 if ((ret = listener->listen(port)) != ERROR_SUCCESS) {
773 srs_error("RTMP stream listen at port %d failed. ret=%d", port, ret); 773 srs_error("RTMP stream listen at port %d failed. ret=%d", port, ret);
774 return ret; 774 return ret;