1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

fix #244, conn thread use cond to wait for recv thread error. 2.0.47.

This commit is contained in:
winlin 2014-12-03 12:08:29 +08:00
parent 565f29ed6c
commit 787ab674e3
4 changed files with 52 additions and 40 deletions

View file

@ -230,11 +230,25 @@ SrsPublishRecvThread::SrsPublishRecvThread(
recv_error_code = ERROR_SUCCESS;
_nb_msgs = 0;
error = st_cond_new();
}
SrsPublishRecvThread::~SrsPublishRecvThread()
{
trd.stop();
st_cond_destroy(error);
}
int SrsPublishRecvThread::wait(int timeout_ms)
{
if (recv_error_code != ERROR_SUCCESS) {
return recv_error_code;
}
// ignore any return of cond wait.
st_cond_timedwait(error, timeout_ms * 1000);
return ERROR_SUCCESS;
}
int64_t SrsPublishRecvThread::nb_msgs()
@ -282,6 +296,10 @@ int SrsPublishRecvThread::handle(SrsMessage* msg)
void SrsPublishRecvThread::on_recv_error(int ret)
{
recv_error_code = ret;
// when recv thread error, signal the conn thread to process it.
// @see https://github.com/winlinvip/simple-rtmp-server/issues/244
st_cond_signal(error);
}
void SrsPublishRecvThread::on_thread_start()
@ -294,4 +312,8 @@ void SrsPublishRecvThread::on_thread_stop()
{
// we donot set the auto response to true,
// for we donot set to false yet.
// when thread stop, signal the conn thread which wait.
// @see https://github.com/winlinvip/simple-rtmp-server/issues/244
st_cond_signal(error);
}

View file

@ -142,14 +142,22 @@ private:
// the recv thread error code.
int recv_error_code;
SrsRtmpConn* _conn;
// the params for conn callback.
SrsSource* _source;
bool _is_fmle;
bool _is_edge;
// the error timeout cond
// @see https://github.com/winlinvip/simple-rtmp-server/issues/244
st_cond_t error;
public:
SrsPublishRecvThread(SrsRtmpServer* rtmp_sdk, int timeout_ms,
SrsRtmpConn* conn, SrsSource* source, bool is_fmle, bool is_edge);
virtual ~SrsPublishRecvThread();
public:
/**
* wait for error for some timeout.
*/
virtual int wait(int timeout_ms);
virtual int64_t nb_msgs();
virtual int error_code();
public:

View file

@ -750,17 +750,15 @@ int SrsRtmpConn::do_publishing(SrsSource* source, SrsPublishRecvThread* trd)
int64_t nb_msgs = 0;
while (true) {
// use small loop to check the error code, interval = 30s/43 = 697ms.
for (int i = 0; i < 43; i++) {
st_usleep(SRS_CONSTS_RTMP_RECV_TIMEOUT_US / 43);
// cond wait for error.
trd->wait(SRS_CONSTS_RTMP_RECV_TIMEOUT_US / 1000);
// check the thread error code.
if ((ret = trd->error_code()) != ERROR_SUCCESS) {
if (!srs_is_client_gracefully_close(ret)) {
srs_error("recv thread failed. ret=%d", ret);
}
return ret;
// check the thread error code.
if ((ret = trd->error_code()) != ERROR_SUCCESS) {
if (!srs_is_client_gracefully_close(ret)) {
srs_error("recv thread failed. ret=%d", ret);
}
return ret;
}
// when not got any messages, timeout.