- updated for compiling on BSD

- also bugfix for socket broadcast segfault (partial fix)
This commit is contained in:
Mark Vejvoda
2011-01-13 01:46:32 +00:00
parent fec68c872a
commit 8c4cdd037c
5 changed files with 582 additions and 642 deletions

View File

@@ -37,7 +37,7 @@
#include "cache_manager.h" #include "cache_manager.h"
// For gcc backtrace on crash! // For gcc backtrace on crash!
#if defined(__GNUC__) && !defined(__MINGW32__) #if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__FreeBSD__) && !defined(BSD)
#include <execinfo.h> #include <execinfo.h>
#include <cxxabi.h> #include <cxxabi.h>
#include <signal.h> #include <signal.h>
@@ -201,7 +201,7 @@ public:
message(msg.c_str()); message(msg.c_str());
} }
#ifdef __GNUC__ #if defined(__GNUC__) && !defined(__FreeBSD__) && !defined(BSD)
static int getFileAndLine(void *address, char *file, size_t flen) { static int getFileAndLine(void *address, char *file, size_t flen) {
int line=-1; int line=-1;
static char buf[256]=""; static char buf[256]="";
@@ -261,7 +261,7 @@ public:
string errMsg = (msg != NULL ? msg : "null"); string errMsg = (msg != NULL ? msg : "null");
#if defined(__GNUC__) && !defined(__MINGW32__) #if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__FreeBSD__) && !defined(BSD)
errMsg += "\nStack Trace:\n"; errMsg += "\nStack Trace:\n";
//errMsg += "To find line #'s use:\n"; //errMsg += "To find line #'s use:\n";
//errMsg += "readelf --debug-dump=decodedline %s | egrep 0xaddress-of-stack\n"; //errMsg += "readelf --debug-dump=decodedline %s | egrep 0xaddress-of-stack\n";
@@ -416,7 +416,7 @@ public:
} }
}; };
#ifdef __GNUC__ #if defined(__GNUC__) && !defined(__FreeBSD__) && !defined(BSD)
void handleSIGSEGV(int sig) { void handleSIGSEGV(int sig) {
char szBuf[4096]=""; char szBuf[4096]="";
sprintf(szBuf, "In [%s::%s Line: %d] Error detected: signal %d:\n",__FILE__,__FUNCTION__,__LINE__, sig); sprintf(szBuf, "In [%s::%s Line: %d] Error detected: signal %d:\n",__FILE__,__FUNCTION__,__LINE__, sig);

File diff suppressed because it is too large Load Diff

View File

@@ -75,88 +75,112 @@ public:
virtual ~ServerInterface(); virtual ~ServerInterface();
virtual Socket* getSocket() {return &serverSocket;} virtual Socket* getSocket() {return &serverSocket;}
virtual const Socket* getSocket() const {return &serverSocket;}
virtual void close();
//message processing const virtual Socket *getSocket() const
virtual void update(); {
virtual void updateLobby(){}; return &serverSocket;
virtual void updateKeyframe(int frameCount); }
virtual void waitUntilReady(Checksum* checksum);
// message sending virtual void close();
virtual void sendTextMessage(const string &text, int teamIndex, bool echoLocal=false); virtual void update();
void sendTextMessage(const string &text, int teamIndex, bool echoLocal, int lockedSlotIndex); virtual void updateLobby()
void queueTextMessage(const string &text, int teamIndex, bool echoLocal=false); {
}
virtual void quitGame(bool userManuallyQuit); ;
virtual void updateKeyframe(int frameCount);
virtual void waitUntilReady(Checksum *checksum);
virtual void sendTextMessage(const string & text, int teamIndex, bool echoLocal = false);
void sendTextMessage(const string & text, int teamIndex, bool echoLocal, int lockedSlotIndex);
void queueTextMessage(const string & text, int teamIndex, bool echoLocal = false);
virtual void quitGame(bool userManuallyQuit);
virtual string getNetworkStatus();
ServerSocket *getServerSocket()
{
return &serverSocket;
}
//misc SwitchSetupRequest **getSwitchSetupRequests()
virtual string getNetworkStatus() ; {
return &switchSetupRequests[0];
}
ServerSocket* getServerSocket() {return &serverSocket;} void addSlot(int playerIndex);
SwitchSetupRequest** getSwitchSetupRequests() {return &switchSetupRequests[0];} bool switchSlot(int fromPlayerIndex, int toPlayerIndex);
void addSlot(int playerIndex); void removeSlot(int playerIndex, int lockedSlotIndex = -1);
bool switchSlot(int fromPlayerIndex,int toPlayerIndex); ConnectionSlot *getSlot(int playerIndex);
void removeSlot(int playerIndex, int lockedSlotIndex=-1); int getConnectedSlotCount();
ConnectionSlot* getSlot(int playerIndex); int getOpenSlotCount();
int getConnectedSlotCount(); bool launchGame(const GameSettings *gameSettings);
int getOpenSlotCount(); void setGameSettings(GameSettings *serverGameSettings, bool waitForClientAck);
void broadcastGameSetup(const GameSettings *gameSettings);
void updateListen();
virtual bool getConnectHasHandshaked() const
{
return false;
}
bool launchGame(const GameSettings* gameSettings); virtual void slotUpdateTask(ConnectionSlotEvent *event);
void setGameSettings(GameSettings *serverGameSettings, bool waitForClientAck); bool hasClientConnection();
void broadcastGameSetup(const GameSettings* gameSettings); int getCurrentFrameCount() const
void updateListen(); {
virtual bool getConnectHasHandshaked() const { return false; } return currentFrameCount;
}
virtual void slotUpdateTask(ConnectionSlotEvent *event); std::pair<bool,bool> clientLagCheck(ConnectionSlot *connectionSlot, bool skipNetworkBroadCast = false);
bool hasClientConnection(); bool signalClientReceiveCommands(ConnectionSlot *connectionSlot, int slotIndex, bool socketTriggered, ConnectionSlotEvent & event);
int getCurrentFrameCount() const { return currentFrameCount; } void updateSocketTriggeredList(std::map<PLATFORM_SOCKET,bool> & socketTriggeredList);
std::pair<bool,bool> clientLagCheck(ConnectionSlot* connectionSlot,bool skipNetworkBroadCast=false); bool isPortBound() const
{
return serverSocket.isPortBound();
}
bool signalClientReceiveCommands(ConnectionSlot* connectionSlot, int getBindPort() const
int slotIndex, {
bool socketTriggered, return serverSocket.getBindPort();
ConnectionSlotEvent &event); }
void updateSocketTriggeredList(std::map<PLATFORM_SOCKET,bool> &socketTriggeredList);
bool isPortBound() const { return serverSocket.isPortBound(); } void broadcastPing(const NetworkMessagePing *networkMessage, int excludeSlot = -1)
int getBindPort() const { return serverSocket.getBindPort(); } {
this->broadcastMessage(networkMessage, excludeSlot);
}
void broadcastPing(const NetworkMessagePing* networkMessage, int excludeSlot= -1) { void queueBroadcastMessage(const NetworkMessage *networkMessage, int excludeSlot = -1);
this->broadcastMessage(networkMessage,excludeSlot); virtual string getHumanPlayerName(int index = -1);
} virtual int getHumanPlayerIndex() const;
bool getNeedToRepublishToMasterserver() const
{
return needToRepublishToMasterserver;
}
void queueBroadcastMessage(const NetworkMessage *networkMessage, int excludeSlot=-1); void setNeedToRepublishToMasterserver(bool value)
{
virtual string getHumanPlayerName(int index=-1); needToRepublishToMasterserver = value;
virtual int getHumanPlayerIndex() const; }
bool getNeedToRepublishToMasterserver() const {return needToRepublishToMasterserver;}
void setNeedToRepublishToMasterserver(bool value) {needToRepublishToMasterserver = value;}
public: public:
Mutex *getServerSynchAccessor()
{
return &serverSynchAccessor;
}
Mutex * getServerSynchAccessor() { return &serverSynchAccessor; } virtual void simpleTask(BaseThread *callingThread);
void addClientToServerIPAddress(uint32 clientIp, uint32 ServerIp);
virtual void simpleTask(BaseThread *callingThread);
void addClientToServerIPAddress(uint32 clientIp,uint32 ServerIp);
virtual int isValidClientType(uint32 clientIp); virtual int isValidClientType(uint32 clientIp);
private: private:
void broadcastMessage(const NetworkMessage *networkMessage, int excludeSlot = -1, int lockedSlotIndex = -1);
void broadcastMessage(const NetworkMessage* networkMessage, int excludeSlot= -1,int lockedSlotIndex=-1); void broadcastMessageToConnectedClients(const NetworkMessage *networkMessage, int excludeSlot = -1);
void broadcastMessageToConnectedClients(const NetworkMessage* networkMessage, int excludeSlot = -1); bool shouldDiscardNetworkMessage(NetworkMessageType networkMessageType, ConnectionSlot *connectionSlot);
bool shouldDiscardNetworkMessage(NetworkMessageType networkMessageType,ConnectionSlot* connectionSlot); void updateSlot(ConnectionSlotEvent *event);
void updateSlot(ConnectionSlotEvent *event); void validateConnectedClients();
void validateConnectedClients(); std::map<string,string> publishToMasterserver();
std::map<string,string> publishToMasterserver();
int64 getNextEventId(); int64 getNextEventId();
void processTextMessageQueue(); void processTextMessageQueue();
void processBroadCastMessageQueue(); void processBroadCastMessageQueue();
void fsf(std::map<PLATFORM_SOCKET,bool> & socketTriggeredList, std::map<int,ConnectionSlotEvent> & eventList, std::map<int,bool> & mapSlotSignalledList);
protected:
void signalClientsToRecieveDataX(std::map<PLATFORM_SOCKET,bool> & socketTriggeredList, std::map<int,ConnectionSlotEvent> & eventList, std::map<int,bool> & mapSlotSignalledList);
void test(std::map<PLATFORM_SOCKET,bool> & socketTriggeredList, std::map<int,ConnectionSlotEvent> & eventList, std::map<int,bool> & mapSlotSignalledList);
}; };
}}//end namespace }}//end namespace

