39 lines
928 B
C++
39 lines
928 B
C++
#pragma once
|
|
|
|
#include <arpa/inet.h>
|
|
#include <fcntl.h>
|
|
#include <sys/epoll.h>
|
|
#include <netinet/tcp.h>
|
|
|
|
namespace a8
|
|
{
|
|
|
|
struct UdpPacket;
|
|
class UdpSession
|
|
{
|
|
|
|
public:
|
|
UdpSession();
|
|
~UdpSession();
|
|
|
|
virtual void Update(long long tick);
|
|
void SetMaxPacketLen(int max_packet_len);
|
|
virtual void OnRecvPacket(a8::UdpPacket* pkt) = 0;
|
|
virtual void SendClientMsg(char* buf, int buf_len) = 0;
|
|
|
|
protected:
|
|
virtual void OnSocketRead(char* buf, unsigned int buflen);
|
|
virtual void DecodePacket(char* buf, int& offset, unsigned int buflen);
|
|
virtual void DecodeUserPacket(char* buf, int& offset, unsigned int buflen) = 0;
|
|
|
|
private:
|
|
long long remote_key_ = 0;
|
|
int socket_handle_ = 0;
|
|
sockaddr_in remote_addr_ = {};
|
|
char *recv_buff_ = nullptr;
|
|
int recv_bufflen_ = 0;
|
|
int max_packet_len_ = 0;
|
|
};
|
|
|
|
}
|