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:
parent
4827777035
commit
679e851f07
5 changed files with 33 additions and 0 deletions
|
@ -185,6 +185,9 @@ usr sys idl wai hiq siq| read writ| recv send| in out | int csw
|
|||
* nginx v1.5.0: 139524 lines <br/>
|
||||
|
||||
### History
|
||||
* v0.8, 2013-12-06, support max_connections, drop if exceed.
|
||||
* v0.8, 2013-12-05, support log_dir, write ffmpeg log to file.
|
||||
* v0.8, 2013-12-05, fix the forward/hls/encoder bug.
|
||||
* v0.7, 2013-12-03, v0.7 released. 17605 lines.
|
||||
* v0.7, 2013-12-01, support dead-loop detect for forwarder and transcoder.
|
||||
* v0.7, 2013-12-01, support all ffmpeg filters and params.
|
||||
|
|
|
@ -10,6 +10,10 @@ chunk_size 65000;
|
|||
# if enabled ffmpeg, each stracoding stream will create a log file.
|
||||
# default: ./objs/logs
|
||||
log_dir ./objs/logs;
|
||||
# the max connections.
|
||||
# if exceed the max connections, server will drop the new connection.
|
||||
# default: 2000
|
||||
max_connections 2000;
|
||||
# vhost list, the __defaultVhost__ is the default vhost
|
||||
# for which cannot identify the required vhost.
|
||||
# for default demo.
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue