Preparing new send engine.
This commit is contained in:
@@ -70,6 +70,7 @@ HEADERS += \
|
|||||||
src/net/genericsocket.h \
|
src/net/genericsocket.h \
|
||||||
src/net/netpacket.h \
|
src/net/netpacket.h \
|
||||||
src/net/resolverthread.h \
|
src/net/resolverthread.h \
|
||||||
|
src/net/senderinterface.h \
|
||||||
src/net/senderthread.h \
|
src/net/senderthread.h \
|
||||||
src/net/serveracceptthread.h \
|
src/net/serveracceptthread.h \
|
||||||
src/net/servergamethread.h \
|
src/net/servergamethread.h \
|
||||||
@@ -155,6 +156,7 @@ SOURCES += \
|
|||||||
src/net/common/downloadhelper.cpp \
|
src/net/common/downloadhelper.cpp \
|
||||||
src/net/common/netpacket.cpp \
|
src/net/common/netpacket.cpp \
|
||||||
src/net/common/resolverthread.cpp \
|
src/net/common/resolverthread.cpp \
|
||||||
|
src/net/common/senderinterface.cpp \
|
||||||
src/net/common/senderthread.cpp \
|
src/net/common/senderthread.cpp \
|
||||||
src/net/common/sendercallback.cpp \
|
src/net/common/sendercallback.cpp \
|
||||||
src/net/common/servercontext.cpp \
|
src/net/common/servercontext.cpp \
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* Copyright (C) 2009 by Lothar May *
|
||||||
|
* *
|
||||||
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||||||
|
* (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This program is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with this program; if not, write to the *
|
||||||
|
* Free Software Foundation, Inc., *
|
||||||
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include <net/senderinterface.h>
|
||||||
|
|
||||||
|
|
||||||
|
SenderInterface::~SenderInterface()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (C) 2007 by Lothar May *
|
* Copyright (C) 2007-2009 by Lothar May *
|
||||||
* *
|
* *
|
||||||
* This program is free software; you can redistribute it and/or modify *
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
* it under the terms of the GNU General Public License as published by *
|
* it under the terms of the GNU General Public License as published by *
|
||||||
@@ -44,6 +44,24 @@ SenderThread::~SenderThread()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SenderThread::Start()
|
||||||
|
{
|
||||||
|
Run();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SenderThread::SignalStop()
|
||||||
|
{
|
||||||
|
SignalTermination();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SenderThread::WaitStop()
|
||||||
|
{
|
||||||
|
Join(SENDER_THREAD_TERMINATE_TIMEOUT);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SenderThread::Send(boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet)
|
SenderThread::Send(boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -772,7 +772,7 @@ ServerGameThread::SetStateTimerFlag(unsigned flag)
|
|||||||
m_stateTimerFlag = flag;
|
m_stateTimerFlag = flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
SenderThread &
|
SenderInterface &
|
||||||
ServerGameThread::GetSender()
|
ServerGameThread::GetSender()
|
||||||
{
|
{
|
||||||
return GetLobbyThread().GetSender();
|
return GetLobbyThread().GetSender();
|
||||||
|
|||||||
@@ -344,7 +344,7 @@ ServerLobbyThread::GetNextGameId()
|
|||||||
void
|
void
|
||||||
ServerLobbyThread::Main()
|
ServerLobbyThread::Main()
|
||||||
{
|
{
|
||||||
GetSender().Run();
|
GetSender().Start();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -379,9 +379,8 @@ ServerLobbyThread::Main()
|
|||||||
|
|
||||||
TerminateGames();
|
TerminateGames();
|
||||||
|
|
||||||
GetSender().SignalTermination();
|
GetSender().SignalStop();
|
||||||
|
GetSender().WaitStop();
|
||||||
GetSender().Join(SENDER_THREAD_TERMINATE_TIMEOUT);
|
|
||||||
|
|
||||||
CleanupConnectQueue();
|
CleanupConnectQueue();
|
||||||
}
|
}
|
||||||
@@ -1291,7 +1290,7 @@ ServerLobbyThread::GetCallback()
|
|||||||
return m_gui;
|
return m_gui;
|
||||||
}
|
}
|
||||||
|
|
||||||
SenderThread &
|
SenderInterface &
|
||||||
ServerLobbyThread::GetSender()
|
ServerLobbyThread::GetSender()
|
||||||
{
|
{
|
||||||
assert(m_sender.get());
|
assert(m_sender.get());
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (C) 2007 by Lothar May *
|
* Copyright (C) 2007-2009 by Lothar May *
|
||||||
* *
|
* *
|
||||||
* This program is free software; you can redistribute it and/or modify *
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
* it under the terms of the GNU General Public License as published by *
|
* it under the terms of the GNU General Public License as published by *
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
#include <net/sessionmanager.h>
|
#include <net/sessionmanager.h>
|
||||||
#include <net/senderthread.h>
|
#include <net/senderinterface.h>
|
||||||
#include <net/serverexception.h>
|
#include <net/serverexception.h>
|
||||||
#include <net/socket_msg.h>
|
#include <net/socket_msg.h>
|
||||||
|
|
||||||
@@ -357,7 +357,7 @@ SessionManager::GetRawSessionCount()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SessionManager::SendToAllSessions(SenderThread &sender, boost::shared_ptr<NetPacket> packet, SessionData::State state)
|
SessionManager::SendToAllSessions(SenderInterface &sender, boost::shared_ptr<NetPacket> packet, SessionData::State state)
|
||||||
{
|
{
|
||||||
boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
|
boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
|
||||||
|
|
||||||
@@ -377,7 +377,7 @@ SessionManager::SendToAllSessions(SenderThread &sender, boost::shared_ptr<NetPac
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SessionManager::SendLobbyMsgToAllSessions(SenderThread &sender, boost::shared_ptr<NetPacket> packet, SessionData::State state)
|
SessionManager::SendLobbyMsgToAllSessions(SenderInterface &sender, boost::shared_ptr<NetPacket> packet, SessionData::State state)
|
||||||
{
|
{
|
||||||
boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
|
boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
|
||||||
|
|
||||||
@@ -397,7 +397,7 @@ SessionManager::SendLobbyMsgToAllSessions(SenderThread &sender, boost::shared_pt
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SessionManager::SendToAllButOneSessions(SenderThread &sender, boost::shared_ptr<NetPacket> packet, SessionId except, SessionData::State state)
|
SessionManager::SendToAllButOneSessions(SenderInterface &sender, boost::shared_ptr<NetPacket> packet, SessionId except, SessionData::State state)
|
||||||
{
|
{
|
||||||
boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
|
boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* Copyright (C) 2009 by Lothar May *
|
||||||
|
* *
|
||||||
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||||||
|
* (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This program is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with this program; if not, write to the *
|
||||||
|
* Free Software Foundation, Inc., *
|
||||||
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||||
|
***************************************************************************/
|
||||||
|
/* Interface for network sender functions. */
|
||||||
|
|
||||||
|
#ifndef _SENDERINTERFACE_H_
|
||||||
|
#define _SENDERINTERFACE_H_
|
||||||
|
|
||||||
|
#include <net/sessiondata.h>
|
||||||
|
#include <net/netpacket.h>
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
|
class SenderInterface
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~SenderInterface();
|
||||||
|
|
||||||
|
virtual void Start() = 0;
|
||||||
|
virtual void SignalStop() = 0;
|
||||||
|
virtual void WaitStop() = 0;
|
||||||
|
|
||||||
|
virtual void Send(boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet) = 0;
|
||||||
|
virtual void Send(boost::shared_ptr<SessionData> session, const NetPacketList &packetList) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
@@ -22,6 +22,7 @@
|
|||||||
#define _SENDERTHREAD_H_
|
#define _SENDERTHREAD_H_
|
||||||
|
|
||||||
#include <core/thread.h>
|
#include <core/thread.h>
|
||||||
|
#include <net/senderinterface.h>
|
||||||
#include <net/sessiondata.h>
|
#include <net/sessiondata.h>
|
||||||
#include <net/netpacket.h>
|
#include <net/netpacket.h>
|
||||||
#include <net/sendercallback.h>
|
#include <net/sendercallback.h>
|
||||||
@@ -32,14 +33,18 @@
|
|||||||
|
|
||||||
#define SENDER_THREAD_TERMINATE_TIMEOUT THREAD_WAIT_INFINITE
|
#define SENDER_THREAD_TERMINATE_TIMEOUT THREAD_WAIT_INFINITE
|
||||||
|
|
||||||
class SenderThread : public Thread
|
class SenderThread : public Thread, public SenderInterface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SenderThread(SenderCallback &cb);
|
SenderThread(SenderCallback &cb);
|
||||||
virtual ~SenderThread();
|
virtual ~SenderThread();
|
||||||
|
|
||||||
void Send(boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet);
|
virtual void Start();
|
||||||
void Send(boost::shared_ptr<SessionData> session, const NetPacketList &packetList);
|
virtual void SignalStop();
|
||||||
|
virtual void WaitStop();
|
||||||
|
|
||||||
|
virtual void Send(boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet);
|
||||||
|
virtual void Send(boost::shared_ptr<SessionData> session, const NetPacketList &packetList);
|
||||||
|
|
||||||
unsigned GetNumPacketsInQueue() const;
|
unsigned GetNumPacketsInQueue() const;
|
||||||
bool operator<(const SenderThread &other) const;
|
bool operator<(const SenderThread &other) const;
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ protected:
|
|||||||
unsigned GetStateTimerFlag() const;
|
unsigned GetStateTimerFlag() const;
|
||||||
void SetStateTimerFlag(unsigned flag);
|
void SetStateTimerFlag(unsigned flag);
|
||||||
|
|
||||||
SenderThread &GetSender();
|
SenderInterface &GetSender();
|
||||||
ReceiverHelper &GetReceiver();
|
ReceiverHelper &GetReceiver();
|
||||||
|
|
||||||
const StartData &GetStartData() const;
|
const StartData &GetStartData() const;
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
#define NET_ADMIN_IRC_TERMINATE_TIMEOUT_MSEC 4000
|
#define NET_ADMIN_IRC_TERMINATE_TIMEOUT_MSEC 4000
|
||||||
|
|
||||||
|
|
||||||
class SenderThread;
|
class SenderInterface;
|
||||||
class ReceiverHelper;
|
class ReceiverHelper;
|
||||||
class ServerSenderCallback;
|
class ServerSenderCallback;
|
||||||
class ServerGameThread;
|
class ServerGameThread;
|
||||||
@@ -87,7 +87,7 @@ public:
|
|||||||
ServerStats GetStats() const;
|
ServerStats GetStats() const;
|
||||||
boost::posix_time::ptime GetStartTime() const;
|
boost::posix_time::ptime GetStartTime() const;
|
||||||
|
|
||||||
SenderThread &GetSender();
|
SenderInterface &GetSender();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
@@ -99,7 +99,6 @@ protected:
|
|||||||
typedef std::map<unsigned, boost::shared_ptr<ServerGameThread> > GameMap;
|
typedef std::map<unsigned, boost::shared_ptr<ServerGameThread> > GameMap;
|
||||||
typedef std::map<std::string, boost::timers::portable::microsec_timer> TimerClientAddressMap;
|
typedef std::map<std::string, boost::timers::portable::microsec_timer> TimerClientAddressMap;
|
||||||
typedef std::list<unsigned> RemoveGameList;
|
typedef std::list<unsigned> RemoveGameList;
|
||||||
typedef std::list<boost::shared_ptr<SenderThread> > SenderThreadList;
|
|
||||||
|
|
||||||
// Main function of the thread.
|
// Main function of the thread.
|
||||||
virtual void Main();
|
virtual void Main();
|
||||||
@@ -191,7 +190,7 @@ private:
|
|||||||
GameMap m_gameMap;
|
GameMap m_gameMap;
|
||||||
|
|
||||||
boost::shared_ptr<ReceiverHelper> m_receiver;
|
boost::shared_ptr<ReceiverHelper> m_receiver;
|
||||||
boost::shared_ptr<SenderThread> m_sender;
|
boost::shared_ptr<SenderInterface> m_sender;
|
||||||
boost::shared_ptr<ServerSenderCallback> m_senderCallback;
|
boost::shared_ptr<ServerSenderCallback> m_senderCallback;
|
||||||
GuiInterface &m_gui;
|
GuiInterface &m_gui;
|
||||||
AvatarManager &m_avatarManager;
|
AvatarManager &m_avatarManager;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (C) 2007 by Lothar May *
|
* Copyright (C) 2007-2009 by Lothar May *
|
||||||
* *
|
* *
|
||||||
* This program is free software; you can redistribute it and/or modify *
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
* it under the terms of the GNU General Public License as published by *
|
* it under the terms of the GNU General Public License as published by *
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class SenderThread;
|
class SenderInterface;
|
||||||
class NetPacket;
|
class NetPacket;
|
||||||
|
|
||||||
struct SessionWrapper
|
struct SessionWrapper
|
||||||
@@ -74,9 +74,9 @@ public:
|
|||||||
void Clear();
|
void Clear();
|
||||||
unsigned GetRawSessionCount();
|
unsigned GetRawSessionCount();
|
||||||
|
|
||||||
void SendToAllSessions(SenderThread &sender, boost::shared_ptr<NetPacket> packet, SessionData::State state);
|
void SendToAllSessions(SenderInterface &sender, boost::shared_ptr<NetPacket> packet, SessionData::State state);
|
||||||
void SendLobbyMsgToAllSessions(SenderThread &sender, boost::shared_ptr<NetPacket> packet, SessionData::State state);
|
void SendLobbyMsgToAllSessions(SenderInterface &sender, boost::shared_ptr<NetPacket> packet, SessionData::State state);
|
||||||
void SendToAllButOneSessions(SenderThread &sender, boost::shared_ptr<NetPacket> packet, SessionId except, SessionData::State state);
|
void SendToAllButOneSessions(SenderInterface &sender, boost::shared_ptr<NetPacket> packet, SessionId except, SessionData::State state);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user