Skip to content

Commit

Permalink
Fix #786, simply don't reuse object. 3.0.20
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Mar 2, 2017
1 parent 7680ac0 commit 308c6fe
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 19 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion trunk/src/app/srs_app_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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();
}

Expand Down
9 changes: 3 additions & 6 deletions trunk/src/app/srs_app_http_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
}

Expand All @@ -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;
}
Expand Down
2 changes: 0 additions & 2 deletions trunk/src/app/srs_app_rtmp_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -328,7 +327,6 @@ SrsRtmpConn::~SrsRtmpConn()

srs_freep(info);
srs_freep(rtmp);
srs_freep(skt);
srs_freep(refer);
srs_freep(bandwidth);
srs_freep(security);
Expand Down
1 change: 0 additions & 1 deletion trunk/src/app/srs_app_rtmp_conn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion trunk/src/app/srs_app_rtsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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();
}

Expand Down
20 changes: 14 additions & 6 deletions trunk/src/app/srs_app_st.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -401,6 +407,8 @@ SrsTcpClient::SrsTcpClient(string h, int p, int64_t tm)
SrsTcpClient::~SrsTcpClient()
{
close();

srs_freep(io);
}

int SrsTcpClient::connect()
Expand All @@ -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;
}
Expand All @@ -428,7 +437,6 @@ void SrsTcpClient::close()
return;
}

srs_freep(io);
srs_close_stfd(stfd);
}

Expand Down
6 changes: 5 additions & 1 deletion trunk/src/app/srs_app_st.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/core/srs_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <srs_auto_headers.hpp>
Expand Down

1 comment on commit 308c6fe

@winlinvip
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.