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

for bug #237, extract a queue recv thread.

This commit is contained in:
winlin 2014-12-01 22:39:22 +08:00
parent 22524f390a
commit 31eb9bf1c1
2 changed files with 143 additions and 76 deletions

View file

@ -38,24 +38,39 @@ class SrsRtmpServer;
class SrsMessage;
/**
* the recv thread used to replace the timeout recv,
* which hurt performance for the epoll_ctrl is frequently used.
* @see: SrsRtmpConn::playing
* @see: https://github.com/winlinvip/simple-rtmp-server/issues/217
*/
class SrsQueueRecvThread : public ISrsThreadHandler
* for the recv thread to handle the message.
*/
class ISrsMessageHandler
{
private:
public:
ISrsMessageHandler();
virtual ~ISrsMessageHandler();
public:
/**
* whether the handler can handle,
* for example, when queue recv handler got an message,
* it wait the user to process it, then the recv thread
* never recv message util the handler is ok.
*/
virtual bool can_handle() = 0;
/**
* process the received message.
*/
virtual int handle(SrsMessage* msg) = 0;
};
/**
* the recv thread, use message handler to handle each received message.
*/
class SrsRecvThread : public ISrsThreadHandler
{
protected:
SrsThread* trd;
ISrsMessageHandler* handler;
SrsRtmpServer* rtmp;
std::vector<SrsMessage*> queue;
public:
SrsQueueRecvThread(SrsRtmpServer* rtmp_sdk);
virtual ~SrsQueueRecvThread();
public:
virtual bool empty();
virtual int size();
virtual SrsMessage* pump();
SrsRecvThread(ISrsMessageHandler* msg_handler, SrsRtmpServer* rtmp_sdk);
virtual ~SrsRecvThread();
public:
virtual int start();
virtual void stop();
@ -65,5 +80,27 @@ public:
virtual void on_thread_stop();
};
/**
* the recv thread used to replace the timeout recv,
* which hurt performance for the epoll_ctrl is frequently used.
* @see: SrsRtmpConn::playing
* @see: https://github.com/winlinvip/simple-rtmp-server/issues/217
*/
class SrsQueueRecvThread : virtual public ISrsMessageHandler, virtual public SrsRecvThread
{
private:
std::vector<SrsMessage*> queue;
public:
SrsQueueRecvThread(SrsRtmpServer* rtmp_sdk);
virtual ~SrsQueueRecvThread();
public:
virtual bool empty();
virtual int size();
virtual SrsMessage* pump();
public:
virtual bool can_handle();
virtual int handle(SrsMessage* msg);
};
#endif