diff --git a/trunk/src/app/srs_app_rtmp_conn.cpp b/trunk/src/app/srs_app_rtmp_conn.cpp index 6e4c5d9ba..bd98b1801 100644 --- a/trunk/src/app/srs_app_rtmp_conn.cpp +++ b/trunk/src/app/srs_app_rtmp_conn.cpp @@ -410,7 +410,7 @@ int SrsRtmpConn::do_cycle() srs_info("discovery app success. schema=%s, vhost=%s, port=%s, app=%s", req->schema.c_str(), req->vhost.c_str(), req->port.c_str(), req->app.c_str()); - if (req->schema.empty() || req->vhost.empty() || req->app.empty()) { + if (req->schema.empty() || req->vhost.empty() || req->port == 0 || req->app.empty()) { ret = ERROR_RTMP_REQ_TCURL; srs_error("discovery tcUrl failed. " "tcUrl=%s, schema=%s, vhost=%s, port=%d, app=%s, ret=%d", diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp old mode 100755 new mode 100644 index e049ad500..93897b545 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -968,11 +968,11 @@ int SrsServer::do_cycle() // the deamon thread, update the time cache while (true) { - if(handler && (ret = handler->on_cycle((int)conns.size())) != ERROR_SUCCESS){ + if (handler && (ret = handler->on_cycle()) != ERROR_SUCCESS) { srs_error("cycle handle failed. ret=%d", ret); return ret; } - + // the interval in config. int heartbeat_max_resolution = (int)(_srs_config->get_heartbeat_interval() / SRS_SYS_CYCLE_INTERVAL); @@ -1254,15 +1254,20 @@ int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd) int ret = ERROR_SUCCESS; int fd = st_netfd_fileno(client_stfd); - + + // check connection limitation. int max_connections = _srs_config->get_max_connections(); + if (handler && (ret = handler->on_accept_client(max_connections, (int)conns.size()) != ERROR_SUCCESS)) { + srs_error("handle accept client failed, drop client: " + "clients=%d, max=%d, fd=%d. ret=%d", (int)conns.size(), max_connections, fd, ret); + srs_close_stfd(client_stfd); + return ERROR_SUCCESS; + } if ((int)conns.size() >= max_connections) { srs_error("exceed the max connections, drop client: " "clients=%d, max=%d, fd=%d", (int)conns.size(), max_connections, fd); - srs_close_stfd(client_stfd); - - return ret; + return ERROR_SUCCESS; } // avoid fd leak when fork. diff --git a/trunk/src/app/srs_app_server.hpp b/trunk/src/app/srs_app_server.hpp index bd1b4bc2c..23f9dead8 100644 --- a/trunk/src/app/srs_app_server.hpp +++ b/trunk/src/app/srs_app_server.hpp @@ -225,7 +225,11 @@ public: /** * do on_cycle while server doing cycle. */ - virtual int on_cycle(int connections) = 0; + virtual int on_cycle() = 0; + /** + * callback the handler when got client. + */ + virtual int on_accept_client(int conf_conns, int curr_conns) = 0; }; /** diff --git a/trunk/src/app/srs_app_st.cpp b/trunk/src/app/srs_app_st.cpp index e7fecf3ad..18f45d80b 100644 --- a/trunk/src/app/srs_app_st.cpp +++ b/trunk/src/app/srs_app_st.cpp @@ -440,7 +440,7 @@ int SrsTcpClient::connect(string host, int port, int64_t timeout) // connect host. if ((ret = srs_socket_connect(host, port, timeout, &stfd)) != ERROR_SUCCESS) { - srs_error("mpegts: connect server %s:%d failed. ret=%d", host.c_str(), port, ret); + srs_error("connect server %s:%d failed. ret=%d", host.c_str(), port, ret); return ret; } diff --git a/trunk/src/kernel/srs_kernel_utility.cpp b/trunk/src/kernel/srs_kernel_utility.cpp index e1a71898d..8660b9c17 100644 --- a/trunk/src/kernel/srs_kernel_utility.cpp +++ b/trunk/src/kernel/srs_kernel_utility.cpp @@ -356,7 +356,9 @@ vector srs_string_split(string str, string flag) string s = str; while ((pos = s.find(flag)) != string::npos) { - arr.push_back(s.substr(0, pos)); + if (pos != 0) { + arr.push_back(s.substr(0, pos)); + } s = s.substr(pos + flag.length()); } @@ -406,7 +408,9 @@ vector srs_string_split(string str, vector flags) break; } - arr.push_back(s.substr(0, pos)); + if (pos != 0) { + arr.push_back(s.substr(0, pos)); + } s = s.substr(pos + flag.length()); } diff --git a/trunk/src/kernel/srs_kernel_utility.hpp b/trunk/src/kernel/srs_kernel_utility.hpp index f604bf7ad..1b097ae3e 100644 --- a/trunk/src/kernel/srs_kernel_utility.hpp +++ b/trunk/src/kernel/srs_kernel_utility.hpp @@ -88,6 +88,8 @@ extern bool srs_string_starts_with(std::string str, std::string flag0, std::stri extern bool srs_string_starts_with(std::string str, std::string flag0, std::string flag1, std::string flag2, std::string flag3); // whether string contains with extern bool srs_string_contains(std::string str, std::string flag); +// find the min match in str for flags. +extern std::string srs_string_min_match(std::string str, std::vector flags); // split the string by flag to array. extern std::vector srs_string_split(std::string str, std::string flag); extern std::vector srs_string_split(std::string str, std::vector flags); @@ -97,9 +99,9 @@ extern int srs_create_dir_recursively(std::string dir); // whether path exists. extern bool srs_path_exists(std::string path); -// get the dirname of path, for instance, filename("/live/livestream")="/live" +// get the dirname of path, for instance, dirname("/live/livestream")="/live" extern std::string srs_path_dirname(std::string path); -// get the basename of path, for instance, filename("/live/livestream")="livestream" +// get the basename of path, for instance, basename("/live/livestream")="livestream" extern std::string srs_path_basename(std::string path); // get the filename of path, for instance, filename("livestream.flv")="livestream" extern std::string srs_path_filename(std::string path);