From 308c6fee18d5a5a4932481ad21fe552c6cf5346b Mon Sep 17 00:00:00 2001 From: winlin Date: Thu, 2 Mar 2017 16:43:06 +0800 Subject: [PATCH] Fix #786, simply don't reuse object. 3.0.20 --- README.md | 2 ++ trunk/src/app/srs_app_conn.cpp | 8 +++++++- trunk/src/app/srs_app_http_api.cpp | 9 +++------ trunk/src/app/srs_app_rtmp_conn.cpp | 2 -- trunk/src/app/srs_app_rtmp_conn.hpp | 1 - trunk/src/app/srs_app_rtsp.cpp | 7 ++++++- trunk/src/app/srs_app_st.cpp | 20 ++++++++++++++------ trunk/src/app/srs_app_st.hpp | 6 +++++- trunk/src/core/srs_core.hpp | 2 +- 9 files changed, 38 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index f0c9406983..246a7e39ca 100755 --- a/README.md +++ b/README.md @@ -186,6 +186,7 @@ Please select your language: ### V3 changes +* v3.0, 2017-03-02, Fix [#786][bug #786], simply don't reuse object. 3.0.20 * v3.0, 2017-03-01, For [#110][bug #110], refine thread object. 3.0.19 * v3.0, 2017-02-12, Fix [#301][bug #301], User must config the codec in right way for HLS. 3.0.18 * v3.0, 2017-02-07, fix [#738][bug #738] support DVR general mp4. 3.0.17 @@ -1384,6 +1385,7 @@ Winlin [bug #735]: https://github.com/ossrs/srs/issues/735 [bug #742]: https://github.com/ossrs/srs/issues/742 [bug #738]: https://github.com/ossrs/srs/issues/738 +[bug #786]: https://github.com/ossrs/srs/issues/786 [bug #xxxxxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxxxxx [exo #828]: https://github.com/google/ExoPlayer/pull/828 diff --git a/trunk/src/app/srs_app_conn.cpp b/trunk/src/app/srs_app_conn.cpp index 678d0a333d..36982a33d3 100644 --- a/trunk/src/app/srs_app_conn.cpp +++ b/trunk/src/app/srs_app_conn.cpp @@ -48,7 +48,7 @@ SrsConnection::SrsConnection(IConnectionManager* cm, st_netfd_t c, string cip) expired = false; create_time = srs_get_system_time_ms(); - skt = new SrsStSocket(c); + skt = new SrsStSocket(); kbps = new SrsKbps(); kbps->set_io(skt, skt); @@ -105,6 +105,12 @@ void SrsConnection::dispose() int SrsConnection::start() { + int ret = ERROR_SUCCESS; + + if ((ret = skt->initialize(stfd)) != ERROR_SUCCESS) { + return ret; + } + return pthread->start(); } diff --git a/trunk/src/app/srs_app_http_api.cpp b/trunk/src/app/srs_app_http_api.cpp index c62d3d5632..aa7d1f749f 100644 --- a/trunk/src/app/srs_app_http_api.cpp +++ b/trunk/src/app/srs_app_http_api.cpp @@ -1342,12 +1342,9 @@ int SrsHttpApi::do_cycle() return ret; } - // underlayer socket - SrsStSocket skt(stfd); - // set the recv timeout, for some clients never disconnect the connection. // @see https://github.com/ossrs/srs/issues/398 - skt.set_recv_timeout(SRS_HTTP_RECV_TMMS); + skt->set_recv_timeout(SRS_HTTP_RECV_TMMS); // initialize the cors, which will proxy to mux. bool crossdomain_enabled = _srs_config->get_http_api_crossdomain(); @@ -1360,7 +1357,7 @@ int SrsHttpApi::do_cycle() ISrsHttpMessage* req = NULL; // get a http message - if ((ret = parser->parse_message(&skt, this, &req)) != ERROR_SUCCESS) { + if ((ret = parser->parse_message(skt, this, &req)) != ERROR_SUCCESS) { return ret; } @@ -1371,7 +1368,7 @@ int SrsHttpApi::do_cycle() SrsAutoFree(ISrsHttpMessage, req); // ok, handle http request. - SrsHttpResponseWriter writer(&skt); + SrsHttpResponseWriter writer(skt); if ((ret = process_request(&writer, req)) != ERROR_SUCCESS) { return ret; } diff --git a/trunk/src/app/srs_app_rtmp_conn.cpp b/trunk/src/app/srs_app_rtmp_conn.cpp index fa4e8aafb9..f75cc9eeff 100644 --- a/trunk/src/app/srs_app_rtmp_conn.cpp +++ b/trunk/src/app/srs_app_rtmp_conn.cpp @@ -302,7 +302,6 @@ SrsRtmpConn::SrsRtmpConn(SrsServer* svr, st_netfd_t c, string cip) { server = svr; - skt = new SrsStSocket(c); rtmp = new SrsRtmpServer(skt); refer = new SrsRefer(); bandwidth = new SrsBandwidth(); @@ -328,7 +327,6 @@ SrsRtmpConn::~SrsRtmpConn() srs_freep(info); srs_freep(rtmp); - srs_freep(skt); srs_freep(refer); srs_freep(bandwidth); srs_freep(security); diff --git a/trunk/src/app/srs_app_rtmp_conn.hpp b/trunk/src/app/srs_app_rtmp_conn.hpp index f285c2dea6..73e95a72ed 100644 --- a/trunk/src/app/srs_app_rtmp_conn.hpp +++ b/trunk/src/app/srs_app_rtmp_conn.hpp @@ -139,7 +139,6 @@ class SrsRtmpConn : public virtual SrsConnection, public virtual ISrsReloadHandl friend class SrsPublishRecvThread; private: SrsServer* server; - SrsStSocket* skt; SrsRtmpServer* rtmp; SrsRefer* refer; SrsBandwidth* bandwidth; diff --git a/trunk/src/app/srs_app_rtsp.cpp b/trunk/src/app/srs_app_rtsp.cpp index 11bc30bb7e..950c175bec 100644 --- a/trunk/src/app/srs_app_rtsp.cpp +++ b/trunk/src/app/srs_app_rtsp.cpp @@ -193,7 +193,7 @@ SrsRtspConn::SrsRtspConn(SrsRtspCaster* c, st_netfd_t fd, std::string o) caster = c; stfd = fd; - skt = new SrsStSocket(fd); + skt = new SrsStSocket(); rtsp = new SrsRtspStack(skt); trd = new SrsOneCycleThread("rtsp", this); @@ -232,6 +232,11 @@ SrsRtspConn::~SrsRtspConn() int SrsRtspConn::serve() { + int ret = ERROR_SUCCESS; + if ((ret = skt->initialize(stfd)) != ERROR_SUCCESS) { + return ret; + } + return trd->start(); } diff --git a/trunk/src/app/srs_app_st.cpp b/trunk/src/app/srs_app_st.cpp index 4ea69dfce2..af0a45e210 100755 --- a/trunk/src/app/srs_app_st.cpp +++ b/trunk/src/app/srs_app_st.cpp @@ -208,9 +208,9 @@ namespace internal } } -SrsStSocket::SrsStSocket(st_netfd_t client_stfd) +SrsStSocket::SrsStSocket() { - stfd = client_stfd; + stfd = NULL; stm = rtm = SRS_CONSTS_NO_TMMS; rbytes = sbytes = 0; } @@ -219,6 +219,12 @@ SrsStSocket::~SrsStSocket() { } +int SrsStSocket::initialize(st_netfd_t fd) +{ + stfd = fd; + return ERROR_SUCCESS; +} + bool SrsStSocket::is_never_timeout(int64_t tm) { return tm == SRS_CONSTS_NO_TMMS; @@ -390,8 +396,8 @@ int SrsStSocket::writev(const iovec *iov, int iov_size, ssize_t* nwrite) SrsTcpClient::SrsTcpClient(string h, int p, int64_t tm) { - io = NULL; stfd = NULL; + io = new SrsStSocket(); host = h; port = p; @@ -401,6 +407,8 @@ SrsTcpClient::SrsTcpClient(string h, int p, int64_t tm) SrsTcpClient::~SrsTcpClient() { close(); + + srs_freep(io); } int SrsTcpClient::connect() @@ -415,8 +423,9 @@ int SrsTcpClient::connect() return ret; } - srs_assert(io == NULL); - io = new SrsStSocket(stfd); + if ((ret = io->initialize(stfd)) != ERROR_SUCCESS) { + return ret; + } return ret; } @@ -428,7 +437,6 @@ void SrsTcpClient::close() return; } - srs_freep(io); srs_close_stfd(stfd); } diff --git a/trunk/src/app/srs_app_st.hpp b/trunk/src/app/srs_app_st.hpp index b8024c7013..c0af8e5996 100644 --- a/trunk/src/app/srs_app_st.hpp +++ b/trunk/src/app/srs_app_st.hpp @@ -182,8 +182,11 @@ class SrsStSocket : public ISrsProtocolReaderWriter // The underlayer st fd. st_netfd_t stfd; public: - SrsStSocket(st_netfd_t client_stfd); + SrsStSocket(); virtual ~SrsStSocket(); +public: + // Initialize the socket with stfd, user must manage it. + virtual int initialize(st_netfd_t fd); public: virtual bool is_never_timeout(int64_t tm); virtual void set_recv_timeout(int64_t tm); @@ -240,6 +243,7 @@ class SrsTcpClient : public ISrsProtocolReaderWriter * @remark We will close the exists connection before do connect. */ virtual int connect(); +private: /** * Close the connection to server. * @remark User should never use the client when close it. diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp index 8c5727e16b..27ba606b7e 100644 --- a/trunk/src/core/srs_core.hpp +++ b/trunk/src/core/srs_core.hpp @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // current release version #define VERSION_MAJOR 3 #define VERSION_MINOR 0 -#define VERSION_REVISION 19 +#define VERSION_REVISION 20 // generated by configure, only macros. #include