2022-01-02 19:28:16 -05:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <SDL.h>
|
|
|
|
#include <SDL_net.h>
|
|
|
|
|
|
|
|
/* MTU */
|
|
|
|
#define MAX_PACKET_SIZE (1024*1024)
|
|
|
|
|
|
|
|
class Server
|
|
|
|
{
|
2022-01-03 14:48:50 -05:00
|
|
|
SDL_mutex* mProcessPacketMutex;
|
2022-01-02 19:28:16 -05:00
|
|
|
SDL_TimerID mProcessPacketCallbackTimerID;
|
|
|
|
static Uint32 ProcessPacketCallback (Uint32, void*);
|
|
|
|
public:
|
|
|
|
std::vector<UDPsocket> UDPsocks;
|
|
|
|
SDLNet_SocketSet SocketSet;
|
|
|
|
UDPpacket **UDPPacketV;
|
|
|
|
Server (void)
|
|
|
|
{
|
|
|
|
UDPsocks.clear ();
|
|
|
|
SocketSet = NULL;
|
|
|
|
UDPPacketV = NULL;
|
2022-01-03 14:48:50 -05:00
|
|
|
mProcessPacketMutex = NULL;
|
|
|
|
}
|
|
|
|
~Server (void)
|
|
|
|
{
|
|
|
|
// UDP_CloseAll ();
|
|
|
|
// mProcessPacketMutex = SDL_CreateMutex ();
|
|
|
|
// UDPsocks.clear ();
|
|
|
|
// SocketSet = NULL;
|
|
|
|
// UDPPacketV = NULL;
|
2022-01-02 19:28:16 -05:00
|
|
|
}
|
|
|
|
Server (const char* host, const Uint16 port);
|
|
|
|
UDPsocket UDP_Open (Uint16 port);
|
|
|
|
void UDP_CloseAll (void);
|
|
|
|
void ProcessPacket (UDPpacket* packet);
|
2022-01-03 14:48:50 -05:00
|
|
|
int Start (void);
|
|
|
|
int Stop (void);
|
|
|
|
int Lock (void)
|
|
|
|
{
|
|
|
|
return SDL_LockMutex (mProcessPacketMutex);
|
|
|
|
}
|
|
|
|
int Unlock (void)
|
2022-01-02 19:28:16 -05:00
|
|
|
{
|
2022-01-03 14:48:50 -05:00
|
|
|
return SDL_UnlockMutex (mProcessPacketMutex);
|
2022-01-02 19:28:16 -05:00
|
|
|
}
|
|
|
|
};
|