Preparing new send engine.
This commit is contained in:
@@ -70,6 +70,7 @@ HEADERS += \
|
||||
src/net/genericsocket.h \
|
||||
src/net/netpacket.h \
|
||||
src/net/resolverthread.h \
|
||||
src/net/senderinterface.h \
|
||||
src/net/senderthread.h \
|
||||
src/net/serveracceptthread.h \
|
||||
src/net/servergamethread.h \
|
||||
@@ -155,6 +156,7 @@ SOURCES += \
|
||||
src/net/common/downloadhelper.cpp \
|
||||
src/net/common/netpacket.cpp \
|
||||
src/net/common/resolverthread.cpp \
|
||||
src/net/common/senderinterface.cpp \
|
||||
src/net/common/senderthread.cpp \
|
||||
src/net/common/sendercallback.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 *
|
||||
* 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
|
||||
SenderThread::Send(boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet)
|
||||
{
|
||||
|
||||
@@ -772,7 +772,7 @@ ServerGameThread::SetStateTimerFlag(unsigned flag)
|
||||
m_stateTimerFlag = flag;
|
||||
}
|
||||
|
||||
SenderThread &
|
||||
SenderInterface &
|
||||
ServerGameThread::GetSender()
|
||||
{
|
||||
return GetLobbyThread().GetSender();
|
||||
|
||||
@@ -344,7 +344,7 @@ ServerLobbyThread::GetNextGameId()
|
||||
void
|
||||
ServerLobbyThread::Main()
|
||||
{
|
||||
GetSender().Run();
|
||||
GetSender().Start();
|
||||
|
||||
try
|
||||
{
|
||||
@@ -379,9 +379,8 @@ ServerLobbyThread::Main()
|
||||
|
||||
TerminateGames();
|
||||
|
||||
GetSender().SignalTermination();
|
||||
|
||||
GetSender().Join(SENDER_THREAD_TERMINATE_TIMEOUT);
|
||||
GetSender().SignalStop();
|
||||
GetSender().WaitStop();
|
||||
|
||||
CleanupConnectQueue();
|
||||
}
|
||||
@@ -1291,7 +1290,7 @@ ServerLobbyThread::GetCallback()
|
||||
return m_gui;
|
||||
}
|
||||
|
||||
SenderThread &
|
||||
SenderInterface &
|
||||
ServerLobbyThread::GetSender()
|
||||
{
|
||||
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 *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
@@ -18,7 +18,7 @@
|
||||
***************************************************************************/
|
||||
|
||||
#include <net/sessionmanager.h>
|
||||
#include <net/senderthread.h>
|
||||
#include <net/senderinterface.h>
|
||||
#include <net/serverexception.h>
|
||||
#include <net/socket_msg.h>
|
||||
|
||||
@@ -357,7 +357,7 @@ SessionManager::GetRawSessionCount()
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@@ -377,7 +377,7 @@ SessionManager::SendToAllSessions(SenderThread &sender, boost::shared_ptr<NetPac
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@@ -397,7 +397,7 @@ SessionManager::SendLobbyMsgToAllSessions(SenderThread &sender, boost::shared_pt
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
|
||||
@@ -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_
|
||||
|
||||
#include <core/thread.h>
|
||||
#include <net/senderinterface.h>
|
||||
#include <net/sessiondata.h>
|
||||
#include <net/netpacket.h>
|
||||
#include <net/sendercallback.h>
|
||||
@@ -32,14 +33,18 @@
|
||||
|
||||
#define SENDER_THREAD_TERMINATE_TIMEOUT THREAD_WAIT_INFINITE
|
||||
|
||||
class SenderThread : public Thread
|
||||
class SenderThread : public Thread, public SenderInterface
|
||||
{
|
||||
public:
|
||||
SenderThread(SenderCallback &cb);
|
||||
virtual ~SenderThread();
|
||||
|
||||
void Send(boost::shared_ptr<SessionData> session, boost::shared_ptr<NetPacket> packet);
|
||||
void Send(boost::shared_ptr<SessionData> session, const NetPacketList &packetList);
|
||||
virtual void Start();
|
||||
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;
|
||||
bool operator<(const SenderThread &other) const;
|
||||
|
||||
@@ -121,7 +121,7 @@ protected:
|
||||
unsigned GetStateTimerFlag() const;
|
||||
void SetStateTimerFlag(unsigned flag);
|
||||
|
||||
SenderThread &GetSender();
|
||||
SenderInterface &GetSender();
|
||||
ReceiverHelper &GetReceiver();
|
||||
|
||||
const StartData &GetStartData() const;
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
#define NET_ADMIN_IRC_TERMINATE_TIMEOUT_MSEC 4000
|
||||
|
||||
|
||||
class SenderThread;
|
||||
class SenderInterface;
|
||||
class ReceiverHelper;
|
||||
class ServerSenderCallback;
|
||||
class ServerGameThread;
|
||||
@@ -87,7 +87,7 @@ public:
|
||||
ServerStats GetStats() const;
|
||||
boost::posix_time::ptime GetStartTime() const;
|
||||
|
||||
SenderThread &GetSender();
|
||||
SenderInterface &GetSender();
|
||||
|
||||
protected:
|
||||
|
||||
@@ -99,7 +99,6 @@ protected:
|
||||
typedef std::map<unsigned, boost::shared_ptr<ServerGameThread> > GameMap;
|
||||
typedef std::map<std::string, boost::timers::portable::microsec_timer> TimerClientAddressMap;
|
||||
typedef std::list<unsigned> RemoveGameList;
|
||||
typedef std::list<boost::shared_ptr<SenderThread> > SenderThreadList;
|
||||
|
||||
// Main function of the thread.
|
||||
virtual void Main();
|
||||
@@ -191,7 +190,7 @@ private:
|
||||
GameMap m_gameMap;
|
||||
|
||||
boost::shared_ptr<ReceiverHelper> m_receiver;
|
||||
boost::shared_ptr<SenderThread> m_sender;
|
||||
boost::shared_ptr<SenderInterface> m_sender;
|
||||
boost::shared_ptr<ServerSenderCallback> m_senderCallback;
|
||||
GuiInterface &m_gui;
|
||||
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 *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
@@ -29,7 +29,7 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
class SenderThread;
|
||||
class SenderInterface;
|
||||
class NetPacket;
|
||||
|
||||
struct SessionWrapper
|
||||
@@ -74,9 +74,9 @@ public:
|
||||
void Clear();
|
||||
unsigned GetRawSessionCount();
|
||||
|
||||
void SendToAllSessions(SenderThread &sender, boost::shared_ptr<NetPacket> packet, SessionData::State state);
|
||||
void SendLobbyMsgToAllSessions(SenderThread &sender, boost::shared_ptr<NetPacket> packet, SessionData::State state);
|
||||
void SendToAllButOneSessions(SenderThread &sender, boost::shared_ptr<NetPacket> packet, SessionId except, SessionData::State state);
|
||||
void SendToAllSessions(SenderInterface &sender, boost::shared_ptr<NetPacket> packet, SessionData::State state);
|
||||
void SendLobbyMsgToAllSessions(SenderInterface &sender, boost::shared_ptr<NetPacket> packet, SessionData::State state);
|
||||
void SendToAllButOneSessions(SenderInterface &sender, boost::shared_ptr<NetPacket> packet, SessionId except, SessionData::State state);
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user