winlin

Merge pull request #530 from YueHonghui/2.0release

fix bug of fd leek in srs_app_server
@@ -1223,10 +1223,9 @@ void SrsServer::resample_kbps() @@ -1223,10 +1223,9 @@ void SrsServer::resample_kbps()
1223 int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd) 1223 int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd)
1224 { 1224 {
1225 int ret = ERROR_SUCCESS; 1225 int ret = ERROR_SUCCESS;
1226 - 1226 + int fd = st_netfd_fileno(client_stfd);
1227 int max_connections = _srs_config->get_max_connections(); 1227 int max_connections = _srs_config->get_max_connections();
1228 if ((int)conns.size() >= max_connections) { 1228 if ((int)conns.size() >= max_connections) {
1229 - int fd = st_netfd_fileno(client_stfd);  
1230 1229
1231 srs_error("exceed the max connections, drop client: " 1230 srs_error("exceed the max connections, drop client: "
1232 "clients=%d, max=%d, fd=%d", (int)conns.size(), max_connections, fd); 1231 "clients=%d, max=%d, fd=%d", (int)conns.size(), max_connections, fd);
@@ -1235,7 +1234,20 @@ int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd) @@ -1235,7 +1234,20 @@ int SrsServer::accept_client(SrsListenerType type, st_netfd_t client_stfd)
1235 1234
1236 return ret; 1235 return ret;
1237 } 1236 }
1238 - 1237 + int val;
  1238 + if ((val = fcntl(fd, F_GETFD, 0)) < 0) {
  1239 + ret = ERROR_SYSTEM_PID_GET_FILE_INFO;
  1240 + srs_error("fnctl F_GETFD error! fd=%d. ret=%#x", fd, ret);
  1241 + srs_close_stfd(client_stfd);
  1242 + return ret;
  1243 + }
  1244 + val |= FD_CLOEXEC;
  1245 + if (fcntl(fd, F_SETFD, val) < 0) {
  1246 + ret = ERROR_SYSTEM_PID_SET_FILE_INFO;
  1247 + srs_error("fcntl F_SETFD error! fd=%d ret=%#x", fd, ret);
  1248 + srs_close_stfd(client_stfd);
  1249 + return ret;
  1250 + }
1239 SrsConnection* conn = NULL; 1251 SrsConnection* conn = NULL;
1240 if (type == SrsListenerRtmpStream) { 1252 if (type == SrsListenerRtmpStream) {
1241 conn = new SrsRtmpConn(this, client_stfd); 1253 conn = new SrsRtmpConn(this, client_stfd);