2022-03-05 12:44:06 +02:00
|
|
|
#ifndef __INC_PEERBASE_H__
|
|
|
|
#define __INC_PEERBASE_H__
|
|
|
|
|
2022-03-09 21:30:51 +02:00
|
|
|
#include <event2/bufferevent.h>
|
2022-03-05 12:44:06 +02:00
|
|
|
|
2022-03-09 21:30:51 +02:00
|
|
|
class CPeerBase {
|
|
|
|
protected:
|
2022-03-05 12:44:06 +02:00
|
|
|
virtual void OnAccept() = 0;
|
|
|
|
virtual void OnClose() = 0;
|
|
|
|
|
2022-03-09 21:30:51 +02:00
|
|
|
public:
|
|
|
|
bool Accept(bufferevent* bufev, sockaddr* addr);
|
|
|
|
void Close();
|
2022-03-05 12:44:06 +02:00
|
|
|
|
2022-03-09 21:30:51 +02:00
|
|
|
public:
|
2022-03-05 12:44:06 +02:00
|
|
|
CPeerBase();
|
|
|
|
virtual ~CPeerBase();
|
|
|
|
|
2022-03-09 21:30:51 +02:00
|
|
|
void Destroy();
|
2022-03-05 12:44:06 +02:00
|
|
|
|
2022-03-09 21:30:51 +02:00
|
|
|
bufferevent * GetBufferevent() { return m_bufferevent; }
|
2022-03-05 12:44:06 +02:00
|
|
|
|
2022-03-09 21:30:51 +02:00
|
|
|
void EncodeBYTE(BYTE b);
|
|
|
|
void EncodeWORD(WORD w);
|
|
|
|
void EncodeDWORD(DWORD dw);
|
|
|
|
void Encode(const void* data, size_t size);
|
|
|
|
void RecvEnd(size_t proceed_bytes);
|
|
|
|
size_t GetRecvLength();
|
|
|
|
const void * GetRecvBuffer(ssize_t ensure_bytes);
|
2022-03-05 12:44:06 +02:00
|
|
|
|
2022-03-09 21:30:51 +02:00
|
|
|
size_t GetSendLength();
|
2022-03-05 12:44:06 +02:00
|
|
|
|
|
|
|
const char * GetHost() { return m_host; }
|
|
|
|
|
2022-03-09 21:30:51 +02:00
|
|
|
protected:
|
|
|
|
char m_host[IP_ADDRESS_LENGTH + 1];
|
|
|
|
bufferevent * m_bufferevent;
|
2022-03-05 12:44:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|