#pragma once #include #include #include "lib_lua_common.h" #include "UDPbase.h" #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 UDPsocks.at (idx); } UDPpacket** getPacketV (void) { return packetV; } SDLNet_SocketSet getSocketSet (void) { return SocketSet; } };