1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

support max_connections, drop if exceed.

This commit is contained in:
winlin 2013-12-06 11:00:37 +08:00
parent 4827777035
commit 679e851f07
5 changed files with 33 additions and 0 deletions

View file

@ -916,6 +916,18 @@ std::string SrsConfig::get_log_dir()
return conf->arg0();
}
int SrsConfig::get_max_connections()
{
srs_assert(root);
SrsConfDirective* conf = root->get("max_connections");
if (!conf || conf->arg0().empty()) {
return 2000;
}
return ::atoi(conf->arg0().c_str());
}
SrsConfDirective* SrsConfig::get_gop_cache(std::string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);

View file

@ -141,6 +141,7 @@ public:
virtual void get_engine_aparams(SrsConfDirective* engine, std::vector<std::string>& aparams);
virtual std::string get_engine_output(SrsConfDirective* engine);
virtual std::string get_log_dir();
virtual int get_max_connections();
virtual SrsConfDirective* get_gop_cache(std::string vhost);
virtual SrsConfDirective* get_forward(std::string vhost);
virtual SrsConfDirective* get_hls(std::string vhost);

View file

@ -305,6 +305,19 @@ int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd)
{
int ret = ERROR_SUCCESS;
int max_connections = config->get_max_connections();
if ((int)conns.size() >= max_connections) {
int fd = st_netfd_fileno(client_stfd);
srs_error("exceed the max connections, drop client: "
"clients=%d, max=%d, fd=%d", (int)conns.size(), max_connections, fd);
st_netfd_close(client_stfd);
::close(fd);
return ret;
}
SrsConnection* conn = NULL;
if (type == SrsListenerStream) {
conn = new SrsClient(this, client_stfd);