- 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"
// For gcc backtrace on crash!
#if defined(__GNUC__) && !defined(__MINGW32__)
#if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__FreeBSD__) && !defined(BSD)
#include <execinfo.h>
#include <cxxabi.h>
#include <signal.h>
@@ -201,7 +201,7 @@ public:
message(msg.c_str());
}
#ifdef __GNUC__
#if defined(__GNUC__) && !defined(__FreeBSD__) && !defined(BSD)
static int getFileAndLine(void *address, char *file, size_t flen) {
int line=-1;
static char buf[256]="";
@@ -261,7 +261,7 @@ public:
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 += "To find line #'s use:\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) {
char szBuf[4096]="";
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 Socket* getSocket() {return &serverSocket;}
virtual const Socket* getSocket() const {return &serverSocket;}
virtual void close();
//message processing
virtual void update();
virtual void updateLobby(){};
virtual void updateKeyframe(int frameCount);
virtual void waitUntilReady(Checksum* checksum);
const virtual Socket *getSocket() const
{
return &serverSocket;
}
// message sending
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 close();
virtual void update();
virtual void updateLobby()
{
}
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
virtual string getNetworkStatus() ;
SwitchSetupRequest **getSwitchSetupRequests()
{
return &switchSetupRequests[0];
}
ServerSocket* getServerSocket() {return &serverSocket;}
SwitchSetupRequest** getSwitchSetupRequests() {return &switchSetupRequests[0];}
void addSlot(int playerIndex);
bool switchSlot(int fromPlayerIndex,int toPlayerIndex);
void removeSlot(int playerIndex, int lockedSlotIndex=-1);
ConnectionSlot* getSlot(int playerIndex);
int getConnectedSlotCount();
int getOpenSlotCount();
void addSlot(int playerIndex);
bool switchSlot(int fromPlayerIndex, int toPlayerIndex);
void removeSlot(int playerIndex, int lockedSlotIndex = -1);
ConnectionSlot *getSlot(int playerIndex);
int getConnectedSlotCount();
int getOpenSlotCount();
bool launchGame(const GameSettings *gameSettings);
void setGameSettings(GameSettings *serverGameSettings, bool waitForClientAck);
void broadcastGameSetup(const GameSettings *gameSettings);
void updateListen();
virtual bool getConnectHasHandshaked() const
{
return false;
}
bool launchGame(const GameSettings* gameSettings);
void setGameSettings(GameSettings *serverGameSettings, bool waitForClientAck);
void broadcastGameSetup(const GameSettings* gameSettings);
void updateListen();
virtual bool getConnectHasHandshaked() const { return false; }
virtual void slotUpdateTask(ConnectionSlotEvent *event);
bool hasClientConnection();
int getCurrentFrameCount() const
{
return currentFrameCount;
}
virtual void slotUpdateTask(ConnectionSlotEvent *event);
bool hasClientConnection();
int getCurrentFrameCount() const { return currentFrameCount; }
std::pair<bool,bool> clientLagCheck(ConnectionSlot* connectionSlot,bool skipNetworkBroadCast=false);
std::pair<bool,bool> clientLagCheck(ConnectionSlot *connectionSlot, bool skipNetworkBroadCast = false);
bool signalClientReceiveCommands(ConnectionSlot *connectionSlot, int slotIndex, bool socketTriggered, ConnectionSlotEvent & event);
void updateSocketTriggeredList(std::map<PLATFORM_SOCKET,bool> & socketTriggeredList);
bool isPortBound() const
{
return serverSocket.isPortBound();
}
bool signalClientReceiveCommands(ConnectionSlot* connectionSlot,
int slotIndex,
bool socketTriggered,
ConnectionSlotEvent &event);
void updateSocketTriggeredList(std::map<PLATFORM_SOCKET,bool> &socketTriggeredList);
int getBindPort() const
{
return serverSocket.getBindPort();
}
bool isPortBound() const { return serverSocket.isPortBound(); }
int getBindPort() const { return serverSocket.getBindPort(); }
void broadcastPing(const NetworkMessagePing *networkMessage, int excludeSlot = -1)
{
this->broadcastMessage(networkMessage, excludeSlot);
}
void broadcastPing(const NetworkMessagePing* networkMessage, int excludeSlot= -1) {
this->broadcastMessage(networkMessage,excludeSlot);
}
void queueBroadcastMessage(const NetworkMessage *networkMessage, int excludeSlot = -1);
virtual string getHumanPlayerName(int index = -1);
virtual int getHumanPlayerIndex() const;
bool getNeedToRepublishToMasterserver() const
{
return needToRepublishToMasterserver;
}
void queueBroadcastMessage(const NetworkMessage *networkMessage, int excludeSlot=-1);
virtual string getHumanPlayerName(int index=-1);
virtual int getHumanPlayerIndex() const;
bool getNeedToRepublishToMasterserver() const {return needToRepublishToMasterserver;}
void setNeedToRepublishToMasterserver(bool value) {needToRepublishToMasterserver = value;}
void setNeedToRepublishToMasterserver(bool value)
{
needToRepublishToMasterserver = value;
}
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);
private:
void broadcastMessage(const NetworkMessage* networkMessage, int excludeSlot= -1,int lockedSlotIndex=-1);
void broadcastMessageToConnectedClients(const NetworkMessage* networkMessage, int excludeSlot = -1);
bool shouldDiscardNetworkMessage(NetworkMessageType networkMessageType,ConnectionSlot* connectionSlot);
void updateSlot(ConnectionSlotEvent *event);
void validateConnectedClients();
std::map<string,string> publishToMasterserver();
void broadcastMessage(const NetworkMessage *networkMessage, int excludeSlot = -1, int lockedSlotIndex = -1);
void broadcastMessageToConnectedClients(const NetworkMessage *networkMessage, int excludeSlot = -1);
bool shouldDiscardNetworkMessage(NetworkMessageType networkMessageType, ConnectionSlot *connectionSlot);
void updateSlot(ConnectionSlotEvent *event);
void validateConnectedClients();
std::map<string,string> publishToMasterserver();
int64 getNextEventId();
void processTextMessageQueue();
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

View File

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

View File

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