View File

@@ -206,6 +206,7 @@ private:
public: public:
BroadCastSocketThread(); BroadCastSocketThread();
virtual void execute(); virtual void execute();
virtual bool canShutdown(bool deleteSelfIfShutdownDelayed=false);
}; };
// ===================================================== // =====================================================

View File

@@ -1752,11 +1752,13 @@ void ServerSocket::stopBroadCastThread() {
if(broadCastThread != NULL) { if(broadCastThread != NULL) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
broadCastThread->shutdownAndWait(); if(broadCastThread->canShutdown(true) == true) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); if(broadCastThread->shutdownAndWait() == true) {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
delete broadCastThread; delete broadCastThread;
}
}
broadCastThread = NULL; broadCastThread = NULL;
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
@@ -2121,10 +2123,21 @@ BroadCastSocketThread::BroadCastSocketThread() : BaseThread() {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
} }
bool BroadCastSocketThread::canShutdown(bool deleteSelfIfShutdownDelayed) {
bool ret = (getExecutingTask() == false);
if(ret == false && deleteSelfIfShutdownDelayed == true) {
setDeleteSelfOnExecutionDone(deleteSelfIfShutdownDelayed);
signalQuit();
}
return ret;
}
void BroadCastSocketThread::execute() { void BroadCastSocketThread::execute() {
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//setRunningStatus(true); //setRunningStatus(true);
RunningStatusSafeWrapper runningStatus(this); RunningStatusSafeWrapper runningStatus(this);
ExecutingTaskSafeWrapper safeExecutingTaskMutex(this);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Broadcast thread is running\n"); SystemFlags::OutputDebug(SystemFlags::debugNetwork,"Broadcast thread is running\n");