diff --git a/README.md b/README.md
index a973ae777..cb599875b 100755
--- a/README.md
+++ b/README.md
@@ -185,6 +185,9 @@ usr sys idl wai hiq siq| read writ| recv send| in out | int csw
* nginx v1.5.0: 139524 lines
### 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.
diff --git a/trunk/conf/srs.conf b/trunk/conf/srs.conf
index 0748b3cca..94c385c67 100755
--- a/trunk/conf/srs.conf
+++ b/trunk/conf/srs.conf
@@ -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.
diff --git a/trunk/src/core/srs_core_config.cpp b/trunk/src/core/srs_core_config.cpp
index c5aeaa84d..e7e5e3651 100644
--- a/trunk/src/core/srs_core_config.cpp
+++ b/trunk/src/core/srs_core_config.cpp
@@ -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);
diff --git a/trunk/src/core/srs_core_config.hpp b/trunk/src/core/srs_core_config.hpp
index 612876819..ab78003b7 100644
--- a/trunk/src/core/srs_core_config.hpp
+++ b/trunk/src/core/srs_core_config.hpp
@@ -141,6 +141,7 @@ public:
virtual void get_engine_aparams(SrsConfDirective* engine, std::vector& 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);
diff --git a/trunk/src/core/srs_core_server.cpp b/trunk/src/core/srs_core_server.cpp
index 6dc089710..ab6e22102 100644
--- a/trunk/src/core/srs_core_server.cpp
+++ b/trunk/src/core/srs_core_server.cpp
@@ -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);