mirror of
https://github.com/glest/glest-source.git
synced 2025-08-14 04:13: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
|
//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
|
// This triggers LAG update packets to begin as required
|
||||||
lastNetworkCommandListSendTime = time(NULL);
|
lastNetworkCommandListSendTime = time(NULL);
|
||||||
|
@@ -32,18 +32,16 @@ namespace Glest{ namespace Game{
|
|||||||
// class ConnectionSlotThread
|
// class ConnectionSlotThread
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
ConnectionSlotThread::ConnectionSlotThread(ConnectionSlot *slot) : BaseThread() {
|
ConnectionSlotThread::ConnectionSlotThread(int slotIndex) : BaseThread() {
|
||||||
this->slot = slot;
|
this->slotIndex = slotIndex;
|
||||||
this->slotIndex = slot->getPlayerIndex();
|
|
||||||
this->slotInterface = NULL;
|
this->slotInterface = NULL;
|
||||||
//this->event = NULL;
|
//this->event = NULL;
|
||||||
eventList.clear();
|
eventList.clear();
|
||||||
eventList.reserve(100);
|
eventList.reserve(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConnectionSlotThread::ConnectionSlotThread(ConnectionSlotCallbackInterface *slotInterface,ConnectionSlot *slot) : BaseThread() {
|
ConnectionSlotThread::ConnectionSlotThread(ConnectionSlotCallbackInterface *slotInterface,int slotIndex) : BaseThread() {
|
||||||
this->slot = slot;
|
this->slotIndex = slotIndex;
|
||||||
this->slotIndex = slot->getPlayerIndex();
|
|
||||||
this->slotInterface = slotInterface;
|
this->slotInterface = slotInterface;
|
||||||
//this->event = NULL;
|
//this->event = NULL;
|
||||||
eventList.clear();
|
eventList.clear();
|
||||||
@@ -205,12 +203,10 @@ void ConnectionSlotThread::execute() {
|
|||||||
//this->slotInterface->slotUpdateTask(&eventCopy);
|
//this->slotInterface->slotUpdateTask(&eventCopy);
|
||||||
this->slotUpdateTask(&eventCopy);
|
this->slotUpdateTask(&eventCopy);
|
||||||
setTaskCompleted(eventCopy.eventId);
|
setTaskCompleted(eventCopy.eventId);
|
||||||
this->slot->signalSlotWorkerTaskCompleted();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
safeMutex.ReleaseLock();
|
safeMutex.ReleaseLock();
|
||||||
this->slot->signalSlotWorkerTaskCompleted();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(getQuitStatus() == true) {
|
if(getQuitStatus() == true) {
|
||||||
@@ -223,14 +219,12 @@ void ConnectionSlotThread::execute() {
|
|||||||
}
|
}
|
||||||
catch(const exception &ex) {
|
catch(const exception &ex) {
|
||||||
//setRunningStatus(false);
|
//setRunningStatus(false);
|
||||||
this->slot->signalSlotWorkerTaskCompleted();
|
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
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__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
throw runtime_error(ex.what());
|
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__);
|
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->setSocket(NULL);
|
||||||
this->slotThreadWorker = NULL;
|
this->slotThreadWorker = NULL;
|
||||||
this->slotThreadWorker = new ConnectionSlotThread(this->serverInterface,this);
|
this->slotThreadWorker = new ConnectionSlotThread(this->serverInterface,playerIndex);
|
||||||
this->slotThreadWorker->setUniqueID(__FILE__);
|
this->slotThreadWorker->setUniqueID(__FILE__);
|
||||||
this->slotThreadWorker->start();
|
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__);
|
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) {
|
void ConnectionSlot::updateSlot(ConnectionSlotEvent *event) {
|
||||||
Chrono chrono;
|
Chrono chrono;
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chrono.start();
|
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());
|
//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;
|
bool gotTextMsg = true;
|
||||||
//for(;this->hasDataToRead() == true && gotTextMsg == true;) {
|
for(;this->hasDataToRead() == true && gotTextMsg == true;) {
|
||||||
for(;this->hasDataToRead() == true;) {
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] polling for networkMessageType...\n",__FILE__,__FUNCTION__,__LINE__);
|
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);
|
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
|
//process incoming commands
|
||||||
switch(networkMessageType) {
|
switch(networkMessageType) {
|
||||||
|
|
||||||
@@ -529,7 +513,7 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) {
|
|||||||
if(receiveMessage(&networkMessageText)) {
|
if(receiveMessage(&networkMessageText)) {
|
||||||
ChatMsgInfo msg(networkMessageText.getText().c_str(),networkMessageText.getTeamIndex(),networkMessageText.getPlayerIndex(),networkMessageText.getTargetLanguage());
|
ChatMsgInfo msg(networkMessageText.getText().c_str(),networkMessageText.getTeamIndex(),networkMessageText.getPlayerIndex(),networkMessageText.getTargetLanguage());
|
||||||
this->addChatInfo(msg);
|
this->addChatInfo(msg);
|
||||||
//gotTextMsg = true;
|
gotTextMsg = true;
|
||||||
}
|
}
|
||||||
else {
|
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());
|
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);
|
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(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);
|
||||||
MutexSafeWrapper safeMutexSlot(&mutexPendingNetworkCommandList,CODE_AT_LINE);
|
for(int i = 0; i < networkMessageCommandList.getCommandCount(); ++i) {
|
||||||
for(int i = 0; i < networkMessageCommandList.getCommandCount(); ++i) {
|
vctPendingNetworkCommandList.push_back(*networkMessageCommandList.getCommand(i));
|
||||||
vctPendingNetworkCommandList.push_back(*networkMessageCommandList.getCommand(i));
|
|
||||||
}
|
|
||||||
safeMutexSlot.ReleaseLock();
|
|
||||||
}
|
}
|
||||||
|
safeMutexSlot.ReleaseLock();
|
||||||
}
|
}
|
||||||
else {
|
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());
|
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) {
|
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
|
// Skip text messages not intended for the players preferred language
|
||||||
const NetworkMessageText *textMsg = dynamic_cast<const NetworkMessageText *>(networkMessage);
|
const NetworkMessageText *textMsg = dynamic_cast<const NetworkMessageText *>(networkMessage);
|
||||||
@@ -1126,90 +1108,72 @@ void ConnectionSlot::clearPendingNetworkCommandList() {
|
|||||||
safeMutexSlot.ReleaseLock();
|
safeMutexSlot.ReleaseLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
//bool ConnectionSlot::hasValidSocketId() {
|
bool ConnectionSlot::hasValidSocketId() {
|
||||||
// //bool result = (this->getSocket() != NULL && this->getSocket()->getSocketId() > 0);
|
//bool result = (this->getSocket() != NULL && this->getSocket()->getSocketId() > 0);
|
||||||
// //return result;
|
//return result;
|
||||||
// bool result = false;
|
bool result = false;
|
||||||
// MutexSafeWrapper safeMutexSlot(&mutexSocket,CODE_AT_LINE);
|
MutexSafeWrapper safeMutexSlot(&mutexSocket,CODE_AT_LINE);
|
||||||
// if(socket != NULL && socket->getSocketId() > 0) {
|
if(socket != NULL && socket->getSocketId() > 0) {
|
||||||
// result = true;
|
result = true;
|
||||||
// }
|
}
|
||||||
// return result;
|
return result;
|
||||||
//
|
|
||||||
//}
|
}
|
||||||
|
|
||||||
bool ConnectionSlot::isConnected() {
|
bool ConnectionSlot::isConnected() {
|
||||||
bool result = false;
|
bool result = false;
|
||||||
//MutexSafeWrapper safeMutexSlot(&mutexSocket,CODE_AT_LINE);
|
MutexSafeWrapper safeMutexSlot(&mutexSocket,CODE_AT_LINE);
|
||||||
ReadWriteMutexSafeWrapper safeRWL(&socketRWLMutex,true,CODE_AT_LINE);
|
|
||||||
if(socket != NULL && socket->isConnected() == true) {
|
if(socket != NULL && socket->isConnected() == true) {
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
//socketRWLMutex.unlockRead();
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
PLATFORM_SOCKET ConnectionSlot::getSocketId() {
|
PLATFORM_SOCKET ConnectionSlot::getSocketId() {
|
||||||
PLATFORM_SOCKET result = 0;
|
PLATFORM_SOCKET result = 0;
|
||||||
//MutexSafeWrapper safeMutexSlot(&mutexSocket,CODE_AT_LINE);
|
MutexSafeWrapper safeMutexSlot(&mutexSocket,CODE_AT_LINE);
|
||||||
ReadWriteMutexSafeWrapper safeRWL(&socketRWLMutex,true,CODE_AT_LINE);
|
|
||||||
if(socket != NULL) {
|
if(socket != NULL) {
|
||||||
result = socket->getSocketId();
|
result = socket->getSocketId();
|
||||||
}
|
}
|
||||||
//socketRWLMutex.unlockRead();
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
pair<bool,Socket*> ConnectionSlot::getSocketInfo() {
|
pair<bool,Socket*> ConnectionSlot::getSocketInfo() {
|
||||||
pair<bool,Socket*> result;
|
pair<bool,Socket*> result;
|
||||||
//MutexSafeWrapper safeMutexSlot(&mutexSocket,CODE_AT_LINE);
|
MutexSafeWrapper safeMutexSlot(&mutexSocket,CODE_AT_LINE);
|
||||||
ReadWriteMutexSafeWrapper safeRWL(&socketRWLMutex,true,CODE_AT_LINE);
|
|
||||||
result.first = (socket != NULL && socket->isConnected());
|
result.first = (socket != NULL && socket->isConnected());
|
||||||
result.second = socket;
|
result.second = socket;
|
||||||
//socketRWLMutex.unlockRead();
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Socket* ConnectionSlot::getSocket(bool mutexLock) {
|
Socket* ConnectionSlot::getSocket(bool mutexLock) {
|
||||||
Socket *result = NULL;
|
MutexSafeWrapper safeMutexSlot(NULL,CODE_AT_LINE);
|
||||||
//MutexSafeWrapper safeMutexSlot(NULL,CODE_AT_LINE);
|
|
||||||
ReadWriteMutexSafeWrapper safeRWL(&socketRWLMutex,true,CODE_AT_LINE);
|
|
||||||
if(mutexLock == true) {
|
if(mutexLock == true) {
|
||||||
//safeMutexSlot.setMutex(&mutexSocket,CODE_AT_LINE);
|
safeMutexSlot.setMutex(&mutexSocket,CODE_AT_LINE);
|
||||||
}
|
}
|
||||||
result = socket;
|
return socket;
|
||||||
//socketRWLMutex.unlockRead();
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionSlot::setSocket(Socket *newSocket) {
|
void ConnectionSlot::setSocket(Socket *newSocket) {
|
||||||
//MutexSafeWrapper safeMutexSlot(&mutexSocket,CODE_AT_LINE);
|
MutexSafeWrapper safeMutexSlot(&mutexSocket,CODE_AT_LINE);
|
||||||
ReadWriteMutexSafeWrapper safeRWL(&socketRWLMutex,false,CODE_AT_LINE);
|
|
||||||
socket = newSocket;
|
socket = newSocket;
|
||||||
//socketRWLMutex.unlockWrite();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionSlot::deleteSocket() {
|
void ConnectionSlot::deleteSocket() {
|
||||||
//MutexSafeWrapper safeMutexSlot(&mutexSocket,CODE_AT_LINE);
|
MutexSafeWrapper safeMutexSlot(&mutexSocket,CODE_AT_LINE);
|
||||||
ReadWriteMutexSafeWrapper safeRWL(&socketRWLMutex,false,CODE_AT_LINE);
|
|
||||||
delete socket;
|
delete socket;
|
||||||
socket = NULL;
|
socket = NULL;
|
||||||
//socketRWLMutex.unlockWrite();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConnectionSlot::hasDataToRead() {
|
bool ConnectionSlot::hasDataToRead() {
|
||||||
bool result = false;
|
bool result = false;
|
||||||
//MutexSafeWrapper safeMutexSlot(&mutexSocket,CODE_AT_LINE);
|
MutexSafeWrapper safeMutexSlot(&mutexSocket,CODE_AT_LINE);
|
||||||
ReadWriteMutexSafeWrapper safeRWL(&socketRWLMutex,true,CODE_AT_LINE);
|
|
||||||
|
|
||||||
if(socket != NULL && socket->hasDataToRead() == true) {
|
if(socket != NULL && socket->hasDataToRead() == true) {
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
//socketRWLMutex.unlockRead();
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -78,7 +78,6 @@ protected:
|
|||||||
Mutex triggerIdMutex;
|
Mutex triggerIdMutex;
|
||||||
vector<ConnectionSlotEvent> eventList;
|
vector<ConnectionSlotEvent> eventList;
|
||||||
int slotIndex;
|
int slotIndex;
|
||||||
ConnectionSlot *slot;
|
|
||||||
|
|
||||||
virtual void setQuitStatus(bool value);
|
virtual void setQuitStatus(bool value);
|
||||||
virtual void setTaskCompleted(int eventId);
|
virtual void setTaskCompleted(int eventId);
|
||||||
@@ -87,8 +86,8 @@ protected:
|
|||||||
void slotUpdateTask(ConnectionSlotEvent *event);
|
void slotUpdateTask(ConnectionSlotEvent *event);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ConnectionSlotThread(ConnectionSlot *slot);
|
ConnectionSlotThread(int slotIndex);
|
||||||
ConnectionSlotThread(ConnectionSlotCallbackInterface *slotInterface,ConnectionSlot *slot);
|
ConnectionSlotThread(ConnectionSlotCallbackInterface *slotInterface,int slotIndex);
|
||||||
virtual void execute();
|
virtual void execute();
|
||||||
void signalUpdate(ConnectionSlotEvent *event);
|
void signalUpdate(ConnectionSlotEvent *event);
|
||||||
bool isSignalCompleted(ConnectionSlotEvent *event);
|
bool isSignalCompleted(ConnectionSlotEvent *event);
|
||||||
@@ -107,12 +106,8 @@ class ConnectionSlot: public NetworkInterface {
|
|||||||
private:
|
private:
|
||||||
ServerInterface* serverInterface;
|
ServerInterface* serverInterface;
|
||||||
|
|
||||||
Semaphore semSlotWorkerTaskCompleted;
|
Mutex mutexSocket;
|
||||||
|
|
||||||
//Mutex mutexSocket;
|
|
||||||
ReadWriteMutex socketRWLMutex;
|
|
||||||
Socket* socket;
|
Socket* socket;
|
||||||
|
|
||||||
int playerIndex;
|
int playerIndex;
|
||||||
string name;
|
string name;
|
||||||
bool ready;
|
bool ready;
|
||||||
@@ -140,9 +135,6 @@ public:
|
|||||||
ConnectionSlot(ServerInterface* serverInterface, int playerIndex);
|
ConnectionSlot(ServerInterface* serverInterface, int playerIndex);
|
||||||
~ConnectionSlot();
|
~ConnectionSlot();
|
||||||
|
|
||||||
void signalSlotWorkerTaskCompleted();
|
|
||||||
bool waitSlotWorkerTaskCompleted(int waitMilliseconds=-1);
|
|
||||||
|
|
||||||
void update(bool checkForNewClients,int lockedSlotIndex);
|
void update(bool checkForNewClients,int lockedSlotIndex);
|
||||||
void setPlayerIndex(int value) { playerIndex = value; }
|
void setPlayerIndex(int value) { playerIndex = value; }
|
||||||
int getPlayerIndex() const {return playerIndex;}
|
int getPlayerIndex() const {return playerIndex;}
|
||||||
@@ -163,7 +155,7 @@ public:
|
|||||||
bool getReceivedNetworkGameStatus() const { return receivedNetworkGameStatus; }
|
bool getReceivedNetworkGameStatus() const { return receivedNetworkGameStatus; }
|
||||||
void setReceivedNetworkGameStatus(bool value) { receivedNetworkGameStatus = value; }
|
void setReceivedNetworkGameStatus(bool value) { receivedNetworkGameStatus = value; }
|
||||||
|
|
||||||
//bool hasValidSocketId();
|
bool hasValidSocketId();
|
||||||
virtual bool getConnectHasHandshaked() const { return gotIntro; }
|
virtual bool getConnectHasHandshaked() const { return gotIntro; }
|
||||||
std::vector<std::string> getThreadErrorList() const { return threadErrorList; }
|
std::vector<std::string> getThreadErrorList() const { return threadErrorList; }
|
||||||
void clearThreadErrorList() { threadErrorList.clear(); }
|
void clearThreadErrorList() { threadErrorList.clear(); }
|
||||||
|
@@ -44,33 +44,25 @@ void NetworkInterface::sendMessage(const NetworkMessage* networkMessage){
|
|||||||
networkMessage->send(socket);
|
networkMessage->send(socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkMessageType NetworkInterface::getNextMessageType(bool checkHasData)
|
NetworkMessageType NetworkInterface::getNextMessageType()
|
||||||
{
|
{
|
||||||
Socket* socket= getSocket(false);
|
Socket* socket= getSocket(false);
|
||||||
int8 messageType= nmtInvalid;
|
int8 messageType= nmtInvalid;
|
||||||
|
|
||||||
if(socket != NULL && (checkHasData == false || socket->hasDataToRead() == true)) {
|
if(socket != NULL &&
|
||||||
|
socket->hasDataToRead() == true) {
|
||||||
//peek message type
|
//peek message type
|
||||||
bool peekForMessageType = !checkHasData;
|
|
||||||
if(checkHasData == true) {
|
|
||||||
int dataSize = socket->getDataToRead();
|
int dataSize = socket->getDataToRead();
|
||||||
if(dataSize >= sizeof(messageType)) {
|
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);
|
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));
|
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));
|
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
|
//sanity check new message type
|
||||||
if(messageType < 0 || messageType >= nmtCount) {
|
if(messageType < 0 || messageType >= nmtCount) {
|
||||||
|
@@ -120,7 +120,7 @@ public:
|
|||||||
string getHostName() const {return Socket::getHostName();}
|
string getHostName() const {return Socket::getHostName();}
|
||||||
|
|
||||||
virtual void sendMessage(const NetworkMessage* networkMessage);
|
virtual void sendMessage(const NetworkMessage* networkMessage);
|
||||||
NetworkMessageType getNextMessageType(bool checkHasData=true);
|
NetworkMessageType getNextMessageType();
|
||||||
bool receiveMessage(NetworkMessage* networkMessage);
|
bool receiveMessage(NetworkMessage* networkMessage);
|
||||||
|
|
||||||
virtual bool isConnected();
|
virtual bool isConnected();
|
||||||
|
@@ -169,8 +169,7 @@ ServerInterface::~ServerInterface() {
|
|||||||
exitServer = true;
|
exitServer = true;
|
||||||
for(int i= 0; i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; i < GameConstants::maxPlayers; ++i) {
|
||||||
if(slots[i] != NULL) {
|
if(slots[i] != NULL) {
|
||||||
//MutexSafeWrapper safeMutex(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutex(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],false,CODE_AT_LINE_X(i));
|
|
||||||
delete slots[i];
|
delete slots[i];
|
||||||
slots[i]=NULL;
|
slots[i]=NULL;
|
||||||
}
|
}
|
||||||
@@ -204,8 +203,7 @@ int ServerInterface::isValidClientType(uint32 clientIp) {
|
|||||||
int result = 0;
|
int result = 0;
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
if(slots[i] != NULL) {
|
if(slots[i] != NULL) {
|
||||||
//MutexSafeWrapper safeMutex(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutex(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
|
||||||
|
|
||||||
Socket *socket = slots[i]->getSocket();
|
Socket *socket = slots[i]->getSocket();
|
||||||
if(socket != NULL) {
|
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__);
|
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));
|
||||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[playerIndex],CODE_AT_LINE_X(playerIndex));
|
|
||||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[playerIndex],false,CODE_AT_LINE_X(i));
|
|
||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
ConnectionSlot *slot = slots[playerIndex];
|
ConnectionSlot *slot = slots[playerIndex];
|
||||||
if(slot != NULL) {
|
if(slot != NULL) {
|
||||||
@@ -245,7 +240,7 @@ void ServerInterface::addSlot(int playerIndex) {
|
|||||||
}
|
}
|
||||||
slots[playerIndex] = new ConnectionSlot(this, 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__);
|
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;
|
delete slot;
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
safeMutex.ReleaseLock();
|
safeMutex.ReleaseLock();
|
||||||
@@ -264,12 +259,8 @@ bool ServerInterface::switchSlot(int fromPlayerIndex, int toPlayerIndex) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MutexSafeWrapper safeMutex(&serverSynchAccessor,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(&serverSynchAccessor,CODE_AT_LINE);
|
||||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[fromPlayerIndex],CODE_AT_LINE_X(fromPlayerIndex));
|
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));
|
||||||
|
|
||||||
//MutexSafeWrapper safeMutexSlot2(&slotAccessorMutexes[toPlayerIndex],CODE_AT_LINE_X(toPlayerIndex));
|
|
||||||
ReadWriteMutexSafeWrapper safeRWL2(&slotAccessorMutexes[toPlayerIndex],false,CODE_AT_LINE_X(i));
|
|
||||||
|
|
||||||
if(slots[toPlayerIndex] != NULL && slots[toPlayerIndex] != NULL &&
|
if(slots[toPlayerIndex] != NULL && slots[toPlayerIndex] != NULL &&
|
||||||
slots[toPlayerIndex]->isConnected() == false) {
|
slots[toPlayerIndex]->isConnected() == false) {
|
||||||
slots[fromPlayerIndex]->setPlayerIndex(toPlayerIndex);
|
slots[fromPlayerIndex]->setPlayerIndex(toPlayerIndex);
|
||||||
@@ -280,14 +271,14 @@ bool ServerInterface::switchSlot(int fromPlayerIndex, int toPlayerIndex) {
|
|||||||
safeMutex.ReleaseLock();
|
safeMutex.ReleaseLock();
|
||||||
PlayerIndexMessage playerIndexMessage(toPlayerIndex);
|
PlayerIndexMessage playerIndexMessage(toPlayerIndex);
|
||||||
slots[toPlayerIndex]->sendMessage(&playerIndexMessage);
|
slots[toPlayerIndex]->sendMessage(&playerIndexMessage);
|
||||||
safeRWL.ReleaseLock();
|
safeMutexSlot.ReleaseLock();
|
||||||
safeRWL2.ReleaseLock();
|
safeMutexSlot2.ReleaseLock();
|
||||||
result = true;
|
result = true;
|
||||||
updateListen();
|
updateListen();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
safeRWL.ReleaseLock();
|
safeMutexSlot.ReleaseLock();
|
||||||
safeRWL2.ReleaseLock();
|
safeMutexSlot2.ReleaseLock();
|
||||||
safeMutex.ReleaseLock();
|
safeMutex.ReleaseLock();
|
||||||
}
|
}
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
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();
|
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);
|
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 safeMutex(&serverSynchAccessor,CODE_AT_LINE);
|
||||||
//MutexSafeWrapper safeMutexSlot(NULL,CODE_AT_LINE_X(playerIndex));
|
MutexSafeWrapper safeMutexSlot(NULL,CODE_AT_LINE_X(playerIndex));
|
||||||
ReadWriteMutexSafeWrapper safeRWL(NULL,false,CODE_AT_LINE_X(i));
|
|
||||||
if(playerIndex != lockedSlotIndex) {
|
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);
|
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];
|
ConnectionSlot *slot = slots[playerIndex];
|
||||||
bool notifyDisconnect = false;
|
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);
|
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;
|
slots[playerIndex]= NULL;
|
||||||
safeRWL.ReleaseLock();
|
safeMutexSlot.ReleaseLock();
|
||||||
safeMutex.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);
|
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;
|
delete slot;
|
||||||
@@ -356,16 +346,14 @@ void ServerInterface::removeSlot(int playerIndex, int lockedSlotIndex) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ConnectionSlot *ServerInterface::getSlot(int playerIndex) {
|
ConnectionSlot *ServerInterface::getSlot(int playerIndex) {
|
||||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[playerIndex],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[playerIndex],CODE_AT_LINE_X(i));
|
||||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[playerIndex],true,CODE_AT_LINE_X(i));
|
|
||||||
ConnectionSlot *result = slots[playerIndex];
|
ConnectionSlot *result = slots[playerIndex];
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ServerInterface::isClientConnected(int index) {
|
bool ServerInterface::isClientConnected(int index) {
|
||||||
bool result = false;
|
bool result = false;
|
||||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[index],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[index],CODE_AT_LINE_X(i));
|
||||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[index],true,CODE_AT_LINE_X(i));
|
|
||||||
if(slots[index] != NULL && slots[index]->isConnected() == true) {
|
if(slots[index] != NULL && slots[index]->isConnected() == true) {
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
@@ -386,8 +374,7 @@ bool ServerInterface::hasClientConnection() {
|
|||||||
int ServerInterface::getConnectedSlotCount() {
|
int ServerInterface::getConnectedSlotCount() {
|
||||||
int connectedSlotCount = 0;
|
int connectedSlotCount = 0;
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
|
||||||
if(slots[i] != NULL) {
|
if(slots[i] != NULL) {
|
||||||
++connectedSlotCount;
|
++connectedSlotCount;
|
||||||
}
|
}
|
||||||
@@ -669,8 +656,7 @@ bool ServerInterface::signalClientReceiveCommands(ConnectionSlot *connectionSlot
|
|||||||
|
|
||||||
void ServerInterface::updateSocketTriggeredList(std::map<PLATFORM_SOCKET,bool> & socketTriggeredList) {
|
void ServerInterface::updateSocketTriggeredList(std::map<PLATFORM_SOCKET,bool> & socketTriggeredList) {
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
|
||||||
ConnectionSlot* connectionSlot= slots[i];
|
ConnectionSlot* connectionSlot= slots[i];
|
||||||
if(connectionSlot != NULL) {
|
if(connectionSlot != NULL) {
|
||||||
PLATFORM_SOCKET clientSocket = connectionSlot->getSocketId();
|
PLATFORM_SOCKET clientSocket = connectionSlot->getSocketId();
|
||||||
@@ -683,8 +669,7 @@ void ServerInterface::updateSocketTriggeredList(std::map<PLATFORM_SOCKET,bool> &
|
|||||||
|
|
||||||
void ServerInterface::validateConnectedClients() {
|
void ServerInterface::validateConnectedClients() {
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
|
||||||
ConnectionSlot* connectionSlot = slots[i];
|
ConnectionSlot* connectionSlot = slots[i];
|
||||||
if(connectionSlot != NULL) {
|
if(connectionSlot != NULL) {
|
||||||
connectionSlot->validateConnection();
|
connectionSlot->validateConnection();
|
||||||
@@ -697,8 +682,7 @@ void ServerInterface::signalClientsToRecieveData(std::map<PLATFORM_SOCKET,bool>
|
|||||||
std::map<int,bool> & mapSlotSignalledList) {
|
std::map<int,bool> & mapSlotSignalledList) {
|
||||||
//bool checkForNewClients = true;
|
//bool checkForNewClients = true;
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
|
||||||
ConnectionSlot* connectionSlot = slots[i];
|
ConnectionSlot* connectionSlot = slots[i];
|
||||||
|
|
||||||
bool socketTriggered = false;
|
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]);
|
//printf("===> START slot %d [%p] - About to checkForCompletedClients\n",i,slots[i]);
|
||||||
|
|
||||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
|
||||||
|
|
||||||
//printf("===> IN slot %d - About to checkForCompletedClients\n",i);
|
//printf("===> IN slot %d - About to checkForCompletedClients\n",i);
|
||||||
|
|
||||||
@@ -789,8 +772,7 @@ void ServerInterface::checkForLaggingClients(std::map<int,bool> &mapSlotSignalle
|
|||||||
threadsDone = true;
|
threadsDone = true;
|
||||||
// Examine all threads for completion of delegation
|
// Examine all threads for completion of delegation
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
|
||||||
ConnectionSlot* connectionSlot = slots[i];
|
ConnectionSlot* connectionSlot = slots[i];
|
||||||
if(connectionSlot != NULL && mapSlotSignalledList[i] == true &&
|
if(connectionSlot != NULL && mapSlotSignalledList[i] == true &&
|
||||||
slotsCompleted.find(i) == slotsCompleted.end()) {
|
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() {
|
void ServerInterface::executeNetworkCommandsFromClients() {
|
||||||
if(gameHasBeenInitiated == true) {
|
if(gameHasBeenInitiated == true) {
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
|
||||||
ConnectionSlot* connectionSlot= slots[i];
|
ConnectionSlot* connectionSlot= slots[i];
|
||||||
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
|
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
|
||||||
vector<NetworkCommand> pendingList = connectionSlot->getPendingNetworkCommandList(true);
|
vector<NetworkCommand> pendingList = connectionSlot->getPendingNetworkCommandList(true);
|
||||||
@@ -969,19 +902,18 @@ void ServerInterface::executeNetworkCommandsFromClients() {
|
|||||||
|
|
||||||
void ServerInterface::dispatchPendingChatMessages(std::vector <string> &errorMsgList) {
|
void ServerInterface::dispatchPendingChatMessages(std::vector <string> &errorMsgList) {
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
|
||||||
ConnectionSlot* connectionSlot= slots[i];
|
ConnectionSlot* connectionSlot= slots[i];
|
||||||
if(connectionSlot != NULL &&
|
if(connectionSlot != NULL &&
|
||||||
connectionSlot->getChatTextList(false).empty() == false) {
|
connectionSlot->getChatTextList(false).empty() == false) {
|
||||||
std::vector<ChatMsgInfo> chatList = connectionSlot->getChatTextList(true);
|
|
||||||
try {
|
try {
|
||||||
|
std::vector<ChatMsgInfo> chatText = connectionSlot->getChatTextList(true);
|
||||||
for(int chatIdx = 0;
|
for(int chatIdx = 0;
|
||||||
exitServer == false && slots[i] != NULL &&
|
exitServer == false && slots[i] != NULL &&
|
||||||
chatIdx < chatList.size(); chatIdx++) {
|
chatIdx < chatText.size(); chatIdx++) {
|
||||||
connectionSlot= slots[i];
|
connectionSlot= slots[i];
|
||||||
if(connectionSlot != NULL) {
|
if(connectionSlot != NULL) {
|
||||||
ChatMsgInfo msg(chatList[chatIdx]);
|
ChatMsgInfo msg(chatText[chatIdx]);
|
||||||
this->addChatInfo(msg);
|
this->addChatInfo(msg);
|
||||||
|
|
||||||
string newChatText = msg.chatText.c_str();
|
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);
|
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
|
// Its possible that the slot is disconnected here
|
||||||
// so check the original pointer again
|
// so check the original pointer again
|
||||||
//if(slots[i] != NULL) {
|
if(slots[i] != NULL) {
|
||||||
// slots[i]->clearChatInfo();
|
slots[i]->clearChatInfo();
|
||||||
//}
|
}
|
||||||
}
|
}
|
||||||
catch(const exception &ex) {
|
catch(const exception &ex) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
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() {
|
void ServerInterface::update() {
|
||||||
Chrono chrono;
|
Chrono chrono;
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled) chrono.start();
|
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());
|
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
|
// Step #2 check all connection slot worker threads for completed status
|
||||||
checkForCompletedClients(mapSlotSignalledList,errorMsgList, eventList);
|
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::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());
|
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
|
// Step #3 check clients for any lagging scenarios and try to deal with them
|
||||||
//checkForLaggingClients(mapSlotSignalledList, eventList, socketTriggeredList,errorMsgList);
|
checkForLaggingClients(mapSlotSignalledList, eventList, socketTriggeredList,errorMsgList);
|
||||||
checkForLaggingClients(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::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());
|
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");
|
//printf("\nServerInterface::update -- E1\n");
|
||||||
|
|
||||||
//std::map<int,ConnectionSlotEvent> eventList;
|
//std::map<int,ConnectionSlotEvent> eventList;
|
||||||
//std::map<int,bool> mapSlotSignalledList;
|
std::map<int,bool> mapSlotSignalledList;
|
||||||
//checkForLaggingClients(mapSlotSignalledList, eventList, socketTriggeredList,errorMsgList);
|
|
||||||
checkForLaggingClients(errorMsgList);
|
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());
|
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) {
|
difftime(time(NULL),lastGlobalLagCheckTime) >= LAG_CHECK_GRACE_PERIOD) {
|
||||||
//printf("\nServerInterface::update -- F\n");
|
//printf("\nServerInterface::update -- F\n");
|
||||||
|
|
||||||
//std::map<int,ConnectionSlotEvent> eventList;
|
std::map<int,ConnectionSlotEvent> eventList;
|
||||||
//std::map<int,bool> mapSlotSignalledList;
|
std::map<int,bool> mapSlotSignalledList;
|
||||||
//checkForLaggingClients(mapSlotSignalledList, eventList, socketTriggeredList,errorMsgList);
|
|
||||||
checkForLaggingClients(errorMsgList);
|
checkForLaggingClients(mapSlotSignalledList, eventList, socketTriggeredList,errorMsgList);
|
||||||
}
|
}
|
||||||
|
|
||||||
//printf("\nServerInterface::update -- G\n");
|
//printf("\nServerInterface::update -- G\n");
|
||||||
@@ -1335,8 +1232,7 @@ void ServerInterface::waitUntilReady(Checksum *checksum) {
|
|||||||
vector<string> waitingForHosts;
|
vector<string> waitingForHosts;
|
||||||
allReady= true;
|
allReady= true;
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
|
||||||
ConnectionSlot* connectionSlot= slots[i];
|
ConnectionSlot* connectionSlot= slots[i];
|
||||||
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
|
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
|
||||||
if(connectionSlot->isReady() == false) {
|
if(connectionSlot->isReady() == false) {
|
||||||
@@ -1415,8 +1311,7 @@ void ServerInterface::waitUntilReady(Checksum *checksum) {
|
|||||||
uint32 loadingStatus = nmls_NONE;
|
uint32 loadingStatus = nmls_NONE;
|
||||||
//send ready message after, so clients start delayed
|
//send ready message after, so clients start delayed
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
|
||||||
ConnectionSlot* connectionSlot= slots[i];
|
ConnectionSlot* connectionSlot= slots[i];
|
||||||
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
|
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
|
||||||
switch(i) {
|
switch(i) {
|
||||||
@@ -1474,8 +1369,7 @@ void ServerInterface::waitUntilReady(Checksum *checksum) {
|
|||||||
|
|
||||||
// send loading status message
|
// send loading status message
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
|
||||||
ConnectionSlot* connectionSlot= slots[i];
|
ConnectionSlot* connectionSlot= slots[i];
|
||||||
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
|
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
|
||||||
NetworkMessageLoadingStatus networkMessageLoadingStatus(loadingStatus);
|
NetworkMessageLoadingStatus networkMessageLoadingStatus(loadingStatus);
|
||||||
@@ -1511,8 +1405,7 @@ void ServerInterface::waitUntilReady(Checksum *checksum) {
|
|||||||
try {
|
try {
|
||||||
//send ready message after, so clients start delayed
|
//send ready message after, so clients start delayed
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
|
||||||
ConnectionSlot* connectionSlot= slots[i];
|
ConnectionSlot* connectionSlot= slots[i];
|
||||||
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
|
if(connectionSlot != NULL && connectionSlot->isConnected() == true) {
|
||||||
NetworkMessageReady networkMessageReady(checksum->getSum());
|
NetworkMessageReady networkMessageReady(checksum->getSum());
|
||||||
@@ -1608,8 +1501,7 @@ string ServerInterface::getNetworkStatus() {
|
|||||||
Lang &lang = Lang::getInstance();
|
Lang &lang = Lang::getInstance();
|
||||||
string str="";
|
string str="";
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
|
||||||
ConnectionSlot* connectionSlot= slots[i];
|
ConnectionSlot* connectionSlot= slots[i];
|
||||||
|
|
||||||
str+= intToStr(i)+ ": ";
|
str+= intToStr(i)+ ": ";
|
||||||
@@ -1638,8 +1530,7 @@ bool ServerInterface::launchGame(const GameSettings *gameSettings) {
|
|||||||
bool bOkToStart = true;
|
bool bOkToStart = true;
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
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) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
|
||||||
ConnectionSlot *connectionSlot= slots[i];
|
ConnectionSlot *connectionSlot= slots[i];
|
||||||
if(connectionSlot != NULL &&
|
if(connectionSlot != NULL &&
|
||||||
(connectionSlot->getAllowDownloadDataSynch() == true || connectionSlot->getAllowGameDataSynchCheck() == true) &&
|
(connectionSlot->getAllowDownloadDataSynch() == true || connectionSlot->getAllowGameDataSynchCheck() == true) &&
|
||||||
@@ -1659,8 +1550,7 @@ bool ServerInterface::launchGame(const GameSettings *gameSettings) {
|
|||||||
if(useInGameBlockingClientSockets == true) {
|
if(useInGameBlockingClientSockets == true) {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
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) {
|
for(int i= 0; i < GameConstants::maxPlayers; ++i) {
|
||||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
|
||||||
ConnectionSlot *connectionSlot= slots[i];
|
ConnectionSlot *connectionSlot= slots[i];
|
||||||
if(connectionSlot != NULL && connectionSlot->isConnected()) {
|
if(connectionSlot != NULL && connectionSlot->isConnected()) {
|
||||||
connectionSlot->getSocket()->setBlock(true);
|
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) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
//MutexSafeWrapper safeMutexSlot(NULL,CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(NULL,CODE_AT_LINE_X(i));
|
||||||
ReadWriteMutexSafeWrapper safeRWL(NULL,true,CODE_AT_LINE_X(i));
|
|
||||||
if(i != lockedSlotIndex) {
|
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);
|
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];
|
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__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
try {
|
try {
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
|
||||||
ConnectionSlot *connectionSlot= slots[i];
|
ConnectionSlot *connectionSlot= slots[i];
|
||||||
|
|
||||||
if(i != excludeSlot && connectionSlot != NULL) {
|
if(i != excludeSlot && connectionSlot != NULL) {
|
||||||
@@ -1816,7 +1704,6 @@ void ServerInterface::updateListen() {
|
|||||||
int openSlotCount = 0;
|
int openSlotCount = 0;
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],intToStr(__LINE__) + "_" + intToStr(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);
|
bool isSlotOpen = (slots[i] != NULL && slots[i]->isConnected() == false);
|
||||||
|
|
||||||
if(isSlotOpen == true) {
|
if(isSlotOpen == true) {
|
||||||
@@ -1830,7 +1717,6 @@ int ServerInterface::getOpenSlotCount() {
|
|||||||
int openSlotCount = 0;
|
int openSlotCount = 0;
|
||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],intToStr(__LINE__) + "_" + intToStr(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);
|
bool isSlotOpen = (slots[i] != NULL && slots[i]->isConnected() == false);
|
||||||
|
|
||||||
if(isSlotOpen == true) {
|
if(isSlotOpen == true) {
|
||||||
@@ -1890,8 +1776,7 @@ void ServerInterface::setGameSettings(GameSettings *serverGameSettings, bool wai
|
|||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
//printf("===> START slot %d - About to setGameSettings #1\n",i);
|
//printf("===> START slot %d - About to setGameSettings #1\n",i);
|
||||||
|
|
||||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
|
||||||
ConnectionSlot *connectionSlot = slots[i];
|
ConnectionSlot *connectionSlot = slots[i];
|
||||||
if(connectionSlot != NULL && connectionSlot->isConnected()) {
|
if(connectionSlot != NULL && connectionSlot->isConnected()) {
|
||||||
if(connectionSlot->getReceivedNetworkGameStatus() == false) {
|
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) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
|
||||||
ConnectionSlot *connectionSlot = slots[i];
|
ConnectionSlot *connectionSlot = slots[i];
|
||||||
if(connectionSlot != NULL && connectionSlot->isConnected()) {
|
if(connectionSlot != NULL && connectionSlot->isConnected()) {
|
||||||
connectionSlot->setReceivedNetworkGameStatus(false);
|
connectionSlot->setReceivedNetworkGameStatus(false);
|
||||||
@@ -1928,8 +1812,7 @@ void ServerInterface::setGameSettings(GameSettings *serverGameSettings, bool wai
|
|||||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
//printf("===> START slot %d - About to setGameSettings 2\n",i);
|
//printf("===> START slot %d - About to setGameSettings 2\n",i);
|
||||||
|
|
||||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
|
||||||
ConnectionSlot *connectionSlot = slots[i];
|
ConnectionSlot *connectionSlot = slots[i];
|
||||||
if(connectionSlot != NULL && connectionSlot->isConnected()) {
|
if(connectionSlot != NULL && connectionSlot->isConnected()) {
|
||||||
if(connectionSlot->getReceivedNetworkGameStatus() == false) {
|
if(connectionSlot->getReceivedNetworkGameStatus() == false) {
|
||||||
@@ -1980,8 +1863,7 @@ std::map<string,string> ServerInterface::publishToMasterserver() {
|
|||||||
std::map < string, string > publishToServerInfo;
|
std::map < string, string > publishToServerInfo;
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
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) {
|
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||||
//MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],CODE_AT_LINE_X(i));
|
||||||
ReadWriteMutexSafeWrapper safeRWL(&slotAccessorMutexes[i],true,CODE_AT_LINE_X(i));
|
|
||||||
if(slots[i] != NULL) {
|
if(slots[i] != NULL) {
|
||||||
slotCountUsed++;
|
slotCountUsed++;
|
||||||
slotCountHumans++;
|
slotCountHumans++;
|
||||||
|
@@ -48,8 +48,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
ConnectionSlot* slots[GameConstants::maxPlayers];
|
ConnectionSlot* slots[GameConstants::maxPlayers];
|
||||||
//Mutex slotAccessorMutexes[GameConstants::maxPlayers];
|
Mutex slotAccessorMutexes[GameConstants::maxPlayers];
|
||||||
ReadWriteMutex slotAccessorMutexes[GameConstants::maxPlayers];
|
|
||||||
|
|
||||||
ServerSocket serverSocket;
|
ServerSocket serverSocket;
|
||||||
bool gameHasBeenInitiated;
|
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 checkForLaggingClients(std::map<int,bool> &mapSlotSignalledList, std::map<int,ConnectionSlotEvent> &eventList, std::map<PLATFORM_SOCKET,bool> &socketTriggeredList,std::vector <string> &errorMsgList);
|
||||||
void executeNetworkCommandsFromClients();
|
void executeNetworkCommandsFromClients();
|
||||||
void dispatchPendingChatMessages(std::vector <string> &errorMsgList);
|
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
|
}}//end namespace
|
||||||
|
@@ -333,10 +333,6 @@ void FactionThread::execute() {
|
|||||||
safeMutex.ReleaseLock();
|
safeMutex.ReleaseLock();
|
||||||
|
|
||||||
setTaskCompleted(frameIndex.first);
|
setTaskCompleted(frameIndex.first);
|
||||||
this->faction->signalWorkerTaskCompleted();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this->faction->signalWorkerTaskCompleted();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(getQuitStatus() == true) {
|
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);
|
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) {
|
catch(const exception &ex) {
|
||||||
this->faction->signalWorkerTaskCompleted();
|
|
||||||
//setRunningStatus(false);
|
//setRunningStatus(false);
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
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());
|
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__);
|
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__);
|
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() {
|
void Faction::end() {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
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<int> livingUnits;
|
||||||
set<Unit*> livingUnitsp;
|
set<Unit*> livingUnitsp;
|
||||||
|
|
||||||
Semaphore semWorkerTaskCompleted;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Faction();
|
Faction();
|
||||||
~Faction();
|
~Faction();
|
||||||
|
|
||||||
void signalWorkerTaskCompleted();
|
|
||||||
bool waitWorkerTaskCompleted(int waitMilliseconds=-1);
|
|
||||||
|
|
||||||
void addLivingUnits(int id) { livingUnits.insert(id); }
|
void addLivingUnits(int id) { livingUnits.insert(id); }
|
||||||
void addLivingUnitsp(Unit *unit) { livingUnitsp.insert(unit); }
|
void addLivingUnitsp(Unit *unit) { livingUnitsp.insert(unit); }
|
||||||
|
|
||||||
|
@@ -372,40 +372,30 @@ void World::updateAllFactionUnits() {
|
|||||||
faction->signalWorkerThread(frameCount);
|
faction->signalWorkerThread(frameCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool workThreadsFinished = false;
|
||||||
Chrono chrono;
|
Chrono chrono;
|
||||||
chrono.start();
|
chrono.start();
|
||||||
|
|
||||||
const int MAX_FACTION_THREAD_WAIT_MILLISECONDS = 20000;
|
const int MAX_FACTION_THREAD_WAIT_MILLISECONDS = 20000;
|
||||||
// bool workThreadsFinished = false;
|
for(;chrono.getMillis() < MAX_FACTION_THREAD_WAIT_MILLISECONDS;) {
|
||||||
// for(;chrono.getMillis() < MAX_FACTION_THREAD_WAIT_MILLISECONDS;) {
|
workThreadsFinished = true;
|
||||||
// workThreadsFinished = true;
|
for(int i = 0; i < factionCount; ++i) {
|
||||||
// for(int i = 0; i < factionCount; ++i) {
|
Faction *faction = getFaction(i);
|
||||||
// Faction *faction = getFaction(i);
|
if(faction == NULL) {
|
||||||
// if(faction == NULL) {
|
throw runtime_error("faction == NULL");
|
||||||
// throw runtime_error("faction == NULL");
|
}
|
||||||
// }
|
if(faction->isWorkerThreadSignalCompleted(frameCount) == false) {
|
||||||
// if(faction->isWorkerThreadSignalCompleted(frameCount) == false) {
|
workThreadsFinished = false;
|
||||||
// workThreadsFinished = false;
|
break;
|
||||||
// break;
|
}
|
||||||
// }
|
}
|
||||||
// }
|
if(workThreadsFinished == false) {
|
||||||
// if(workThreadsFinished == false) {
|
//sleep(0);
|
||||||
// //sleep(0);
|
}
|
||||||
// }
|
else {
|
||||||
// else {
|
break;
|
||||||
// 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");
|
|
||||||
}
|
}
|
||||||
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);
|
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;
|
time_t lastThreadedPing;
|
||||||
//Mutex pingThreadAccessor;
|
//Mutex pingThreadAccessor;
|
||||||
|
|
||||||
//Mutex dataSynchAccessorRead;
|
Mutex dataSynchAccessorRead;
|
||||||
//Mutex dataSynchAccessorWrite;
|
Mutex dataSynchAccessorWrite;
|
||||||
ReadWriteMutex dataSynchAccessorRWLMutex;
|
|
||||||
|
|
||||||
ReadWriteMutex inSocketDestructorSynchAccessor;
|
Mutex inSocketDestructorSynchAccessor;
|
||||||
//bool inSocketDestructor;
|
bool inSocketDestructor;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Socket(PLATFORM_SOCKET sock);
|
Socket(PLATFORM_SOCKET sock);
|
||||||
|
@@ -785,25 +785,26 @@ bool Socket::isSocketValid(const PLATFORM_SOCKET *validateSocket) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Socket::Socket(PLATFORM_SOCKET sock) {
|
Socket::Socket(PLATFORM_SOCKET sock) {
|
||||||
ReadWriteMutexSafeWrapper safeMutexSocketDestructorFlag(&inSocketDestructorSynchAccessor,true,CODE_AT_LINE);
|
MutexSafeWrapper safeMutexSocketDestructorFlag(&inSocketDestructorSynchAccessor,CODE_AT_LINE);
|
||||||
inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
|
inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
|
||||||
//this->inSocketDestructor = false;
|
this->inSocketDestructor = false;
|
||||||
//safeMutexSocketDestructorFlag.ReleaseLock();
|
//safeMutexSocketDestructorFlag.ReleaseLock();
|
||||||
|
|
||||||
//this->pingThread = NULL;
|
//this->pingThread = NULL;
|
||||||
//pingThreadAccessor.setOwnerId(CODE_AT_LINE);
|
//pingThreadAccessor.setOwnerId(CODE_AT_LINE);
|
||||||
//dataSynchAccessorRead.setOwnerId(CODE_AT_LINE);
|
dataSynchAccessorRead.setOwnerId(CODE_AT_LINE);
|
||||||
//dataSynchAccessorWrite.setOwnerId(CODE_AT_LINE);
|
dataSynchAccessorWrite.setOwnerId(CODE_AT_LINE);
|
||||||
dataSynchAccessorRWLMutex.setOwnerId(CODE_AT_LINE);
|
|
||||||
|
|
||||||
|
|
||||||
this->sock= sock;
|
this->sock= sock;
|
||||||
this->connectedIpAddress = "";
|
this->connectedIpAddress = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
Socket::Socket() {
|
Socket::Socket() {
|
||||||
ReadWriteMutexSafeWrapper safeMutexSocketDestructorFlag(&inSocketDestructorSynchAccessor,true,CODE_AT_LINE);
|
MutexSafeWrapper safeMutexSocketDestructorFlag(&inSocketDestructorSynchAccessor,CODE_AT_LINE);
|
||||||
inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
|
inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
|
||||||
//this->inSocketDestructor = false;
|
this->inSocketDestructor = false;
|
||||||
//safeMutexSocketDestructorFlag.ReleaseLock();
|
//safeMutexSocketDestructorFlag.ReleaseLock();
|
||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
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() {
|
Socket::~Socket() {
|
||||||
ReadWriteMutexSafeWrapper safeMutexSocketDestructorFlag(&inSocketDestructorSynchAccessor,false,CODE_AT_LINE);
|
MutexSafeWrapper safeMutexSocketDestructorFlag(&inSocketDestructorSynchAccessor,CODE_AT_LINE);
|
||||||
//if(this->inSocketDestructor == true) {
|
if(this->inSocketDestructor == true) {
|
||||||
// SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] this->inSocketDestructor == true\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] this->inSocketDestructor == true\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
// return;
|
return;
|
||||||
//}
|
}
|
||||||
inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
|
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);
|
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();
|
disconnectSocket();
|
||||||
|
|
||||||
// Allow other callers with a lock on the mutexes to let them go
|
// Allow other callers with a lock on the mutexes to let them go
|
||||||
//for(time_t elapsed = time(NULL);
|
for(time_t elapsed = time(NULL);
|
||||||
// (dataSynchAccessorRead.getRefCount() > 0 ||
|
(dataSynchAccessorRead.getRefCount() > 0 ||
|
||||||
// dataSynchAccessorWrite.getRefCount() > 0) &&
|
dataSynchAccessorWrite.getRefCount() > 0) &&
|
||||||
// difftime(time(NULL),elapsed) <= 5;) {
|
difftime(time(NULL),elapsed) <= 5;) {
|
||||||
//sleep(0);
|
//sleep(0);
|
||||||
//}
|
}
|
||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END closing socket = %d...\n",__FILE__,__FUNCTION__,sock);
|
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(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);
|
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 safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
|
||||||
//MutexSafeWrapper safeMutex1(&dataSynchAccessorWrite,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex1(&dataSynchAccessorWrite,CODE_AT_LINE);
|
||||||
ReadWriteMutexSafeWrapper safeMutex(&dataSynchAccessorRWLMutex,false,CODE_AT_LINE);
|
|
||||||
::shutdown(sock,2);
|
::shutdown(sock,2);
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
::close(sock);
|
::close(sock);
|
||||||
@@ -951,8 +951,8 @@ void Socket::disconnectSocket() {
|
|||||||
::closesocket(sock);
|
::closesocket(sock);
|
||||||
sock = -1;
|
sock = -1;
|
||||||
#endif
|
#endif
|
||||||
//safeMutex.ReleaseLock();
|
safeMutex.ReleaseLock();
|
||||||
//safeMutex1.ReleaseLock();
|
safeMutex1.ReleaseLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END closing socket = %d...\n",__FILE__,__FUNCTION__,sock);
|
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);
|
// inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
|
||||||
// safeMutexSocketDestructorFlag.ReleaseLock();
|
// safeMutexSocketDestructorFlag.ReleaseLock();
|
||||||
|
|
||||||
//MutexSafeWrapper safeMutex(&dataSynchAccessorWrite,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(&dataSynchAccessorWrite,CODE_AT_LINE);
|
||||||
ReadWriteMutexSafeWrapper safeMutex(&dataSynchAccessorRWLMutex,false,CODE_AT_LINE);
|
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
bytesSent = ::send(sock, (const char *)data, dataSize, SO_NOSIGPIPE);
|
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);
|
// inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
|
||||||
// safeMutexSocketDestructorFlag.ReleaseLock();
|
// safeMutexSocketDestructorFlag.ReleaseLock();
|
||||||
|
|
||||||
//MutexSafeWrapper safeMutex(&dataSynchAccessorWrite,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(&dataSynchAccessorWrite,CODE_AT_LINE);
|
||||||
ReadWriteMutexSafeWrapper safeMutex(&dataSynchAccessorRWLMutex,false,CODE_AT_LINE);
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
bytesSent = ::send(sock, (const char *)data, dataSize, SO_NOSIGPIPE);
|
bytesSent = ::send(sock, (const char *)data, dataSize, SO_NOSIGPIPE);
|
||||||
#else
|
#else
|
||||||
@@ -1272,8 +1270,7 @@ int Socket::send(const void *data, int dataSize) {
|
|||||||
// inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
|
// inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
|
||||||
// safeMutexSocketDestructorFlag.ReleaseLock();
|
// safeMutexSocketDestructorFlag.ReleaseLock();
|
||||||
|
|
||||||
//MutexSafeWrapper safeMutex(&dataSynchAccessorWrite,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(&dataSynchAccessorWrite,CODE_AT_LINE);
|
||||||
ReadWriteMutexSafeWrapper safeMutex(&dataSynchAccessorRWLMutex,false,CODE_AT_LINE);
|
|
||||||
const char *sendBuf = (const char *)data;
|
const char *sendBuf = (const char *)data;
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
bytesSent = ::send(sock, &sendBuf[totalBytesSent], dataSize - totalBytesSent, SO_NOSIGPIPE);
|
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);
|
// inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
|
||||||
// safeMutexSocketDestructorFlag.ReleaseLock();
|
// safeMutexSocketDestructorFlag.ReleaseLock();
|
||||||
|
|
||||||
//MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
|
||||||
ReadWriteMutexSafeWrapper safeMutex(&dataSynchAccessorRWLMutex,true,CODE_AT_LINE);
|
|
||||||
bytesReceived = recv(sock, reinterpret_cast<char*>(data), dataSize, 0);
|
bytesReceived = recv(sock, reinterpret_cast<char*>(data), dataSize, 0);
|
||||||
safeMutex.ReleaseLock();
|
safeMutex.ReleaseLock();
|
||||||
}
|
}
|
||||||
@@ -1368,8 +1364,7 @@ int Socket::receive(void *data, int dataSize, bool tryReceiveUntilDataSizeMet) {
|
|||||||
// inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
|
// inSocketDestructorSynchAccessor.setOwnerId(CODE_AT_LINE);
|
||||||
// safeMutexSocketDestructorFlag.ReleaseLock();
|
// safeMutexSocketDestructorFlag.ReleaseLock();
|
||||||
|
|
||||||
//MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
|
||||||
ReadWriteMutexSafeWrapper safeMutex(&dataSynchAccessorRWLMutex,true,CODE_AT_LINE);
|
|
||||||
bytesReceived = recv(sock, reinterpret_cast<char*>(data), dataSize, 0);
|
bytesReceived = recv(sock, reinterpret_cast<char*>(data), dataSize, 0);
|
||||||
safeMutex.ReleaseLock();
|
safeMutex.ReleaseLock();
|
||||||
|
|
||||||
@@ -1428,8 +1423,7 @@ int Socket::peek(void *data, int dataSize,bool mustGetData) {
|
|||||||
// safeMutexSocketDestructorFlag.ReleaseLock();
|
// safeMutexSocketDestructorFlag.ReleaseLock();
|
||||||
|
|
||||||
//MutexSafeWrapper safeMutex(&dataSynchAccessor,CODE_AT_LINE + "_" + intToStr(sock) + "_" + intToStr(dataSize));
|
//MutexSafeWrapper safeMutex(&dataSynchAccessor,CODE_AT_LINE + "_" + intToStr(sock) + "_" + intToStr(dataSize));
|
||||||
//MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
|
||||||
ReadWriteMutexSafeWrapper safeMutex(&dataSynchAccessorRWLMutex,true,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());
|
//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();
|
// safeMutexSocketDestructorFlag.ReleaseLock();
|
||||||
|
|
||||||
//MutexSafeWrapper safeMutex(&dataSynchAccessor,CODE_AT_LINE + "_" + intToStr(sock) + "_" + intToStr(dataSize));
|
//MutexSafeWrapper safeMutex(&dataSynchAccessor,CODE_AT_LINE + "_" + intToStr(sock) + "_" + intToStr(dataSize));
|
||||||
//MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
|
||||||
ReadWriteMutexSafeWrapper safeMutex(&dataSynchAccessorRWLMutex,true,CODE_AT_LINE);
|
|
||||||
err = recv(sock, reinterpret_cast<char*>(data), dataSize, MSG_PEEK);
|
err = recv(sock, reinterpret_cast<char*>(data), dataSize, MSG_PEEK);
|
||||||
safeMutex.ReleaseLock();
|
safeMutex.ReleaseLock();
|
||||||
|
|
||||||
@@ -1764,8 +1757,7 @@ void ClientSocket::connect(const Ip &ip, int port)
|
|||||||
FD_SET(sock, &myset);
|
FD_SET(sock, &myset);
|
||||||
|
|
||||||
{
|
{
|
||||||
//MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
|
||||||
ReadWriteMutexSafeWrapper safeMutex(&dataSynchAccessorRWLMutex,true,CODE_AT_LINE);
|
|
||||||
err = select((int)sock + 1, NULL, &myset, NULL, &tv);
|
err = select((int)sock + 1, NULL, &myset, NULL, &tv);
|
||||||
//safeMutex.ReleaseLock();
|
//safeMutex.ReleaseLock();
|
||||||
}
|
}
|
||||||
@@ -2181,8 +2173,7 @@ Socket *ServerSocket::accept() {
|
|||||||
struct sockaddr_in cli_addr;
|
struct sockaddr_in cli_addr;
|
||||||
socklen_t clilen = sizeof(cli_addr);
|
socklen_t clilen = sizeof(cli_addr);
|
||||||
char client_host[100]="";
|
char client_host[100]="";
|
||||||
//MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
|
MutexSafeWrapper safeMutex(&dataSynchAccessorRead,CODE_AT_LINE);
|
||||||
ReadWriteMutexSafeWrapper safeMutex(&dataSynchAccessorRWLMutex,true,CODE_AT_LINE);
|
|
||||||
PLATFORM_SOCKET newSock= ::accept(sock, (struct sockaddr *) &cli_addr, &clilen);
|
PLATFORM_SOCKET newSock= ::accept(sock, (struct sockaddr *) &cli_addr, &clilen);
|
||||||
safeMutex.ReleaseLock();
|
safeMutex.ReleaseLock();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user