mirror of
https://github.com/glest/glest-source.git
synced 2025-08-13 20:03:58 +02:00
revert network code back to beta1 code
This commit is contained in:
@@ -983,7 +983,7 @@ void ClientInterface::waitUntilReady(Checksum* checksum) {
|
||||
}
|
||||
|
||||
//delay the start a bit, so clients have more room to get messages
|
||||
sleep(200);
|
||||
sleep(100);
|
||||
|
||||
// This triggers LAG update packets to begin as required
|
||||
lastNetworkCommandListSendTime = time(NULL);
|
||||
|
@@ -32,18 +32,16 @@ namespace Glest{ namespace Game{
|
||||
// class ConnectionSlotThread
|
||||
// =====================================================
|
||||
|
||||
ConnectionSlotThread::ConnectionSlotThread(ConnectionSlot *slot) : BaseThread() {
|
||||
this->slot = slot;
|
||||
this->slotIndex = slot->getPlayerIndex();
|
||||
ConnectionSlotThread::ConnectionSlotThread(int slotIndex) : BaseThread() {
|
||||
this->slotIndex = slotIndex;
|
||||
this->slotInterface = NULL;
|
||||
//this->event = NULL;
|
||||
eventList.clear();
|
||||
eventList.reserve(100);
|
||||
}
|
||||
|
||||
ConnectionSlotThread::ConnectionSlotThread(ConnectionSlotCallbackInterface *slotInterface,ConnectionSlot *slot) : BaseThread() {
|
||||
this->slot = slot;
|
||||
this->slotIndex = slot->getPlayerIndex();
|
||||
ConnectionSlotThread::ConnectionSlotThread(ConnectionSlotCallbackInterface *slotInterface,int slotIndex) : BaseThread() {
|
||||
this->slotIndex = slotIndex;
|
||||
this->slotInterface = slotInterface;
|
||||
//this->event = NULL;
|
||||
eventList.clear();
|
||||
@@ -205,12 +203,10 @@ void ConnectionSlotThread::execute() {
|
||||
//this->slotInterface->slotUpdateTask(&eventCopy);
|
||||
this->slotUpdateTask(&eventCopy);
|
||||
setTaskCompleted(eventCopy.eventId);
|
||||
this->slot->signalSlotWorkerTaskCompleted();
|
||||
}
|
||||
}
|
||||
else {
|
||||
safeMutex.ReleaseLock();
|
||||
this->slot->signalSlotWorkerTaskCompleted();
|
||||
}
|
||||
|
||||
if(getQuitStatus() == true) {
|
||||
@@ -223,14 +219,12 @@ void ConnectionSlotThread::execute() {
|
||||
}
|
||||
catch(const exception &ex) {
|
||||
//setRunningStatus(false);
|
||||
this->slot->signalSlotWorkerTaskCompleted();
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
throw runtime_error(ex.what());
|
||||
}
|
||||
this->slot->signalSlotWorkerTaskCompleted();
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
}
|
||||
|
||||
@@ -256,7 +250,7 @@ ConnectionSlot::ConnectionSlot(ServerInterface* serverInterface, int playerIndex
|
||||
|
||||
this->setSocket(NULL);
|
||||
this->slotThreadWorker = NULL;
|
||||
this->slotThreadWorker = new ConnectionSlotThread(this->serverInterface,this);
|
||||
this->slotThreadWorker = new ConnectionSlotThread(this->serverInterface,playerIndex);
|
||||
this->slotThreadWorker->setUniqueID(__FILE__);
|
||||
this->slotThreadWorker->start();
|
||||
|
||||
@@ -292,15 +286,6 @@ ConnectionSlot::~ConnectionSlot() {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END\n",__FILE__,__FUNCTION__);
|
||||
}
|
||||
|
||||
void ConnectionSlot::signalSlotWorkerTaskCompleted() {
|
||||
semSlotWorkerTaskCompleted.signal();
|
||||
}
|
||||
|
||||
bool ConnectionSlot::waitSlotWorkerTaskCompleted(int waitMilliseconds) {
|
||||
int result = semSlotWorkerTaskCompleted.waitTillSignalled(waitMilliseconds);
|
||||
return (result == 0);
|
||||
}
|
||||
|
||||
void ConnectionSlot::updateSlot(ConnectionSlotEvent *event) {
|
||||
Chrono chrono;
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chrono.start();
|
||||
@@ -479,18 +464,17 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) {
|
||||
|
||||
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||
|
||||
//this->clearChatInfo();
|
||||
this->clearChatInfo();
|
||||
|
||||
//bool gotTextMsg = true;
|
||||
//for(;this->hasDataToRead() == true && gotTextMsg == true;) {
|
||||
for(;this->hasDataToRead() == true;) {
|
||||
bool gotTextMsg = true;
|
||||
for(;this->hasDataToRead() == true && gotTextMsg == true;) {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] polling for networkMessageType...\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
NetworkMessageType networkMessageType= getNextMessageType(false);
|
||||
NetworkMessageType networkMessageType= getNextMessageType();
|
||||
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] networkMessageType = %d\n",__FILE__,__FUNCTION__,__LINE__,networkMessageType);
|
||||
|
||||
//gotTextMsg = false;
|
||||
gotTextMsg = false;
|
||||
//process incoming commands
|
||||
switch(networkMessageType) {
|
||||
|
||||
@@ -529,7 +513,7 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) {
|
||||
if(receiveMessage(&networkMessageText)) {
|
||||
ChatMsgInfo msg(networkMessageText.getText().c_str(),networkMessageText.getTeamIndex(),networkMessageText.getPlayerIndex(),networkMessageText.getTargetLanguage());
|
||||
this->addChatInfo(msg);
|
||||
//gotTextMsg = true;
|
||||
gotTextMsg = true;
|
||||
}
|
||||
else {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugError).enabled) SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d]\nInvalid message type before intro handshake [%d]\nDisconnecting socket for slot: %d [%s].\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,networkMessageType,this->playerIndex,this->getIpAddress().c_str());
|
||||
@@ -561,13 +545,11 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) {
|
||||
lastReceiveCommandListTime = time(NULL);
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] currentFrameCount = %d\n",__FILE__,__FUNCTION__,__LINE__,currentFrameCount);
|
||||
|
||||
if(networkMessageCommandList.getCommandCount() > 0) {
|
||||
MutexSafeWrapper safeMutexSlot(&mutexPendingNetworkCommandList,CODE_AT_LINE);
|
||||
for(int i = 0; i < networkMessageCommandList.getCommandCount(); ++i) {
|
||||
vctPendingNetworkCommandList.push_back(*networkMessageCommandList.getCommand(i));
|
||||
}
|
||||
safeMutexSlot.ReleaseLock();
|
||||
MutexSafeWrapper safeMutexSlot(&mutexPendingNetworkCommandList,CODE_AT_LINE);
|
||||
for(int i = 0; i < networkMessageCommandList.getCommandCount(); ++i) {
|
||||
vctPendingNetworkCommandList.push_back(*networkMessageCommandList.getCommand(i));
|
||||
}
|
||||
safeMutexSlot.ReleaseLock();
|
||||
}
|
||||
else {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugError).enabled) SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d]\nInvalid message type before intro handshake [%d]\nDisconnecting socket for slot: %d [%s].\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,networkMessageType,this->playerIndex,this->getIpAddress().c_str());
|
||||
@@ -1084,7 +1066,7 @@ bool ConnectionSlot::updateCompleted(ConnectionSlotEvent *event) {
|
||||
}
|
||||
|
||||
void ConnectionSlot::sendMessage(const NetworkMessage* networkMessage) {
|
||||
//MutexSafeWrapper safeMutex(&socketSynchAccessor,CODE_AT_LINE);
|
||||
MutexSafeWrapper safeMutex(&socketSynchAccessor,CODE_AT_LINE);
|
||||
|
||||
// Skip text messages not intended for the players preferred language
|
||||
const NetworkMessageText *textMsg = dynamic_cast<const NetworkMessageText *>(networkMessage);
|
||||
@@ -1126,90 +1108,72 @@ void ConnectionSlot::clearPendingNetworkCommandList() {
|
||||
safeMutexSlot.ReleaseLock();
|
||||
}
|
||||
|
||||
//bool ConnectionSlot::hasValidSocketId() {
|
||||
// //bool result = (this->getSocket() != NULL && this->getSocket()->getSocketId() > 0);
|
||||
// //return result;
|
||||
// bool result = false;
|
||||
// MutexSafeWrapper safeMutexSlot(&mutexSocket,CODE_AT_LINE);
|
||||
// if(socket != NULL && socket->getSocketId() > 0) {
|
||||
// result = true;
|
||||
// }
|
||||
// return result;
|
||||
//
|
||||
//}
|
||||
bool ConnectionSlot::hasValidSocketId() {
|
||||
//bool result = (this->getSocket() != NULL && this->getSocket()->getSocketId() > 0);
|
||||
//return result;
|
||||
bool result = false;
|
||||
MutexSafeWrapper safeMutexSlot(&mutexSocket,CODE_AT_LINE);
|
||||
if(socket != NULL && socket->getSocketId() > 0) {
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
bool ConnectionSlot::isConnected() {
|
||||
bool result = false;
|
||||
//MutexSafeWrapper safeMutexSlot(&mutexSocket,CODE_AT_LINE);
|
||||
ReadWriteMutexSafeWrapper safeRWL(&socketRWLMutex,true,CODE_AT_LINE);
|
||||
MutexSafeWrapper safeMutexSlot(&mutexSocket,CODE_AT_LINE);
|
||||
if(socket != NULL && socket->isConnected() == true) {
|
||||
result = true;
|
||||
}
|
||||
//socketRWLMutex.unlockRead();
|
||||
return result;
|
||||
}
|
||||
|
||||
PLATFORM_SOCKET ConnectionSlot::getSocketId() {
|
||||
PLATFORM_SOCKET result = 0;
|
||||
//MutexSafeWrapper safeMutexSlot(&mutexSocket,CODE_AT_LINE);
|
||||
ReadWriteMutexSafeWrapper safeRWL(&socketRWLMutex,true,CODE_AT_LINE);
|
||||
MutexSafeWrapper safeMutexSlot(&mutexSocket,CODE_AT_LINE);
|
||||
if(socket != NULL) {
|
||||
result = socket->getSocketId();
|
||||
}
|
||||
//socketRWLMutex.unlockRead();
|
||||
return result;
|
||||
}
|
||||
|
||||
pair<bool,Socket*> ConnectionSlot::getSocketInfo() {
|
||||
pair<bool,Socket*> result;
|
||||
//MutexSafeWrapper safeMutexSlot(&mutexSocket,CODE_AT_LINE);
|
||||
ReadWriteMutexSafeWrapper safeRWL(&socketRWLMutex,true,CODE_AT_LINE);
|
||||
MutexSafeWrapper safeMutexSlot(&mutexSocket,CODE_AT_LINE);
|
||||
result.first = (socket != NULL && socket->isConnected());
|
||||
result.second = socket;
|
||||
//socketRWLMutex.unlockRead();
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
Socket* ConnectionSlot::getSocket(bool mutexLock) {
|
||||
Socket *result = NULL;
|
||||
//MutexSafeWrapper safeMutexSlot(NULL,CODE_AT_LINE);
|
||||
ReadWriteMutexSafeWrapper safeRWL(&socketRWLMutex,true,CODE_AT_LINE);
|
||||
MutexSafeWrapper safeMutexSlot(NULL,CODE_AT_LINE);
|
||||
if(mutexLock == true) {
|
||||
//safeMutexSlot.setMutex(&mutexSocket,CODE_AT_LINE);
|
||||
safeMutexSlot.setMutex(&mutexSocket,CODE_AT_LINE);
|
||||
}
|
||||
result = socket;
|
||||
//socketRWLMutex.unlockRead();
|
||||
|
||||
return result;
|
||||
return socket;
|
||||
}
|
||||
|
||||
void ConnectionSlot::setSocket(Socket *newSocket) {
|
||||
//MutexSafeWrapper safeMutexSlot(&mutexSocket,CODE_AT_LINE);
|
||||
ReadWriteMutexSafeWrapper safeRWL(&socketRWLMutex,false,CODE_AT_LINE);
|
||||
MutexSafeWrapper safeMutexSlot(&mutexSocket,CODE_AT_LINE);
|
||||
socket = newSocket;
|
||||
//socketRWLMutex.unlockWrite();
|
||||
}
|
||||
|
||||
void ConnectionSlot::deleteSocket() {
|
||||
//MutexSafeWrapper safeMutexSlot(&mutexSocket,CODE_AT_LINE);
|
||||
ReadWriteMutexSafeWrapper safeRWL(&socketRWLMutex,false,CODE_AT_LINE);
|
||||
MutexSafeWrapper safeMutexSlot(&mutexSocket,CODE_AT_LINE);
|
||||
delete socket;
|
||||
socket = NULL;
|
||||
//socketRWLMutex.unlockWrite();
|
||||
}
|
||||
|
||||
bool ConnectionSlot::hasDataToRead() {
|
||||
bool result = false;
|
||||
//MutexSafeWrapper safeMutexSlot(&mutexSocket,CODE_AT_LINE);
|
||||
ReadWriteMutexSafeWrapper safeRWL(&socketRWLMutex,true,CODE_AT_LINE);
|
||||
MutexSafeWrapper safeMutexSlot(&mutexSocket,CODE_AT_LINE);
|
||||
|
||||
if(socket != NULL && socket->hasDataToRead() == true) {
|
||||
result = true;
|
||||
}
|
||||
//socketRWLMutex.unlockRead();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@@ -78,7 +78,6 @@ protected:
|
||||
Mutex triggerIdMutex;
|
||||
vector<ConnectionSlotEvent> eventList;
|
||||
int slotIndex;
|
||||
ConnectionSlot *slot;
|
||||
|
||||
virtual void setQuitStatus(bool value);
|
||||
virtual void setTaskCompleted(int eventId);
|
||||
@@ -87,8 +86,8 @@ protected:
|
||||
void slotUpdateTask(ConnectionSlotEvent *event);
|
||||
|
||||
public:
|
||||
ConnectionSlotThread(ConnectionSlot *slot);
|
||||
ConnectionSlotThread(ConnectionSlotCallbackInterface *slotInterface,ConnectionSlot *slot);
|
||||
ConnectionSlotThread(int slotIndex);
|
||||
ConnectionSlotThread(ConnectionSlotCallbackInterface *slotInterface,int slotIndex);
|
||||
virtual void execute();
|
||||
void signalUpdate(ConnectionSlotEvent *event);
|
||||
bool isSignalCompleted(ConnectionSlotEvent *event);
|
||||
@@ -107,12 +106,8 @@ class ConnectionSlot: public NetworkInterface {
|
||||
private:
|
||||
ServerInterface* serverInterface;
|
||||
|
||||
Semaphore semSlotWorkerTaskCompleted;
|
||||
|
||||
//Mutex mutexSocket;
|
||||
ReadWriteMutex socketRWLMutex;
|
||||
Mutex mutexSocket;
|
||||
Socket* socket;
|
||||
|
||||
int playerIndex;
|
||||
string name;
|
||||
bool ready;
|
||||
@@ -140,9 +135,6 @@ public:
|
||||
ConnectionSlot(ServerInterface* serverInterface, int playerIndex);
|
||||
~ConnectionSlot();
|
||||
|
||||
void signalSlotWorkerTaskCompleted();
|
||||
bool waitSlotWorkerTaskCompleted(int waitMilliseconds=-1);
|
||||
|
||||
void update(bool checkForNewClients,int lockedSlotIndex);
|
||||
void setPlayerIndex(int value) { playerIndex = value; }
|
||||
int getPlayerIndex() const {return playerIndex;}
|
||||
@@ -163,7 +155,7 @@ public:
|
||||
bool getReceivedNetworkGameStatus() const { return receivedNetworkGameStatus; }
|
||||
void setReceivedNetworkGameStatus(bool value) { receivedNetworkGameStatus = value; }
|
||||
|
||||
//bool hasValidSocketId();
|
||||
bool hasValidSocketId();
|
||||
virtual bool getConnectHasHandshaked() const { return gotIntro; }
|
||||
std::vector<std::string> getThreadErrorList() const { return threadErrorList; }
|
||||
void clearThreadErrorList() { threadErrorList.clear(); }
|
||||
|
@@ -44,33 +44,25 @@ void NetworkInterface::sendMessage(const NetworkMessage* networkMessage){
|
||||
networkMessage->send(socket);
|
||||
}
|
||||
|
||||
NetworkMessageType NetworkInterface::getNextMessageType(bool checkHasData)
|
||||
NetworkMessageType NetworkInterface::getNextMessageType()
|
||||
{
|
||||
Socket* socket= getSocket(false);
|
||||
int8 messageType= nmtInvalid;
|
||||
|
||||
if(socket != NULL && (checkHasData == false || socket->hasDataToRead() == true)) {
|
||||
if(socket != NULL &&
|
||||
socket->hasDataToRead() == true) {
|
||||
//peek message type
|
||||
bool peekForMessageType = !checkHasData;
|
||||
if(checkHasData == true) {
|
||||
int dataSize = socket->getDataToRead();
|
||||
if(dataSize >= sizeof(messageType)) {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] socket->getDataToRead() dataSize = %d\n",__FILE__,__FUNCTION__,__LINE__,dataSize);
|
||||
peekForMessageType = true;
|
||||
//int iPeek = socket->peek(&messageType, sizeof(messageType));
|
||||
|
||||
//if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] socket->getDataToRead() iPeek = %d, messageType = %d [size = %d]\n",__FILE__,__FUNCTION__,__LINE__,iPeek,messageType,sizeof(messageType));
|
||||
}
|
||||
else {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] PEEK WARNING, socket->getDataToRead() messageType = %d [size = %d], dataSize = %d\n",__FILE__,__FUNCTION__,__LINE__,messageType,sizeof(messageType),dataSize);
|
||||
}
|
||||
}
|
||||
|
||||
if(peekForMessageType == true) {
|
||||
int iPeek = socket->peek(&messageType, sizeof(messageType));
|
||||
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] socket->getDataToRead() iPeek = %d, messageType = %d [size = %d]\n",__FILE__,__FUNCTION__,__LINE__,iPeek,messageType,sizeof(messageType));
|
||||
}
|
||||
else {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] PEEK WARNING, socket->getDataToRead() messageType = %d [size = %d], dataSize = %d\n",__FILE__,__FUNCTION__,__LINE__,messageType,sizeof(messageType),dataSize);
|
||||
}
|
||||
|
||||
//sanity check new message type
|
||||
if(messageType < 0 || messageType >= nmtCount) {
|
||||
|
@@ -120,7 +120,7 @@ public:
|
||||
string getHostName() const {return Socket::getHostName();}
|
||||
|
||||
virtual void sendMessage(const NetworkMessage* networkMessage);
|
||||
NetworkMessageType getNextMessageType(bool checkHasData=true);
|
||||
NetworkMessageType getNextMessageType();
|
||||
bool receiveMessage(NetworkMessage* networkMessage);
|
||||
|
||||
virtual bool isConnected();
|
||||
|
@@ -169,8 +169,7 @@ ServerInterface::~ServerInterface() {
|
||||
exitServer = true;
|
||||
for(int i= 0; i < GameConstants::maxPlayers; ++i) {
|
||||
if(slots[i] != NULL) {
|
||||
//MutexSafeWrapper safeMutex(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],false,CODE_AT_LINE_X(i));
|
||||
MutexSafeWrapper safeMutex(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
delete slots[i];
|
||||
slots[i]=NULL;
|
||||
}
|
||||
@@ -204,8 +203,7 @@ int ServerInterface::isValidClientType(uint32 clientIp) {
|
||||
int result = 0;
|
||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||
if(slots[i] != NULL) {
|
||||
//MutexSafeWrapper safeMutex(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
||||
MutexSafeWrapper safeMutex(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
|
||||
Socket *socket = slots[i]->getSocket();
|
||||
if(socket != NULL) {
|
||||
@@ -234,10 +232,7 @@ void ServerInterface::addSlot(int playerIndex) {
|
||||
}
|
||||
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[playerIndex],CODE_AT_LINE_X(playerIndex));
|
||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[playerIndex],false,CODE_AT_LINE_X(i));
|
||||
|
||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[playerIndex],CODE_AT_LINE_X(playerIndex));
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
ConnectionSlot *slot = slots[playerIndex];
|
||||
if(slot != NULL) {
|
||||
@@ -245,7 +240,7 @@ void ServerInterface::addSlot(int playerIndex) {
|
||||
}
|
||||
slots[playerIndex] = new ConnectionSlot(this, playerIndex);
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
safeRWL.ReleaseLock();
|
||||
safeMutexSlot.ReleaseLock();
|
||||
delete slot;
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
safeMutex.ReleaseLock();
|
||||
@@ -264,12 +259,8 @@ bool ServerInterface::switchSlot(int fromPlayerIndex, int toPlayerIndex) {
|
||||
}
|
||||
|
||||
MutexSafeWrapper safeMutex(&serverSynchAccessor,CODE_AT_LINE);
|
||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[fromPlayerIndex],CODE_AT_LINE_X(fromPlayerIndex));
|
||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[fromPlayerIndex],false,CODE_AT_LINE_X(i));
|
||||
|
||||
//MutexSafeWrapper safeMutexSlot2(&slotAccessorMutexes[toPlayerIndex],CODE_AT_LINE_X(toPlayerIndex));
|
||||
ReadWriteMutexSafeWrapper safeRWL2(&slotAccessorMutexes[toPlayerIndex],false,CODE_AT_LINE_X(i));
|
||||
|
||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[fromPlayerIndex],CODE_AT_LINE_X(fromPlayerIndex));
|
||||
MutexSafeWrapper safeMutexSlot2(&slotAccessorMutexes[toPlayerIndex],CODE_AT_LINE_X(toPlayerIndex));
|
||||
if(slots[toPlayerIndex] != NULL && slots[toPlayerIndex] != NULL &&
|
||||
slots[toPlayerIndex]->isConnected() == false) {
|
||||
slots[fromPlayerIndex]->setPlayerIndex(toPlayerIndex);
|
||||
@@ -280,14 +271,14 @@ bool ServerInterface::switchSlot(int fromPlayerIndex, int toPlayerIndex) {
|
||||
safeMutex.ReleaseLock();
|
||||
PlayerIndexMessage playerIndexMessage(toPlayerIndex);
|
||||
slots[toPlayerIndex]->sendMessage(&playerIndexMessage);
|
||||
safeRWL.ReleaseLock();
|
||||
safeRWL2.ReleaseLock();
|
||||
safeMutexSlot.ReleaseLock();
|
||||
safeMutexSlot2.ReleaseLock();
|
||||
result = true;
|
||||
updateListen();
|
||||
}
|
||||
else {
|
||||
safeRWL.ReleaseLock();
|
||||
safeRWL2.ReleaseLock();
|
||||
safeMutexSlot.ReleaseLock();
|
||||
safeMutexSlot2.ReleaseLock();
|
||||
safeMutex.ReleaseLock();
|
||||
}
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
@@ -298,11 +289,10 @@ void ServerInterface::removeSlot(int playerIndex, int lockedSlotIndex) {
|
||||
Lang &lang= Lang::getInstance();
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex);
|
||||
MutexSafeWrapper safeMutex(&serverSynchAccessor,CODE_AT_LINE);
|
||||
//MutexSafeWrapper safeMutexSlot(NULL,CODE_AT_LINE_X(playerIndex));
|
||||
ReadWriteMutexSafeWrapper safeRWL(NULL,false,CODE_AT_LINE_X(i));
|
||||
MutexSafeWrapper safeMutexSlot(NULL,CODE_AT_LINE_X(playerIndex));
|
||||
if(playerIndex != lockedSlotIndex) {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex);
|
||||
safeRWL.setReadWriteMutex(&slotAccessorMutexes[playerIndex],false,CODE_AT_LINE_X(playerIndex));
|
||||
safeMutexSlot.setMutex(&slotAccessorMutexes[playerIndex],CODE_AT_LINE_X(playerIndex));
|
||||
}
|
||||
ConnectionSlot *slot = slots[playerIndex];
|
||||
bool notifyDisconnect = false;
|
||||
@@ -334,7 +324,7 @@ void ServerInterface::removeSlot(int playerIndex, int lockedSlotIndex) {
|
||||
}
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex);
|
||||
slots[playerIndex]= NULL;
|
||||
safeRWL.ReleaseLock();
|
||||
safeMutexSlot.ReleaseLock();
|
||||
safeMutex.ReleaseLock();
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] playerIndex = %d, lockedSlotIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,playerIndex,lockedSlotIndex);
|
||||
delete slot;
|
||||
@@ -356,16 +346,14 @@ void ServerInterface::removeSlot(int playerIndex, int lockedSlotIndex) {
|
||||
}
|
||||
|
||||
ConnectionSlot *ServerInterface::getSlot(int playerIndex) {
|
||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[playerIndex],CODE_AT_LINE_X(i));
|
||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[playerIndex],true,CODE_AT_LINE_X(i));
|
||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[playerIndex],CODE_AT_LINE_X(i));
|
||||
ConnectionSlot *result = slots[playerIndex];
|
||||
return result;
|
||||
}
|
||||
|
||||
bool ServerInterface::isClientConnected(int index) {
|
||||
bool result = false;
|
||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[index],CODE_AT_LINE_X(i));
|
||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[index],true,CODE_AT_LINE_X(i));
|
||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[index],CODE_AT_LINE_X(i));
|
||||
if(slots[index] != NULL && slots[index]->isConnected() == true) {
|
||||
result = true;
|
||||
}
|
||||
@@ -386,8 +374,7 @@ bool ServerInterface::hasClientConnection() {
|
||||
int ServerInterface::getConnectedSlotCount() {
|
||||
int connectedSlotCount = 0;
|
||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
if(slots[i] != NULL) {
|
||||
++connectedSlotCount;
|
||||
}
|
||||
@@ -669,8 +656,7 @@ bool ServerInterface::signalClientReceiveCommands(ConnectionSlot *connectionSlot
|
||||
|
||||
void ServerInterface::updateSocketTriggeredList(std::map<PLATFORM_SOCKET,bool> & socketTriggeredList) {
|
||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ConnectionSlot* connectionSlot= slots[i];
|
||||
if(connectionSlot != NULL) {
|
||||
PLATFORM_SOCKET clientSocket = connectionSlot->getSocketId();
|
||||
@@ -683,8 +669,7 @@ void ServerInterface::updateSocketTriggeredList(std::map<PLATFORM_SOCKET,bool> &
|
||||
|
||||
void ServerInterface::validateConnectedClients() {
|
||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ConnectionSlot* connectionSlot = slots[i];
|
||||
if(connectionSlot != NULL) {
|
||||
connectionSlot->validateConnection();
|
||||
@@ -697,8 +682,7 @@ void ServerInterface::signalClientsToRecieveData(std::map<PLATFORM_SOCKET,bool>
|
||||
std::map<int,bool> & mapSlotSignalledList) {
|
||||
//bool checkForNewClients = true;
|
||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ConnectionSlot* connectionSlot = slots[i];
|
||||
|
||||
bool socketTriggered = false;
|
||||
@@ -728,8 +712,7 @@ void ServerInterface::checkForCompletedClients(std::map<int,bool> & mapSlotSigna
|
||||
|
||||
//printf("===> START slot %d [%p] - About to checkForCompletedClients\n",i,slots[i]);
|
||||
|
||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
|
||||
//printf("===> IN slot %d - About to checkForCompletedClients\n",i);
|
||||
|
||||
@@ -789,8 +772,7 @@ void ServerInterface::checkForLaggingClients(std::map<int,bool> &mapSlotSignalle
|
||||
threadsDone = true;
|
||||
// Examine all threads for completion of delegation
|
||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ConnectionSlot* connectionSlot = slots[i];
|
||||
if(connectionSlot != NULL && mapSlotSignalledList[i] == true &&
|
||||
slotsCompleted.find(i) == slotsCompleted.end()) {
|
||||
@@ -900,59 +882,10 @@ void ServerInterface::checkForLaggingClients(std::map<int,bool> &mapSlotSignalle
|
||||
}
|
||||
}
|
||||
|
||||
void ServerInterface::checkForLaggingClients(std::vector <string> &errorMsgList) {
|
||||
bool lastGlobalLagCheckTimeUpdate = false;
|
||||
time_t waitForClientsElapsed = time(NULL);
|
||||
time_t waitForThreadElapsed = time(NULL);
|
||||
std::map<int,bool> slotsWarnedList;
|
||||
// Examine all threads for completion of delegation
|
||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
||||
ConnectionSlot* connectionSlot = slots[i];
|
||||
|
||||
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
|
||||
try {
|
||||
if(gameHasBeenInitiated == true &&
|
||||
difftime(time(NULL),lastGlobalLagCheckTime) >= LAG_CHECK_GRACE_PERIOD) {
|
||||
|
||||
//printf("\n\n\n^^^^^^^^^^^^^^ PART A\n\n\n");
|
||||
|
||||
// New lag check
|
||||
std::pair<bool,bool> clientLagExceededOrWarned = std::make_pair(false,false);
|
||||
if( gameHasBeenInitiated == true && connectionSlot != NULL &&
|
||||
connectionSlot->isConnected() == true) {
|
||||
//printf("\n\n\n^^^^^^^^^^^^^^ PART B\n\n\n");
|
||||
|
||||
lastGlobalLagCheckTimeUpdate = true;
|
||||
clientLagExceededOrWarned = clientLagCheck(connectionSlot,slotsWarnedList[i]);
|
||||
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] clientLagExceededOrWarned.first = %d, clientLagExceededOrWarned.second = %d, gameSettings.getNetworkPauseGameForLaggedClients() = %d\n",__FILE__,__FUNCTION__,__LINE__,clientLagExceededOrWarned.first,clientLagExceededOrWarned.second,gameSettings.getNetworkPauseGameForLaggedClients());
|
||||
|
||||
if(clientLagExceededOrWarned.first == true) {
|
||||
slotsWarnedList[i] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(const exception &ex) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] error detected [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
||||
errorMsgList.push_back(ex.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(lastGlobalLagCheckTimeUpdate == true) {
|
||||
lastGlobalLagCheckTime = time(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void ServerInterface::executeNetworkCommandsFromClients() {
|
||||
if(gameHasBeenInitiated == true) {
|
||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ConnectionSlot* connectionSlot= slots[i];
|
||||
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
|
||||
vector<NetworkCommand> pendingList = connectionSlot->getPendingNetworkCommandList(true);
|
||||
@@ -969,19 +902,18 @@ void ServerInterface::executeNetworkCommandsFromClients() {
|
||||
|
||||
void ServerInterface::dispatchPendingChatMessages(std::vector <string> &errorMsgList) {
|
||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ConnectionSlot* connectionSlot= slots[i];
|
||||
if(connectionSlot != NULL &&
|
||||
connectionSlot->getChatTextList(false).empty() == false) {
|
||||
std::vector<ChatMsgInfo> chatList = connectionSlot->getChatTextList(true);
|
||||
try {
|
||||
std::vector<ChatMsgInfo> chatText = connectionSlot->getChatTextList(true);
|
||||
for(int chatIdx = 0;
|
||||
exitServer == false && slots[i] != NULL &&
|
||||
chatIdx < chatList.size(); chatIdx++) {
|
||||
chatIdx < chatText.size(); chatIdx++) {
|
||||
connectionSlot= slots[i];
|
||||
if(connectionSlot != NULL) {
|
||||
ChatMsgInfo msg(chatList[chatIdx]);
|
||||
ChatMsgInfo msg(chatText[chatIdx]);
|
||||
this->addChatInfo(msg);
|
||||
|
||||
string newChatText = msg.chatText.c_str();
|
||||
@@ -1003,9 +935,9 @@ void ServerInterface::dispatchPendingChatMessages(std::vector <string> &errorMsg
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] i = %d\n",__FILE__,__FUNCTION__,__LINE__,i);
|
||||
// Its possible that the slot is disconnected here
|
||||
// so check the original pointer again
|
||||
//if(slots[i] != NULL) {
|
||||
// slots[i]->clearChatInfo();
|
||||
//}
|
||||
if(slots[i] != NULL) {
|
||||
slots[i]->clearChatInfo();
|
||||
}
|
||||
}
|
||||
catch(const exception &ex) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
||||
@@ -1016,37 +948,6 @@ void ServerInterface::dispatchPendingChatMessages(std::vector <string> &errorMsg
|
||||
}
|
||||
}
|
||||
|
||||
void ServerInterface::waitForSignalledClients(std::map<int,bool> &mapSlotSignalledList,std::vector <string> &errorMsgList) {
|
||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||
if(mapSlotSignalledList[i] == true) {
|
||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
||||
ConnectionSlot* connectionSlot= slots[i];
|
||||
safeRWL.ReleaseLock(true);
|
||||
if(connectionSlot != NULL) {
|
||||
connectionSlot->waitSlotWorkerTaskCompleted(4000);
|
||||
|
||||
safeRWL.Lock();
|
||||
connectionSlot= slots[i];
|
||||
if(connectionSlot != NULL) {
|
||||
std::vector<std::string> errorList = connectionSlot->getThreadErrorList();
|
||||
// Collect any collected errors from threads
|
||||
if(errorList.empty() == false) {
|
||||
for(int iErrIdx = 0; iErrIdx < errorList.size(); ++iErrIdx) {
|
||||
string &sErr = errorList[iErrIdx];
|
||||
if(sErr != "") {
|
||||
errorMsgList.push_back(sErr);
|
||||
}
|
||||
}
|
||||
connectionSlot->clearThreadErrorList();
|
||||
}
|
||||
}
|
||||
safeRWL.ReleaseLock();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ServerInterface::update() {
|
||||
Chrono chrono;
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chrono.start();
|
||||
@@ -1097,18 +998,14 @@ void ServerInterface::update() {
|
||||
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||
|
||||
waitForSignalledClients(mapSlotSignalledList,errorMsgList);
|
||||
|
||||
/*
|
||||
// Step #2 check all connection slot worker threads for completed status
|
||||
checkForCompletedClients(mapSlotSignalledList,errorMsgList, eventList);
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ============ Step #3\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||
*/
|
||||
|
||||
// Step #3 check clients for any lagging scenarios and try to deal with them
|
||||
//checkForLaggingClients(mapSlotSignalledList, eventList, socketTriggeredList,errorMsgList);
|
||||
checkForLaggingClients(errorMsgList);
|
||||
checkForLaggingClients(mapSlotSignalledList, eventList, socketTriggeredList,errorMsgList);
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ============ Step #4\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||
@@ -1130,9 +1027,9 @@ void ServerInterface::update() {
|
||||
//printf("\nServerInterface::update -- E1\n");
|
||||
|
||||
//std::map<int,ConnectionSlotEvent> eventList;
|
||||
//std::map<int,bool> mapSlotSignalledList;
|
||||
//checkForLaggingClients(mapSlotSignalledList, eventList, socketTriggeredList,errorMsgList);
|
||||
checkForLaggingClients(errorMsgList);
|
||||
std::map<int,bool> mapSlotSignalledList;
|
||||
|
||||
checkForLaggingClients(mapSlotSignalledList, eventList, socketTriggeredList,errorMsgList);
|
||||
}
|
||||
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took %lld msecs\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||
@@ -1141,10 +1038,10 @@ void ServerInterface::update() {
|
||||
difftime(time(NULL),lastGlobalLagCheckTime) >= LAG_CHECK_GRACE_PERIOD) {
|
||||
//printf("\nServerInterface::update -- F\n");
|
||||
|
||||
//std::map<int,ConnectionSlotEvent> eventList;
|
||||
//std::map<int,bool> mapSlotSignalledList;
|
||||
//checkForLaggingClients(mapSlotSignalledList, eventList, socketTriggeredList,errorMsgList);
|
||||
checkForLaggingClients(errorMsgList);
|
||||
std::map<int,ConnectionSlotEvent> eventList;
|
||||
std::map<int,bool> mapSlotSignalledList;
|
||||
|
||||
checkForLaggingClients(mapSlotSignalledList, eventList, socketTriggeredList,errorMsgList);
|
||||
}
|
||||
|
||||
//printf("\nServerInterface::update -- G\n");
|
||||
@@ -1335,8 +1232,7 @@ void ServerInterface::waitUntilReady(Checksum *checksum) {
|
||||
vector<string> waitingForHosts;
|
||||
allReady= true;
|
||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ConnectionSlot* connectionSlot= slots[i];
|
||||
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
|
||||
if(connectionSlot->isReady() == false) {
|
||||
@@ -1415,8 +1311,7 @@ void ServerInterface::waitUntilReady(Checksum *checksum) {
|
||||
uint32 loadingStatus = nmls_NONE;
|
||||
//send ready message after, so clients start delayed
|
||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ConnectionSlot* connectionSlot= slots[i];
|
||||
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
|
||||
switch(i) {
|
||||
@@ -1474,8 +1369,7 @@ void ServerInterface::waitUntilReady(Checksum *checksum) {
|
||||
|
||||
// send loading status message
|
||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ConnectionSlot* connectionSlot= slots[i];
|
||||
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
|
||||
NetworkMessageLoadingStatus networkMessageLoadingStatus(loadingStatus);
|
||||
@@ -1511,8 +1405,7 @@ void ServerInterface::waitUntilReady(Checksum *checksum) {
|
||||
try {
|
||||
//send ready message after, so clients start delayed
|
||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ConnectionSlot* connectionSlot= slots[i];
|
||||
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
|
||||
NetworkMessageReady networkMessageReady(checksum->getSum());
|
||||
@@ -1608,8 +1501,7 @@ string ServerInterface::getNetworkStatus() {
|
||||
Lang &lang = Lang::getInstance();
|
||||
string str="";
|
||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ConnectionSlot* connectionSlot= slots[i];
|
||||
|
||||
str+= intToStr(i)+ ": ";
|
||||
@@ -1638,8 +1530,7 @@ bool ServerInterface::launchGame(const GameSettings *gameSettings) {
|
||||
bool bOkToStart = true;
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ConnectionSlot *connectionSlot= slots[i];
|
||||
if(connectionSlot != NULL &&
|
||||
(connectionSlot->getAllowDownloadDataSynch() == true || connectionSlot->getAllowGameDataSynchCheck() == true) &&
|
||||
@@ -1659,8 +1550,7 @@ bool ServerInterface::launchGame(const GameSettings *gameSettings) {
|
||||
if(useInGameBlockingClientSockets == true) {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
for(int i= 0; i < GameConstants::maxPlayers; ++i) {
|
||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ConnectionSlot *connectionSlot= slots[i];
|
||||
if(connectionSlot != NULL && connectionSlot->isConnected()) {
|
||||
connectionSlot->getSocket()->setBlock(true);
|
||||
@@ -1738,11 +1628,10 @@ void ServerInterface::broadcastMessage(const NetworkMessage *networkMessage, int
|
||||
}
|
||||
|
||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||
//MutexSafeWrapper safeMutexSlot(NULL,CODE_AT_LINE_X(i));
|
||||
ReadWriteMutexSafeWrapper safeRWL(NULL,true,CODE_AT_LINE_X(i));
|
||||
MutexSafeWrapper safeMutexSlot(NULL,CODE_AT_LINE_X(i));
|
||||
if(i != lockedSlotIndex) {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] i = %d, lockedSlotIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,i,lockedSlotIndex);
|
||||
safeRWL.setReadWriteMutex(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
||||
safeMutexSlot.setMutex(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
}
|
||||
|
||||
ConnectionSlot* connectionSlot= slots[i];
|
||||
@@ -1790,8 +1679,7 @@ void ServerInterface::broadcastMessageToConnectedClients(const NetworkMessage *n
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
try {
|
||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ConnectionSlot *connectionSlot= slots[i];
|
||||
|
||||
if(i != excludeSlot && connectionSlot != NULL) {
|
||||
@@ -1816,7 +1704,6 @@ void ServerInterface::updateListen() {
|
||||
int openSlotCount = 0;
|
||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],intToStr(__LINE__) + "_" + intToStr(i));
|
||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
||||
bool isSlotOpen = (slots[i] != NULL && slots[i]->isConnected() == false);
|
||||
|
||||
if(isSlotOpen == true) {
|
||||
@@ -1830,7 +1717,6 @@ int ServerInterface::getOpenSlotCount() {
|
||||
int openSlotCount = 0;
|
||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],intToStr(__LINE__) + "_" + intToStr(i));
|
||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
||||
bool isSlotOpen = (slots[i] != NULL && slots[i]->isConnected() == false);
|
||||
|
||||
if(isSlotOpen == true) {
|
||||
@@ -1890,8 +1776,7 @@ void ServerInterface::setGameSettings(GameSettings *serverGameSettings, bool wai
|
||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||
//printf("===> START slot %d - About to setGameSettings #1\n",i);
|
||||
|
||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ConnectionSlot *connectionSlot = slots[i];
|
||||
if(connectionSlot != NULL && connectionSlot->isConnected()) {
|
||||
if(connectionSlot->getReceivedNetworkGameStatus() == false) {
|
||||
@@ -1907,8 +1792,7 @@ void ServerInterface::setGameSettings(GameSettings *serverGameSettings, bool wai
|
||||
}
|
||||
|
||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ConnectionSlot *connectionSlot = slots[i];
|
||||
if(connectionSlot != NULL && connectionSlot->isConnected()) {
|
||||
connectionSlot->setReceivedNetworkGameStatus(false);
|
||||
@@ -1928,8 +1812,7 @@ void ServerInterface::setGameSettings(GameSettings *serverGameSettings, bool wai
|
||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||
//printf("===> START slot %d - About to setGameSettings 2\n",i);
|
||||
|
||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ConnectionSlot *connectionSlot = slots[i];
|
||||
if(connectionSlot != NULL && connectionSlot->isConnected()) {
|
||||
if(connectionSlot->getReceivedNetworkGameStatus() == false) {
|
||||
@@ -1980,8 +1863,7 @@ std::map<string,string> ServerInterface::publishToMasterserver() {
|
||||
std::map < string, string > publishToServerInfo;
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||
if(slots[i] != NULL) {
|
||||
slotCountUsed++;
|
||||
slotCountHumans++;
|
||||
|
@@ -48,8 +48,7 @@ public:
|
||||
|
||||
private:
|
||||
ConnectionSlot* slots[GameConstants::maxPlayers];
|
||||
//Mutex slotAccessorMutexes[GameConstants::maxPlayers];
|
||||
ReadWriteMutex slotAccessorMutexes[GameConstants::maxPlayers];
|
||||
Mutex slotAccessorMutexes[GameConstants::maxPlayers];
|
||||
|
||||
ServerSocket serverSocket;
|
||||
bool gameHasBeenInitiated;
|
||||
@@ -210,9 +209,6 @@ protected:
|
||||
void checkForLaggingClients(std::map<int,bool> &mapSlotSignalledList, std::map<int,ConnectionSlotEvent> &eventList, std::map<PLATFORM_SOCKET,bool> &socketTriggeredList,std::vector <string> &errorMsgList);
|
||||
void executeNetworkCommandsFromClients();
|
||||
void dispatchPendingChatMessages(std::vector <string> &errorMsgList);
|
||||
|
||||
void waitForSignalledClients(std::map<int,bool> &mapSlotSignalledList,std::vector <string> &errorMsgList);
|
||||
void checkForLaggingClients(std::vector <string> &errorMsgList);
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
@@ -333,10 +333,6 @@ void FactionThread::execute() {
|
||||
safeMutex.ReleaseLock();
|
||||
|
||||
setTaskCompleted(frameIndex.first);
|
||||
this->faction->signalWorkerTaskCompleted();
|
||||
}
|
||||
else {
|
||||
this->faction->signalWorkerTaskCompleted();
|
||||
}
|
||||
|
||||
if(getQuitStatus() == true) {
|
||||
@@ -349,7 +345,6 @@ void FactionThread::execute() {
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] ****************** ENDING worker thread this = %p\n",__FILE__,__FUNCTION__,__LINE__,this);
|
||||
}
|
||||
catch(const exception &ex) {
|
||||
this->faction->signalWorkerTaskCompleted();
|
||||
//setRunningStatus(false);
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
||||
@@ -357,7 +352,6 @@ void FactionThread::execute() {
|
||||
|
||||
throw runtime_error(ex.what());
|
||||
}
|
||||
this->faction->signalWorkerTaskCompleted();
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
}
|
||||
|
||||
@@ -418,15 +412,6 @@ Faction::~Faction() {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
}
|
||||
|
||||
void Faction::signalWorkerTaskCompleted() {
|
||||
semWorkerTaskCompleted.signal();
|
||||
}
|
||||
|
||||
bool Faction::waitWorkerTaskCompleted(int waitMilliseconds) {
|
||||
int result = semWorkerTaskCompleted.waitTillSignalled(waitMilliseconds);
|
||||
return (result == 0);
|
||||
}
|
||||
|
||||
void Faction::end() {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
|
@@ -137,15 +137,10 @@ private:
|
||||
set<int> livingUnits;
|
||||
set<Unit*> livingUnitsp;
|
||||
|
||||
Semaphore semWorkerTaskCompleted;
|
||||
|
||||
public:
|
||||
Faction();
|
||||
~Faction();
|
||||
|
||||
void signalWorkerTaskCompleted();
|
||||
bool waitWorkerTaskCompleted(int waitMilliseconds=-1);
|
||||
|
||||
void addLivingUnits(int id) { livingUnits.insert(id); }
|
||||
void addLivingUnitsp(Unit *unit) { livingUnitsp.insert(unit); }
|
||||
|
||||
|
@@ -372,40 +372,30 @@ void World::updateAllFactionUnits() {
|
||||
faction->signalWorkerThread(frameCount);
|
||||
}
|
||||
|
||||
bool workThreadsFinished = false;
|
||||
Chrono chrono;
|
||||
chrono.start();
|
||||
|
||||
const int MAX_FACTION_THREAD_WAIT_MILLISECONDS = 20000;
|
||||
// bool workThreadsFinished = false;
|
||||
// for(;chrono.getMillis() < MAX_FACTION_THREAD_WAIT_MILLISECONDS;) {
|
||||
// workThreadsFinished = true;
|
||||
// for(int i = 0; i < factionCount; ++i) {
|
||||
// Faction *faction = getFaction(i);
|
||||
// if(faction == NULL) {
|
||||
// throw runtime_error("faction == NULL");
|
||||
// }
|
||||
// if(faction->isWorkerThreadSignalCompleted(frameCount) == false) {
|
||||
// workThreadsFinished = false;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// if(workThreadsFinished == false) {
|
||||
// //sleep(0);
|
||||
// }
|
||||
// else {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
// Wait for faction threads to finish
|
||||
for(int i = 0; i < factionCount; ++i) {
|
||||
Faction *faction = getFaction(i);
|
||||
if(faction == NULL) {
|
||||
throw runtime_error("faction == NULL");
|
||||
for(;chrono.getMillis() < MAX_FACTION_THREAD_WAIT_MILLISECONDS;) {
|
||||
workThreadsFinished = true;
|
||||
for(int i = 0; i < factionCount; ++i) {
|
||||
Faction *faction = getFaction(i);
|
||||
if(faction == NULL) {
|
||||
throw runtime_error("faction == NULL");
|
||||
}
|
||||
if(faction->isWorkerThreadSignalCompleted(frameCount) == false) {
|
||||
workThreadsFinished = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(workThreadsFinished == false) {
|
||||
//sleep(0);
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
faction->waitWorkerTaskCompleted(MAX_FACTION_THREAD_WAIT_MILLISECONDS);
|
||||
}
|
||||
//
|
||||
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED && chrono.getMillis() >= 10) printf("In [%s::%s Line: %d] *** Faction thread preprocessing took [%lld] msecs for %d factions for frameCount = %d.\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis(),factionCount,frameCount);
|
||||
|
||||
|
@@ -118,12 +118,11 @@ protected:
|
||||
time_t lastThreadedPing;
|
||||
//Mutex pingThreadAccessor;
|
||||
|
||||
//Mutex dataSynchAccessorRead;
|
||||
//Mutex dataSynchAccessorWrite;
|
||||
ReadWriteMutex dataSynchAccessorRWLMutex;
|
||||
Mutex dataSynchAccessorRead;
|
||||
Mutex dataSynchAccessorWrite;
|
||||
|
||||
ReadWriteMutex inSocketDestructorSynchAccessor;
|
||||
//bool inSocketDestructor;
|
||||
Mutex inSocketDestructorSynchAccessor;
|
||||
bool inSocketDestructor;
|
||||
|
||||
public:
|
||||
Socket(PLATFORM_SOCKET sock);
|
||||
|
@@ -785,25 +785,26 @@ bool Socket::isSocketValid(const PLATFORM_SOCKET *validateSocket) {
|
||||
}
|
||||
|
||||
Socket::Socket(PLATFORM_SOCKET sock) {
|
||||
ReadWriteMutexSafeWrapper safeMutexSocketDestructorFlag(&inSocketDestructorSynchAccessor,true,CODE_AT_LINE);
|
||||
MutexSafeWrapper safeMutexSocketDestructorFlag(&inSocketDestructorSynchAccessor,CODE_AT_LINE);
|
||||
inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
|
||||
//this->inSocketDestructor = false;
|
||||
this->inSocketDestructor = false;
|
||||
//safeMutexSocketDestructorFlag.ReleaseLock();
|
||||
|
||||
//this->pingThread = NULL;
|
||||
//pingThreadAccessor.setOwnerId(CODE_AT_LINE);
|
||||
//dataSynchAccessorRead.setOwnerId(CODE_AT_LINE);
|
||||
//dataSynchAccessorWrite.setOwnerId(CODE_AT_LINE);
|
||||
dataSynchAccessorRWLMutex.setOwnerId(CODE_AT_LINE);
|
||||
dataSynchAccessorRead.setOwnerId(CODE_AT_LINE);
|
||||
dataSynchAccessorWrite.setOwnerId(CODE_AT_LINE);
|
||||
|
||||
|
||||
|
||||
this->sock= sock;
|
||||
this->connectedIpAddress = "";
|
||||
}
|
||||
|
||||
Socket::Socket() {
|
||||
ReadWriteMutexSafeWrapper safeMutexSocketDestructorFlag(&inSocketDestructorSynchAccessor,true,CODE_AT_LINE);
|
||||
MutexSafeWrapper safeMutexSocketDestructorFlag(&inSocketDestructorSynchAccessor,CODE_AT_LINE);
|
||||
inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
|
||||
//this->inSocketDestructor = false;
|
||||
this->inSocketDestructor = false;
|
||||
//safeMutexSocketDestructorFlag.ReleaseLock();
|
||||
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
@@ -905,13 +906,13 @@ void Socket::simpleTask(BaseThread *callingThread) {
|
||||
*/
|
||||
|
||||
Socket::~Socket() {
|
||||
ReadWriteMutexSafeWrapper safeMutexSocketDestructorFlag(&inSocketDestructorSynchAccessor,false,CODE_AT_LINE);
|
||||
//if(this->inSocketDestructor == true) {
|
||||
// SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] this->inSocketDestructor == true\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
// return;
|
||||
//}
|
||||
MutexSafeWrapper safeMutexSocketDestructorFlag(&inSocketDestructorSynchAccessor,CODE_AT_LINE);
|
||||
if(this->inSocketDestructor == true) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] this->inSocketDestructor == true\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
return;
|
||||
}
|
||||
inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
|
||||
//this->inSocketDestructor = true;
|
||||
this->inSocketDestructor = true;
|
||||
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] START closing socket = %d...\n",__FILE__,__FUNCTION__,sock);
|
||||
|
||||
@@ -920,12 +921,12 @@ Socket::~Socket() {
|
||||
disconnectSocket();
|
||||
|
||||
// Allow other callers with a lock on the mutexes to let them go
|
||||
//for(time_t elapsed = time(NULL);
|
||||
// (dataSynchAccessorRead.getRefCount() > 0 ||
|
||||
// dataSynchAccessorWrite.getRefCount() > 0) &&
|
||||
// difftime(time(NULL),elapsed) <= 5;) {
|
||||
for(time_t elapsed = time(NULL);
|
||||
(dataSynchAccessorRead.getRefCount() > 0 ||
|
||||
dataSynchAccessorWrite.getRefCount() > 0) &&
|
||||
difftime(time(NULL),elapsed) <= 5;) {
|
||||
//sleep(0);
|
||||
//}
|
||||
}
|
||||
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END closing socket = %d...\n",__FILE__,__FUNCTION__,sock);
|
||||
|
||||
@@ -940,9 +941,8 @@ void Socket::disconnectSocket() {
|
||||
if(isSocketValid() == true) {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] calling shutdown and close for socket = %d...\n",__FILE__,__FUNCTION__,sock);
|
||||
|
||||
//MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
|
||||
//MutexSafeWrapper safeMutex1(&dataSynchAccessorWrite,CODE_AT_LINE);
|
||||
ReadWriteMutexSafeWrapper safeMutex(&dataSynchAccessorRWLMutex,false,CODE_AT_LINE);
|
||||
MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
|
||||
MutexSafeWrapper safeMutex1(&dataSynchAccessorWrite,CODE_AT_LINE);
|
||||
::shutdown(sock,2);
|
||||
#ifndef WIN32
|
||||
::close(sock);
|
||||
@@ -951,8 +951,8 @@ void Socket::disconnectSocket() {
|
||||
::closesocket(sock);
|
||||
sock = -1;
|
||||
#endif
|
||||
//safeMutex.ReleaseLock();
|
||||
//safeMutex1.ReleaseLock();
|
||||
safeMutex.ReleaseLock();
|
||||
safeMutex1.ReleaseLock();
|
||||
}
|
||||
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END closing socket = %d...\n",__FILE__,__FUNCTION__,sock);
|
||||
@@ -1183,8 +1183,7 @@ int Socket::send(const void *data, int dataSize) {
|
||||
// inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
|
||||
// safeMutexSocketDestructorFlag.ReleaseLock();
|
||||
|
||||
//MutexSafeWrapper safeMutex(&dataSynchAccessorWrite,CODE_AT_LINE);
|
||||
ReadWriteMutexSafeWrapper safeMutex(&dataSynchAccessorRWLMutex,false,CODE_AT_LINE);
|
||||
MutexSafeWrapper safeMutex(&dataSynchAccessorWrite,CODE_AT_LINE);
|
||||
|
||||
#ifdef __APPLE__
|
||||
bytesSent = ::send(sock, (const char *)data, dataSize, SO_NOSIGPIPE);
|
||||
@@ -1222,8 +1221,7 @@ int Socket::send(const void *data, int dataSize) {
|
||||
// inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
|
||||
// safeMutexSocketDestructorFlag.ReleaseLock();
|
||||
|
||||
//MutexSafeWrapper safeMutex(&dataSynchAccessorWrite,CODE_AT_LINE);
|
||||
ReadWriteMutexSafeWrapper safeMutex(&dataSynchAccessorRWLMutex,false,CODE_AT_LINE);
|
||||
MutexSafeWrapper safeMutex(&dataSynchAccessorWrite,CODE_AT_LINE);
|
||||
#ifdef __APPLE__
|
||||
bytesSent = ::send(sock, (const char *)data, dataSize, SO_NOSIGPIPE);
|
||||
#else
|
||||
@@ -1272,8 +1270,7 @@ int Socket::send(const void *data, int dataSize) {
|
||||
// inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
|
||||
// safeMutexSocketDestructorFlag.ReleaseLock();
|
||||
|
||||
//MutexSafeWrapper safeMutex(&dataSynchAccessorWrite,CODE_AT_LINE);
|
||||
ReadWriteMutexSafeWrapper safeMutex(&dataSynchAccessorRWLMutex,false,CODE_AT_LINE);
|
||||
MutexSafeWrapper safeMutex(&dataSynchAccessorWrite,CODE_AT_LINE);
|
||||
const char *sendBuf = (const char *)data;
|
||||
#ifdef __APPLE__
|
||||
bytesSent = ::send(sock, &sendBuf[totalBytesSent], dataSize - totalBytesSent, SO_NOSIGPIPE);
|
||||
@@ -1338,8 +1335,7 @@ int Socket::receive(void *data, int dataSize, bool tryReceiveUntilDataSizeMet) {
|
||||
// inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
|
||||
// safeMutexSocketDestructorFlag.ReleaseLock();
|
||||
|
||||
//MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
|
||||
ReadWriteMutexSafeWrapper safeMutex(&dataSynchAccessorRWLMutex,true,CODE_AT_LINE);
|
||||
MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
|
||||
bytesReceived = recv(sock, reinterpret_cast<char*>(data), dataSize, 0);
|
||||
safeMutex.ReleaseLock();
|
||||
}
|
||||
@@ -1368,8 +1364,7 @@ int Socket::receive(void *data, int dataSize, bool tryReceiveUntilDataSizeMet) {
|
||||
// inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
|
||||
// safeMutexSocketDestructorFlag.ReleaseLock();
|
||||
|
||||
//MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
|
||||
ReadWriteMutexSafeWrapper safeMutex(&dataSynchAccessorRWLMutex,true,CODE_AT_LINE);
|
||||
MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
|
||||
bytesReceived = recv(sock, reinterpret_cast<char*>(data), dataSize, 0);
|
||||
safeMutex.ReleaseLock();
|
||||
|
||||
@@ -1428,8 +1423,7 @@ int Socket::peek(void *data, int dataSize,bool mustGetData) {
|
||||
// safeMutexSocketDestructorFlag.ReleaseLock();
|
||||
|
||||
//MutexSafeWrapper safeMutex(&dataSynchAccessor,CODE_AT_LINE + "_" + intToStr(sock) + "_" + intToStr(dataSize));
|
||||
//MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
|
||||
ReadWriteMutexSafeWrapper safeMutex(&dataSynchAccessorRWLMutex,true,CODE_AT_LINE);
|
||||
MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
|
||||
|
||||
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||
|
||||
@@ -1468,8 +1462,7 @@ int Socket::peek(void *data, int dataSize,bool mustGetData) {
|
||||
// safeMutexSocketDestructorFlag.ReleaseLock();
|
||||
|
||||
//MutexSafeWrapper safeMutex(&dataSynchAccessor,CODE_AT_LINE + "_" + intToStr(sock) + "_" + intToStr(dataSize));
|
||||
//MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
|
||||
ReadWriteMutexSafeWrapper safeMutex(&dataSynchAccessorRWLMutex,true,CODE_AT_LINE);
|
||||
MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
|
||||
err = recv(sock, reinterpret_cast<char*>(data), dataSize, MSG_PEEK);
|
||||
safeMutex.ReleaseLock();
|
||||
|
||||
@@ -1764,8 +1757,7 @@ void ClientSocket::connect(const Ip &ip, int port)
|
||||
FD_SET(sock, &myset);
|
||||
|
||||
{
|
||||
//MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
|
||||
ReadWriteMutexSafeWrapper safeMutex(&dataSynchAccessorRWLMutex,true,CODE_AT_LINE);
|
||||
MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
|
||||
err = select((int)sock + 1, NULL, &myset, NULL, &tv);
|
||||
//safeMutex.ReleaseLock();
|
||||
}
|
||||
@@ -2181,8 +2173,7 @@ Socket *ServerSocket::accept() {
|
||||
struct sockaddr_in cli_addr;
|
||||
socklen_t clilen = sizeof(cli_addr);
|
||||
char client_host[100]="";
|
||||
//MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
|
||||
ReadWriteMutexSafeWrapper safeMutex(&dataSynchAccessorRWLMutex,true,CODE_AT_LINE);
|
||||
MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
|
||||
PLATFORM_SOCKET newSock= ::accept(sock, (struct sockaddr *) &cli_addr, &clilen);
|
||||
safeMutex.ReleaseLock();
|
||||
|
||||
|
Reference in New Issue
Block a user