handmade/include/Server.h

51 lines
1020 B
C
Raw Normal View History

#pragma once
#include <string>
#include <vector>
#include <SDL.h>
#include <SDL_net.h>
/* MTU */
#define MAX_PACKET_SIZE (1024*1024)
class Server
{
SDL_mutex* mProcessPacketMutex;
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;
mProcessPacketMutex = NULL;
}
~Server (void)
{
// UDP_CloseAll ();
// mProcessPacketMutex = SDL_CreateMutex ();
// UDPsocks.clear ();
// SocketSet = NULL;
// UDPPacketV = NULL;
}
Server (const char* host, const Uint16 port);
UDPsocket UDP_Open (Uint16 port);
void UDP_CloseAll (void);
void ProcessPacket (UDPpacket* packet);
int Start (void);
int Stop (void);
int Lock (void)
{
return SDL_LockMutex (mProcessPacketMutex);
}
int Unlock (void)
{
return SDL_UnlockMutex (mProcessPacketMutex);
}
};