handmade/include/Server.h

56 lines
1.2 KiB
C
Raw Normal View History

#pragma once
#include <string>
#include <vector>
#include "lib_lua_common.h"
#include "UDPbase.h"
/*
* Used as mFetchPacketsCallbackTimerID timeout
*/
#define DEFAULT_SOCKET_TIMEOUT 10
class Server : public UDPbase
{
SDL_mutex* mProcessPacketMutex;
SDL_TimerID mFetchPacketsCallbackTimerID;
SDLNet_SocketSet SocketSet;
UDPpacket** packetV;
lua_State *mLuaState;
public:
Server (const char* host, const Uint16 port);
~Server (void);
/*
* error: invalid use of non-static member function Uint32 Server::FetchPacketsCallback(Uint32, void*)
* Don't understand this.
* static keyword fixes it.
*/
static Uint32 FetchPacketsCallback (Uint32 interval, void* param);
void ProcessPacketHelper (UDPpacket* packet);
void RunLua (const std::string& buf);
int AllocateApproximateResources (const int nclients);
int Start (void);
int Stop (void);
int Lock (void)
{
return SDL_LockMutex (mProcessPacketMutex);
}
int Unlock (void)
{
return SDL_UnlockMutex (mProcessPacketMutex);
}
lua_State* getLuaState(void) { return mLuaState; }
UDPsocket getUDPsock (size_t idx) { return m_socks.at (idx); }
UDPpacket** getPacketV (void) { return packetV; }
SDLNet_SocketSet getSocketSet (void) { return SocketSet; }
};