winlin

fix signal bug, break for gmc. fix SrsMessage leak, use common message to free payload. to 0.9.88

... ... @@ -532,6 +532,59 @@ int SrsServer::ingest()
int SrsServer::cycle()
{
int ret = ERROR_SUCCESS;
ret = do_cycle();
#ifdef SRS_AUTO_INGEST
ingester->stop();
#endif
return ret;
}
void SrsServer::remove(SrsConnection* conn)
{
std::vector<SrsConnection*>::iterator it = std::find(conns.begin(), conns.end(), conn);
if (it != conns.end()) {
conns.erase(it);
}
srs_info("conn removed. conns=%d", (int)conns.size());
// all connections are created by server,
// so we free it here.
srs_freep(conn);
}
void SrsServer::on_signal(int signo)
{
if (signo == SIGNAL_RELOAD) {
signal_reload = true;
return;
}
if (signo == SIGINT) {
#ifdef SRS_AUTO_GPERF_MC
srs_trace("gmc is on, main cycle will terminate normally.");
signal_gmc_stop = true;
#else
srs_trace("user terminate program");
exit(0);
#endif
return;
}
if (signo == SIGTERM) {
srs_trace("user terminate program");
exit(0);
return;
}
}
int SrsServer::do_cycle()
{
int ret = ERROR_SUCCESS;
// find the max loop
int max = srs_max(0, SRS_SYS_TIME_RESOLUTION_MS_TIMES);
... ... @@ -551,7 +604,7 @@ int SrsServer::cycle()
// because directly exit will cause core-dump.
#ifdef SRS_AUTO_GPERF_MC
if (signal_gmc_stop) {
break;
return ret;
}
#endif
... ... @@ -582,53 +635,9 @@ int SrsServer::cycle()
}
}
#ifdef SRS_AUTO_INGEST
ingester->stop();
#endif
return ret;
}
void SrsServer::remove(SrsConnection* conn)
{
std::vector<SrsConnection*>::iterator it = std::find(conns.begin(), conns.end(), conn);
if (it != conns.end()) {
conns.erase(it);
}
srs_info("conn removed. conns=%d", (int)conns.size());
// all connections are created by server,
// so we free it here.
srs_freep(conn);
}
void SrsServer::on_signal(int signo)
{
if (signo == SIGNAL_RELOAD) {
signal_reload = true;
return;
}
if (signo == SIGINT) {
#ifdef SRS_AUTO_GPERF_MC
srs_trace("gmc is on, main cycle will terminate normally.");
signal_gmc_stop = true;
#else
srs_trace("user terminate program");
exit(0);
#endif
return;
}
if (signo == SIGTERM) {
srs_trace("user terminate program");
exit(0);
return;
}
}
int SrsServer::listen_rtmp()
{
int ret = ERROR_SUCCESS;
... ...
... ... @@ -140,6 +140,7 @@ public:
virtual void remove(SrsConnection* conn);
virtual void on_signal(int signo);
private:
virtual int do_cycle();
virtual int listen_rtmp();
virtual int listen_http_api();
virtual int listen_http_stream();
... ...
... ... @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// current release version
#define VERSION_MAJOR "0"
#define VERSION_MINOR "9"
#define VERSION_REVISION "87"
#define VERSION_REVISION "88"
#define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
// server info.
#define RTMP_SIG_SRS_KEY "srs"
... ...
... ... @@ -759,7 +759,7 @@ int SrsProtocol::send_and_free_packet(SrsPacket* packet, int stream_id)
}
// to message
SrsMessage* msg = new SrsMessage();
SrsMessage* msg = new SrsCommonMessage();
msg->payload = (int8_t*)payload;
msg->size = (int32_t)size;
... ... @@ -975,7 +975,7 @@ int SrsProtocol::read_message_header(SrsChunkStream* chunk, char fmt, int bh_siz
bool is_first_chunk_of_msg = false;
if (!chunk->msg) {
is_first_chunk_of_msg = true;
chunk->msg = new SrsMessage();
chunk->msg = new SrsCommonMessage();
srs_verbose("create message for new chunk, fmt=%d, cid=%d", fmt, chunk->cid);
}
... ... @@ -1532,7 +1532,16 @@ SrsMessage::SrsMessage()
}
SrsMessage::~SrsMessage()
{
{
}
SrsCommonMessage::SrsCommonMessage()
{
}
SrsCommonMessage::~SrsCommonMessage()
{
srs_freepa(payload);
}
SrsSharedPtrMessage::__SrsSharedPtr::__SrsSharedPtr()
... ...
... ... @@ -325,6 +325,12 @@ public:
* message is raw data RTMP message, bytes oriented,
* protcol always recv RTMP message, and can send RTMP message or RTMP packet.
* the shared-ptr message is a special RTMP message, use ref-count for performance issue.
*
* @remark, never directly new SrsMessage, the constructor is protected,
* for in the SrsMessage, we never know whether we should free the message,
* for SrsCommonMessage, we should free the payload,
* while for SrsSharedPtrMessage, we should use ref-count to free it.
* so, use these two concrete message, SrsCommonMessage or SrsSharedPtrMessage instread.
*/
class SrsMessage
{
... ... @@ -341,12 +347,23 @@ public:
*/
int32_t size;
int8_t* payload;
public:
protected:
SrsMessage();
public:
virtual ~SrsMessage();
};
/**
* the common message used free the payload in common way.
*/
class SrsCommonMessage : public SrsMessage
{
public:
SrsCommonMessage();
virtual ~SrsCommonMessage();
};
/**
* shared ptr message.
* for audio/video/data message that need less memory copy.
* and only for output.
... ...