Preparing to rename some of the network engine files.
This commit is contained in:
@@ -30,19 +30,19 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
ServerThread::ServerThread(GuiInterface &gui, ConfigFile *config)
|
ServerAcceptThread::ServerAcceptThread(GuiInterface &gui, ConfigFile *config)
|
||||||
: m_gui(gui)
|
: m_gui(gui)
|
||||||
{
|
{
|
||||||
m_context.reset(new ServerContext);
|
m_context.reset(new ServerContext);
|
||||||
m_recvThread.reset(new ServerRecvThread(gui, config));
|
m_lobbyThread.reset(new ServerLobbyThread(gui, config));
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerThread::~ServerThread()
|
ServerAcceptThread::~ServerAcceptThread()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ServerThread::Init(unsigned serverPort, bool ipv6, bool sctp, const std::string &pwd,
|
ServerAcceptThread::Init(unsigned serverPort, bool ipv6, bool sctp, const std::string &pwd,
|
||||||
const GameData &gameData)
|
const GameData &gameData)
|
||||||
{
|
{
|
||||||
if (IsRunning())
|
if (IsRunning())
|
||||||
@@ -54,28 +54,28 @@ ServerThread::Init(unsigned serverPort, bool ipv6, bool sctp, const std::string
|
|||||||
context.SetAddrFamily(ipv6 ? AF_INET6 : AF_INET);
|
context.SetAddrFamily(ipv6 ? AF_INET6 : AF_INET);
|
||||||
context.SetServerPort(serverPort);
|
context.SetServerPort(serverPort);
|
||||||
|
|
||||||
GetRecvThread().Init(pwd, gameData);
|
GetLobbyThread().Init(pwd);
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerCallback &
|
ServerCallback &
|
||||||
ServerThread::GetCallback()
|
ServerAcceptThread::GetCallback()
|
||||||
{
|
{
|
||||||
return m_gui;
|
return m_gui;
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiInterface &
|
GuiInterface &
|
||||||
ServerThread::GetGui()
|
ServerAcceptThread::GetGui()
|
||||||
{
|
{
|
||||||
return m_gui;
|
return m_gui;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ServerThread::Main()
|
ServerAcceptThread::Main()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Listen();
|
Listen();
|
||||||
GetRecvThread().Run();
|
GetLobbyThread().Run();
|
||||||
|
|
||||||
while (!ShouldTerminate())
|
while (!ShouldTerminate())
|
||||||
{
|
{
|
||||||
@@ -86,12 +86,12 @@ ServerThread::Main()
|
|||||||
{
|
{
|
||||||
GetCallback().SignalNetServerError(e.GetErrorId(), e.GetOsErrorCode());
|
GetCallback().SignalNetServerError(e.GetErrorId(), e.GetOsErrorCode());
|
||||||
}
|
}
|
||||||
GetRecvThread().SignalTermination();
|
GetLobbyThread().SignalTermination();
|
||||||
GetRecvThread().Join(RECEIVER_THREAD_TERMINATE_TIMEOUT);
|
GetLobbyThread().Join(LOBBY_THREAD_TERMINATE_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ServerThread::Listen()
|
ServerAcceptThread::Listen()
|
||||||
{
|
{
|
||||||
ServerContext &context = GetContext();
|
ServerContext &context = GetContext();
|
||||||
|
|
||||||
@@ -147,7 +147,7 @@ ServerThread::Listen()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ServerThread::AcceptLoop()
|
ServerAcceptThread::AcceptLoop()
|
||||||
{
|
{
|
||||||
ServerContext &context = GetContext();
|
ServerContext &context = GetContext();
|
||||||
|
|
||||||
@@ -174,28 +174,28 @@ ServerThread::AcceptLoop()
|
|||||||
throw ServerException(ERR_SOCK_ACCEPT_FAILED, SOCKET_ERRNO());
|
throw ServerException(ERR_SOCK_ACCEPT_FAILED, SOCKET_ERRNO());
|
||||||
}
|
}
|
||||||
|
|
||||||
GetRecvThread().AddConnection(tmpData);
|
GetLobbyThread().AddConnection(tmpData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const ServerContext &
|
const ServerContext &
|
||||||
ServerThread::GetContext() const
|
ServerAcceptThread::GetContext() const
|
||||||
{
|
{
|
||||||
assert(m_context.get());
|
assert(m_context.get());
|
||||||
return *m_context;
|
return *m_context;
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerContext &
|
ServerContext &
|
||||||
ServerThread::GetContext()
|
ServerAcceptThread::GetContext()
|
||||||
{
|
{
|
||||||
assert(m_context.get());
|
assert(m_context.get());
|
||||||
return *m_context;
|
return *m_context;
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerRecvThread &
|
ServerLobbyThread &
|
||||||
ServerThread::GetRecvThread()
|
ServerAcceptThread::GetLobbyThread()
|
||||||
{
|
{
|
||||||
assert(m_recvThread.get());
|
assert(m_lobbyThread.get());
|
||||||
return *m_recvThread;
|
return *m_lobbyThread;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
#include <list>
|
#include <list>
|
||||||
#include <core/boost/timer.hpp>
|
#include <core/boost/timer.hpp>
|
||||||
|
|
||||||
#define RECEIVER_THREAD_TERMINATE_TIMEOUT 200
|
#define LOBBY_THREAD_TERMINATE_TIMEOUT 200
|
||||||
|
|
||||||
|
|
||||||
class SenderThread;
|
class SenderThread;
|
||||||
|
|||||||
@@ -16,10 +16,10 @@
|
|||||||
* Free Software Foundation, Inc., *
|
* Free Software Foundation, Inc., *
|
||||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
/* Network server thread. */
|
/* Network server thread to accept connections. */
|
||||||
|
|
||||||
#ifndef _SERVERTHREAD_H_
|
#ifndef _SERVERACCEPTTHREAD_H_
|
||||||
#define _SERVERTHREAD_H_
|
#define _SERVERACCEPTTHREAD_H_
|
||||||
|
|
||||||
#include <game_defs.h>
|
#include <game_defs.h>
|
||||||
#include <core/thread.h>
|
#include <core/thread.h>
|
||||||
@@ -28,17 +28,17 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
class ServerContext;
|
class ServerContext;
|
||||||
class ServerRecvThread;
|
class ServerLobbyThread;
|
||||||
class ServerSenderCallback;
|
class ServerSenderCallback;
|
||||||
class SenderThread;
|
class SenderThread;
|
||||||
class ConfigFile;
|
class ConfigFile;
|
||||||
struct GameData;
|
struct GameData;
|
||||||
|
|
||||||
class ServerThread : public Thread
|
class ServerAcceptThread : public Thread
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ServerThread(GuiInterface &gui, ConfigFile *config);
|
ServerAcceptThread(GuiInterface &gui, ConfigFile *config);
|
||||||
virtual ~ServerThread();
|
virtual ~ServerAcceptThread();
|
||||||
|
|
||||||
// Set the parameters.
|
// Set the parameters.
|
||||||
void Init(unsigned serverPort, bool ipv6, bool sctp, const std::string &pwd,
|
void Init(unsigned serverPort, bool ipv6, bool sctp, const std::string &pwd,
|
||||||
@@ -58,11 +58,11 @@ protected:
|
|||||||
const ServerContext &GetContext() const;
|
const ServerContext &GetContext() const;
|
||||||
ServerContext &GetContext();
|
ServerContext &GetContext();
|
||||||
|
|
||||||
ServerRecvThread &GetRecvThread();
|
ServerLobbyThread &GetLobbyThread();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::auto_ptr<ServerContext> m_context;
|
std::auto_ptr<ServerContext> m_context;
|
||||||
std::auto_ptr<ServerRecvThread> m_recvThread;
|
std::auto_ptr<ServerLobbyThread> m_lobbyThread;
|
||||||
|
|
||||||
GuiInterface &m_gui;
|
GuiInterface &m_gui;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user