winlin

support max_connections, drop if exceed.

@@ -185,6 +185,9 @@ usr sys idl wai hiq siq| read writ| recv send| in out | int csw @@ -185,6 +185,9 @@ usr sys idl wai hiq siq| read writ| recv send| in out | int csw
185 * nginx v1.5.0: 139524 lines <br/> 185 * nginx v1.5.0: 139524 lines <br/>
186 186
187 ### History 187 ### History
  188 +* v0.8, 2013-12-06, support max_connections, drop if exceed.
  189 +* v0.8, 2013-12-05, support log_dir, write ffmpeg log to file.
  190 +* v0.8, 2013-12-05, fix the forward/hls/encoder bug.
188 * v0.7, 2013-12-03, v0.7 released. 17605 lines. 191 * v0.7, 2013-12-03, v0.7 released. 17605 lines.
189 * v0.7, 2013-12-01, support dead-loop detect for forwarder and transcoder. 192 * v0.7, 2013-12-01, support dead-loop detect for forwarder and transcoder.
190 * v0.7, 2013-12-01, support all ffmpeg filters and params. 193 * v0.7, 2013-12-01, support all ffmpeg filters and params.
@@ -10,6 +10,10 @@ chunk_size 65000; @@ -10,6 +10,10 @@ chunk_size 65000;
10 # if enabled ffmpeg, each stracoding stream will create a log file. 10 # if enabled ffmpeg, each stracoding stream will create a log file.
11 # default: ./objs/logs 11 # default: ./objs/logs
12 log_dir ./objs/logs; 12 log_dir ./objs/logs;
  13 +# the max connections.
  14 +# if exceed the max connections, server will drop the new connection.
  15 +# default: 2000
  16 +max_connections 2000;
13 # vhost list, the __defaultVhost__ is the default vhost 17 # vhost list, the __defaultVhost__ is the default vhost
14 # for which cannot identify the required vhost. 18 # for which cannot identify the required vhost.
15 # for default demo. 19 # for default demo.
@@ -916,6 +916,18 @@ std::string SrsConfig::get_log_dir() @@ -916,6 +916,18 @@ std::string SrsConfig::get_log_dir()
916 return conf->arg0(); 916 return conf->arg0();
917 } 917 }
918 918
  919 +int SrsConfig::get_max_connections()
  920 +{
  921 + srs_assert(root);
  922 +
  923 + SrsConfDirective* conf = root->get("max_connections");
  924 + if (!conf || conf->arg0().empty()) {
  925 + return 2000;
  926 + }
  927 +
  928 + return ::atoi(conf->arg0().c_str());
  929 +}
  930 +
919 SrsConfDirective* SrsConfig::get_gop_cache(std::string vhost) 931 SrsConfDirective* SrsConfig::get_gop_cache(std::string vhost)
920 { 932 {
921 SrsConfDirective* conf = get_vhost(vhost); 933 SrsConfDirective* conf = get_vhost(vhost);
@@ -141,6 +141,7 @@ public: @@ -141,6 +141,7 @@ public:
141 virtual void get_engine_aparams(SrsConfDirective* engine, std::vector<std::string>& aparams); 141 virtual void get_engine_aparams(SrsConfDirective* engine, std::vector<std::string>& aparams);
142 virtual std::string get_engine_output(SrsConfDirective* engine); 142 virtual std::string get_engine_output(SrsConfDirective* engine);
143 virtual std::string get_log_dir(); 143 virtual std::string get_log_dir();
  144 + virtual int get_max_connections();
144 virtual SrsConfDirective* get_gop_cache(std::string vhost); 145 virtual SrsConfDirective* get_gop_cache(std::string vhost);
145 virtual SrsConfDirective* get_forward(std::string vhost); 146 virtual SrsConfDirective* get_forward(std::string vhost);
146 virtual SrsConfDirective* get_hls(std::string vhost); 147 virtual SrsConfDirective* get_hls(std::string vhost);
@@ -305,6 +305,19 @@ int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd) @@ -305,6 +305,19 @@ int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd)
305 { 305 {
306 int ret = ERROR_SUCCESS; 306 int ret = ERROR_SUCCESS;
307 307
  308 + int max_connections = config->get_max_connections();
  309 + if ((int)conns.size() >= max_connections) {
  310 + int fd = st_netfd_fileno(client_stfd);
  311 +
  312 + srs_error("exceed the max connections, drop client: "
  313 + "clients=%d, max=%d, fd=%d", (int)conns.size(), max_connections, fd);
  314 +
  315 + st_netfd_close(client_stfd);
  316 + ::close(fd);
  317 +
  318 + return ret;
  319 + }
  320 +
308 SrsConnection* conn = NULL; 321 SrsConnection* conn = NULL;
309 if (type == SrsListenerStream) { 322 if (type == SrsListenerStream) {
310 conn = new SrsClient(this, client_stfd); 323 conn = new SrsClient(this, client_stfd);