Use one sender thread for everything, as there may occur conflicts with multiple sender threads. This is a temporary solution, the best solution would be having multiple sender threads, but sending all packets for the same target using the same thread, so that no packets are corrupted.

This commit is contained in:
lotodore
2007-11-22 19:11:45 +00:00
parent 6489f28e93
commit 49162870a1
3 changed files with 3 additions and 41 deletions
+1 -34
View File
@@ -22,7 +22,6 @@
#include <net/serverlobbythread.h>
#include <net/serverexception.h>
#include <net/senderthread.h>
#include <net/sendercallback.h>
#include <net/receiverhelper.h>
#include <net/socket_msg.h>
#include <core/loghelper.h>
@@ -35,32 +34,12 @@
using namespace std;
class GameSenderCallback : public SenderCallback
{
public:
GameSenderCallback(ServerGameThread &server) : m_server(server) {}
virtual ~GameSenderCallback() {}
virtual void SignalNetError(SessionId /*session*/, int /*errorID*/, int /*osErrorID*/)
{
// We just ignore send errors for now, on server side.
// A serious send error should trigger a read error or a read
// returning 0 afterwards, and we will handle this error.
}
private:
ServerGameThread &m_server;
};
ServerGameThread::ServerGameThread(ServerLobbyThread &lobbyThread, u_int32_t id, const string &name, const string &pwd, const GameData &gameData, unsigned adminPlayerId, GuiInterface &gui, ConfigFile *playerConfig)
: m_adminPlayerId(adminPlayerId), m_lobbyThread(lobbyThread), m_gui(gui),
m_gameData(gameData), m_id(id), m_name(name), m_password(pwd), m_playerConfig(playerConfig),
m_curState(NULL), m_gameNum(1),
m_stateTimer(boost::posix_time::time_duration(0, 0, 0), boost::timers::portable::microsec_timer::manual_start)
{
m_senderCallback.reset(new GameSenderCallback(*this));
m_sender.reset(new SenderThread(GetSenderCallback()));
m_receiver.reset(new ReceiverHelper);
}
@@ -127,7 +106,6 @@ void
ServerGameThread::Main()
{
SetState(SERVER_INITIAL_STATE::Instance());
GetSender().Run();
try
{
@@ -156,9 +134,6 @@ ServerGameThread::Main()
GetCallback().SignalNetServerError(e.GetErrorId(), e.GetOsErrorCode());
LOG_ERROR(e.what());
}
GetSender().SignalTermination();
if (!GetSender().Join(SENDER_THREAD_TERMINATE_TIMEOUT))
LOG_ERROR("Fatal error: Unable to terminated Sender Thread in Game.");
ResetComputerPlayerList();
GetLobbyThread().RemoveGame(GetId());
@@ -519,8 +494,7 @@ ServerGameThread::GetStateTimer()
SenderThread &
ServerGameThread::GetSender()
{
assert(m_sender.get());
return *m_sender;
return GetLobbyThread().GetSender();
}
ReceiverHelper &
@@ -574,13 +548,6 @@ ServerGameThread::CheckPassword(const string &password) const
return (password == m_password);
}
GameSenderCallback &
ServerGameThread::GetSenderCallback()
{
assert(m_senderCallback.get());
return *m_senderCallback;
}
GuiInterface &
ServerGameThread::GetGui()
{
-6
View File
@@ -31,10 +31,8 @@
#define GAME_THREAD_TERMINATE_TIMEOUT THREAD_WAIT_INFINITE
class SenderThread;
class ReceiverHelper;
class ServerLobbyThread;
class GameSenderCallback;
class ServerGameState;
class ConfigFile;
struct GameData;
@@ -118,7 +116,6 @@ protected:
const StartData &GetStartData() const;
void SetStartData(const StartData &startData);
GameSenderCallback &GetSenderCallback();
GuiInterface &GetGui();
unsigned GetNextGameNum();
@@ -143,8 +140,6 @@ private:
ServerLobbyThread &m_lobbyThread;
boost::shared_ptr<ReceiverHelper> m_receiver;
boost::shared_ptr<SenderThread> m_sender;
boost::shared_ptr<GameSenderCallback> m_senderCallback;
GuiInterface &m_gui;
const GameData m_gameData;
@@ -173,7 +168,6 @@ friend class ServerGameStateDealCardsDelay;
friend class ServerGameStateShowCardsDelay;
friend class ServerGameStateNextHandDelay;
friend class ServerGameStateNextGameDelay;
friend class GameSenderCallback;
};
#endif
+2 -1
View File
@@ -81,6 +81,8 @@ public:
ServerStats GetStats() const;
SenderThread &GetSender();
protected:
typedef std::deque<boost::shared_ptr<ConnectData> > ConnectQueue;
@@ -137,7 +139,6 @@ protected:
void ReadStatisticsFile();
void SaveStatisticsFile();
SenderThread &GetSender();
ReceiverHelper &GetReceiver();
bool CheckPassword(const std::string &password) const;