class DLLEXP BaseProtocol {
private:
static uint32_t _idGenerator;
uint32_t_id; //协议ID
BaseClientApplication*_pApplication; //上层应用 该协议将被注册到应用中
protected:
uint64_t_type; //协议类型
BaseProtocol*_pFarProtocol; //协议链中前一个协议。
BaseProtocol*_pNearProtocol; //协议链中后一个协议
bool _deleteFar; //是否删除前一个协议
bool _deleteNear; //是否删除后一个协议
bool _enqueueForDelete; //出队并删除
bool _gracefullyEnqueueForDelete; //出队并删除
Variant_customParameters; //自定义参数
double _creationTimestamp;
public:
BaseProtocol(uint64_ttype);
virtual ~BaseProtocol();
…
/*!
@briefThis is called by the framework when data is available for processing, directlyfrom the network i/o layer
@briefrecvAmount
@parampPeerAddress
*/
virtual boolSignalInputData(int32_t recvAmount, sockaddr_in *pPeerAddress); //有i/o层调用,将数据交由逻辑协议层处理
};
#endif /*_BASEPROTOCOL_H */
该类是所有协议类的基类。每个协议都是以协议链存在,最底层协议是I/0协议(TCP,UDP,STDIO),并关联i/o句柄,GetFarEndpoint()获取的就是最底层的I/0协议,只有这一层
才与i/0打交道。
协议越高,其逻辑处理越接近上层应用。I/0的数据都会按照协议链从i/0协议->p1->p2->pN来处理。
比如配置文件中:
{
ip="0.0.0.0",
port=1935,
protocol="inboundRtmp"
},
其inboundRtmp协议链是PT_TCP->PT_INBOUND_RTMP。