From c82c636d8c9ac24c1e73740c35b3a93525783a3d Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Wed, 8 Feb 2012 10:02:46 +0000 Subject: cSocketThreads plugged in for cClientHandle reading. Sending still kept the old way. Please help me test this commit thoroughly, this is a change that can break on subtleties. git-svn-id: http://mc-server.googlecode.com/svn/trunk@244 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cServer.cpp | 65 ++++++++++++++---------------------------------------- 1 file changed, 16 insertions(+), 49 deletions(-) (limited to 'source/cServer.cpp') diff --git a/source/cServer.cpp b/source/cServer.cpp index 36fb71875..e3fdb2f86 100644 --- a/source/cServer.cpp +++ b/source/cServer.cpp @@ -100,46 +100,9 @@ void cServer::ServerListenThread( void *a_Args ) -std::string GetWSAError() +void cServer::ClientDestroying(const cClientHandle * a_Client) { -#ifdef _WIN32 - switch( WSAGetLastError() ) - { - case WSANOTINITIALISED: - return "WSANOTINITIALISED"; - case WSAENETDOWN: - return "WSAENETDOWN"; - case WSAEFAULT: - return "WSAEFAULT"; - case WSAENOTCONN: - return "WSAENOTCONN"; - case WSAEINTR: - return "WSAEINTR"; - case WSAEINPROGRESS: - return "WSAEINPROGRESS"; - case WSAENETRESET: - return "WSAENETRESET"; - case WSAENOTSOCK: - return "WSAENOTSOCK"; - case WSAEOPNOTSUPP: - return "WSAEOPNOTSUPP"; - case WSAESHUTDOWN: - return "WSAESHUTDOWN"; - case WSAEWOULDBLOCK: - return "WSAEWOULDBLOCK"; - case WSAEMSGSIZE: - return "WSAEMSGSIZE"; - case WSAEINVAL: - return "WSAEINVAL"; - case WSAECONNABORTED: - return "WSAECONNABORTED"; - case WSAETIMEDOUT: - return "WSAETIMEDOUT"; - case WSAECONNRESET: - return "WSAECONNRESET"; - } -#endif - return "No Error"; + m_SocketThreads.RemoveClient(a_Client); } @@ -183,11 +146,11 @@ bool cServer::InitServer( int a_Port ) return false; } - if( m_pState->SListenClient.SetReuseAddress() == -1 ) + if( m_pState->SListenClient.SetReuseAddress() == -1 ) { - LOGERROR("setsockopt == -1"); - return false; - } + LOGERROR("setsockopt == -1"); + return false; + } cSocket::SockAddr_In local; local.Family = cSocket::ADDRESS_FAMILY_INTERNET; @@ -308,9 +271,16 @@ void cServer::StartListenClient() return; } - LOG("%s connected!", ClientIP.c_str()); + LOG("Client \"%s\" connected!", ClientIP.c_str()); - cClientHandle *NewHandle = new cClientHandle( SClient ); + cClientHandle *NewHandle = new cClientHandle(SClient); + if (!m_SocketThreads.AddClient(&(NewHandle->GetSocket()), NewHandle)) + { + // For some reason SocketThreads have rejected the handle, clean it up + SClient.CloseSocket(); + delete NewHandle; + return; + } m_pState->Clients.push_back( NewHandle ); // TODO - lock list } @@ -335,11 +305,8 @@ bool cServer::Tick(float a_Dt) //World->LockClientHandle(); // TODO - Lock client list for( ClientList::iterator itr = m_pState->Clients.begin(); itr != m_pState->Clients.end();) { - (*itr)->HandlePendingPackets(); - if( (*itr)->IsDestroyed() ) { - cClientHandle* RemoveMe = *itr; ++itr; m_pState->Clients.remove( RemoveMe ); @@ -464,7 +431,7 @@ void cServer::ServerCommand( const char* a_Cmd ) { if( split[0].compare( "help" ) == 0 ) { - printf("===================ALL COMMANDS====================\n"); + printf("================== ALL COMMANDS ===================\n"); printf("help - Shows this message\n"); printf("save-all - Saves all loaded chunks to disk\n"); printf("list - Lists all players currently in server\n"); -- cgit v1.2.3