1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
class fSServer
{
public:
fSServer() :iResult(0), wsaData({ 0 }), ServerSock(INVALID_SOCKET), result(NULL), hints({ 0 }) { }
int Initialize(a_port Port, int SockFamily, int SockType, int Protocol);
int Create();
void WINAPI ServerTickProcess();
inline SOCKET GetServerSock() { return ServerSock; }
inline int GetLastErr() { return lastErr; }
private:
WSADATA wsaData;
int iResult;
SOCKET ServerSock;
struct addrinfo *result, hints;
int lastErr;
HANDLE tickThread;
bool threadCreated;
};
int fSServer::Create()
{
ServerSock = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
if (ServerSock == INVALID_SOCKET)
{
lastErr = WSAGetLastError();
return ErrorType::INVALID_SOCK;
}
iResult = bind(ServerSock, result->ai_addr, (int)result->ai_addrlen);
if (iResult == SOCKET_ERROR)
{
lastErr = WSAGetLastError();
return ErrorType::SOCKET_ERR;
}
freeaddrinfo(result); // We no longer need result
if(threadCreated != true) tickThread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)ServerTickProcess, NULL, 0, 0); // -> error here at third argument, position: ( before "LPTHREAD_START_ROUTINE"
threadCreated = true;
}
|