From 96e1de255cafa112bc3792f868e9f06ef11e3fc2 Mon Sep 17 00:00:00 2001 From: winlin Date: Fri, 18 Oct 2013 17:10:24 +0800 Subject: [PATCH] close fd when delete connection object --- trunk/src/core/srs_core_conn.cpp | 6 +++++- trunk/src/core/srs_core_server.cpp | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/trunk/src/core/srs_core_conn.cpp b/trunk/src/core/srs_core_conn.cpp index 4da3967bd..0f650f801 100755 --- a/trunk/src/core/srs_core_conn.cpp +++ b/trunk/src/core/srs_core_conn.cpp @@ -35,6 +35,10 @@ SrsConnection::SrsConnection(SrsServer* srs_server, st_netfd_t client_stfd) SrsConnection::~SrsConnection() { + if (stfd) { + st_netfd_close(stfd); + stfd = NULL; + } } int SrsConnection::start() @@ -59,7 +63,7 @@ void SrsConnection::cycle() // success. if (ret == ERROR_SUCCESS) { - SrsInfo("client process normally finished. ret=%d", ret); + SrsTrace("client process normally finished. ret=%d", ret); } // client close peer. diff --git a/trunk/src/core/srs_core_server.cpp b/trunk/src/core/srs_core_server.cpp index 55d1b66c2..8546a503b 100755 --- a/trunk/src/core/srs_core_server.cpp +++ b/trunk/src/core/srs_core_server.cpp @@ -148,6 +148,8 @@ void SrsServer::remove(SrsConnection* conn) conns.erase(it); } + SrsInfo("conn removed. conns=%d", (int)conns.size()); + // all connections are created by server, // so we delete it here. delete conn; @@ -161,11 +163,13 @@ int SrsServer::accept_client(st_netfd_t client_stfd) // directly enqueue, the cycle thread will remove the client. conns.push_back(conn); + SrsVerbose("add conn to vector. conns=%d", (int)conns.size()); // cycle will start process thread and when finished remove the client. if ((ret = conn->start()) != ERROR_SUCCESS) { return ret; } + SrsVerbose("conn start finished. ret=%d", ret); return ret; } @@ -182,13 +186,14 @@ void SrsServer::listen_cycle() SrsWarn("ignore accept thread stoppped for accept client error"); continue; } + SrsVerbose("get a client. fd=%d", st_netfd_fileno(client_stfd)); if ((ret = accept_client(client_stfd)) != ERROR_SUCCESS) { SrsWarn("accept client error. ret=%d", ret); continue; } - SrsVerbose("accept client finished. ret=%d", ret); + SrsVerbose("accept client finished. conns=%d, ret=%d", (int)conns.size(), ret); } }