1
0
forked from metin2/server
server/db/src/PeerBase.h

41 lines
844 B
C
Raw Normal View History

2022-03-05 12:44:06 +02:00
#ifndef __INC_PEERBASE_H__
#define __INC_PEERBASE_H__
#include <event2/bufferevent.h>
2022-03-05 12:44:06 +02:00
class CPeerBase {
protected:
2022-03-05 12:44:06 +02:00
virtual void OnAccept() = 0;
virtual void OnClose() = 0;
public:
bool Accept(bufferevent* bufev, sockaddr* addr);
void Close();
2022-03-05 12:44:06 +02:00
public:
2022-03-05 12:44:06 +02:00
CPeerBase();
virtual ~CPeerBase();
void Destroy();
2022-03-05 12:44:06 +02:00
bufferevent * GetBufferevent() { return m_bufferevent; }
2022-03-05 12:44:06 +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
size_t GetSendLength();
2022-03-05 12:44:06 +02:00
const char * GetHost() { return m_host; }
protected:
char m_host[IP_ADDRESS_LENGTH + 1];
bufferevent * m_bufferevent;
2022-03-05 12:44:06 +02:00
};
#endif