- bugfixes for when players disconnect, do not switch observers to AI and only show message once.
- Attempts to debug/improve network performance
This commit is contained in:
parent
508a2a8277
commit
31e722287f
|
@ -40,7 +40,7 @@ namespace Glest{ namespace Game{
|
|||
const int PathFinder::maxFreeSearchRadius = 10;
|
||||
//const int PathFinder::pathFindNodesMax= 400;
|
||||
int PathFinder::pathFindNodesMax = 1000;
|
||||
const int PathFinder::pathFindRefresh = 20;
|
||||
const int PathFinder::pathFindRefresh = 10;
|
||||
const int PathFinder::pathFindBailoutRadius = 20;
|
||||
|
||||
|
||||
|
@ -325,7 +325,12 @@ void PathFinder::processNode(Unit *unit, Node *node,const Vec2i finalPos, int i,
|
|||
sucNode->prev= node;
|
||||
sucNode->next= NULL;
|
||||
sucNode->exploredCell= map->getSurfaceCell(Map::toSurfCoords(sucPos))->isExplored(unit->getTeam());
|
||||
openNodesList[sucNode->heuristic].push_back(sucNode);
|
||||
std::map<float, Nodes>::iterator iterFind = openNodesList.find(sucNode->heuristic);
|
||||
if(iterFind == openNodesList.end()) {
|
||||
openNodesList[sucNode->heuristic].reserve(PathFinder::pathFindNodesMax / 3);
|
||||
iterFind = openNodesList.find(sucNode->heuristic);
|
||||
}
|
||||
iterFind->second.push_back(sucNode);
|
||||
openPosList[sucNode->pos] = true;
|
||||
}
|
||||
else {
|
||||
|
@ -484,7 +489,13 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
|
|||
firstNode->pos= unitPos;
|
||||
firstNode->heuristic= heuristic(unitPos, finalPos);
|
||||
firstNode->exploredCell= true;
|
||||
openNodesList[firstNode->heuristic].push_back(firstNode);
|
||||
|
||||
std::map<float, Nodes>::iterator iterFind = openNodesList.find(firstNode->heuristic);
|
||||
if(iterFind == openNodesList.end()) {
|
||||
openNodesList[firstNode->heuristic].reserve(PathFinder::pathFindNodesMax / 3);
|
||||
iterFind = openNodesList.find(firstNode->heuristic);
|
||||
}
|
||||
iterFind->second.push_back(firstNode);
|
||||
openPosList[firstNode->pos] = true;
|
||||
|
||||
//b) loop
|
||||
|
@ -516,7 +527,12 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
|
|||
|
||||
//b4) move this node from closedNodes to openNodes
|
||||
//add all succesors that are not in closedNodes or openNodes to openNodes
|
||||
closedNodesList[node->heuristic].push_back(node);
|
||||
std::map<float, Nodes>::iterator iterFind = closedNodesList.find(node->heuristic);
|
||||
if(iterFind == closedNodesList.end()) {
|
||||
closedNodesList[node->heuristic].reserve(PathFinder::pathFindNodesMax / 3);
|
||||
iterFind = closedNodesList.find(node->heuristic);
|
||||
}
|
||||
iterFind->second.push_back(node);
|
||||
openPosList[node->pos] = true;
|
||||
|
||||
int tryDirection = random.randRange(0,3);
|
||||
|
@ -550,7 +566,7 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
|
|||
}
|
||||
} //while
|
||||
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 4) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled == true && chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] took msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis());
|
||||
|
||||
Node *lastNode= node;
|
||||
|
||||
|
|
|
@ -852,20 +852,27 @@ void Game::ReplaceDisconnectedNetworkPlayersWithAI(bool isNetworkGame, NetworkRo
|
|||
|
||||
for(int i = 0; i < world.getFactionCount(); ++i) {
|
||||
Faction *faction = world.getFaction(i);
|
||||
if( faction->getControlType() == ctNetwork ||
|
||||
if( faction->getFactionDisconnectHandled() == false &&
|
||||
(faction->getControlType() == ctNetwork ||
|
||||
faction->getControlType() == ctNetworkCpuEasy ||
|
||||
faction->getControlType() == ctNetworkCpu ||
|
||||
faction->getControlType() == ctNetworkCpuUltra ||
|
||||
faction->getControlType() == ctNetworkCpuMega) {
|
||||
faction->getControlType() == ctNetworkCpuMega)) {
|
||||
ConnectionSlot *slot = server->getSlot(faction->getStartLocationIndex());
|
||||
if(aiInterfaces[i] == NULL && (slot == NULL || slot->isConnected() == false)) {
|
||||
|
||||
faction->setControlType(ctCpu);
|
||||
aiInterfaces[i] = new AiInterface(*this, i, faction->getTeam(), faction->getStartLocationIndex());
|
||||
logger.add("Creating AI for faction " + intToStr(i), true);
|
||||
faction->setFactionDisconnectHandled(true);
|
||||
|
||||
char szBuf[255]="";
|
||||
sprintf(szBuf,"Player #%d [%s] has disconnected, switching player to AI mode!",i+1,this->gameSettings.getNetworkPlayerName(i).c_str());
|
||||
if(faction->getType()->getPersonalityType() != fpt_Observer) {
|
||||
faction->setControlType(ctCpu);
|
||||
aiInterfaces[i] = new AiInterface(*this, i, faction->getTeam(), faction->getStartLocationIndex());
|
||||
logger.add("Creating AI for faction " + intToStr(i), true);
|
||||
|
||||
sprintf(szBuf,"Player #%d [%s] has disconnected, switching player to AI mode!",i+1,this->gameSettings.getNetworkPlayerName(i).c_str());
|
||||
}
|
||||
else {
|
||||
sprintf(szBuf,"Player #%d [%s] has disconnected, but player was only an observer!",i+1,this->gameSettings.getNetworkPlayerName(i).c_str());
|
||||
}
|
||||
server->sendTextMessage(szBuf,-1,true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -125,16 +125,16 @@ void ClientInterface::update() {
|
|||
}
|
||||
|
||||
double lastSendElapsed = difftime(time(NULL),lastNetworkCommandListSendTime);
|
||||
if(lastSendElapsed > 0) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] lastSendElapsed = %f, networkMessageCommandList.getCommandCount() = %d, requestedCommands.empty() = %d\n",__FILE__,__FUNCTION__,__LINE__,lastSendElapsed,networkMessageCommandList.getCommandCount(),requestedCommands.empty());
|
||||
//if(lastSendElapsed > 0) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] lastSendElapsed = %f, networkMessageCommandList.getCommandCount() = %d, requestedCommands.empty() = %d\n",__FILE__,__FUNCTION__,__LINE__,lastSendElapsed,networkMessageCommandList.getCommandCount(),requestedCommands.empty());
|
||||
|
||||
if(networkMessageCommandList.getCommandCount() > 0 ||
|
||||
(lastNetworkCommandListSendTime > 0 && lastSendElapsed >= ClientInterface::maxNetworkCommandListSendTimeWait)) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
lastNetworkCommandListSendTime = time(NULL);
|
||||
sendMessage(&networkMessageCommandList);
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
}
|
||||
|
||||
// Possible cause of out of synch since we have more commands that need
|
||||
|
@ -508,13 +508,14 @@ void ClientInterface::updateLobby() {
|
|||
void ClientInterface::updateKeyframe(int frameCount) {
|
||||
currentFrameCount = frameCount;
|
||||
|
||||
int simulateLag = Config::getInstance().getInt("SimulateClientLag","0");
|
||||
bool done= false;
|
||||
while(done == false) {
|
||||
//wait for the next message
|
||||
waitForMessage();
|
||||
NetworkMessageType networkMessageType = waitForMessage();
|
||||
|
||||
// START: Test simulating lag for the client
|
||||
if(Config::getInstance().getInt("SimulateClientLag","0") > 0) {
|
||||
if(simulateLag > 0) {
|
||||
if(clientSimulationLagStartTime == 0) {
|
||||
clientSimulationLagStartTime = time(NULL);
|
||||
}
|
||||
|
@ -525,7 +526,7 @@ void ClientInterface::updateKeyframe(int frameCount) {
|
|||
// END: Test simulating lag for the client
|
||||
|
||||
//check we have an expected message
|
||||
NetworkMessageType networkMessageType= getNextMessageType(true);
|
||||
//NetworkMessageType networkMessageType= getNextMessageType(true);
|
||||
|
||||
switch(networkMessageType)
|
||||
{
|
||||
|
@ -811,7 +812,7 @@ string ClientInterface::getNetworkStatus() {
|
|||
return szBuf;
|
||||
}
|
||||
|
||||
void ClientInterface::waitForMessage()
|
||||
NetworkMessageType ClientInterface::waitForMessage()
|
||||
{
|
||||
// Debug!
|
||||
/*
|
||||
|
@ -825,41 +826,47 @@ void ClientInterface::waitForMessage()
|
|||
Chrono chrono;
|
||||
chrono.start();
|
||||
|
||||
NetworkMessageType msg = nmtInvalid;
|
||||
int waitLoopCount = 0;
|
||||
while(getNextMessageType(true) == nmtInvalid) {
|
||||
if(isConnected() == false) {
|
||||
if(quit == false) {
|
||||
//throw runtime_error("Disconnected");
|
||||
//sendTextMessage("Server has Disconnected.",-1);
|
||||
DisplayErrorMessage("Server has Disconnected.");
|
||||
quit= true;
|
||||
while(msg == nmtInvalid) {
|
||||
msg = getNextMessageType(true);
|
||||
if(msg == nmtInvalid) {
|
||||
if(chrono.getMillis() % 150 == 0 && isConnected() == false) {
|
||||
if(quit == false) {
|
||||
//throw runtime_error("Disconnected");
|
||||
//sendTextMessage("Server has Disconnected.",-1);
|
||||
DisplayErrorMessage("Server has Disconnected.");
|
||||
quit= true;
|
||||
}
|
||||
close();
|
||||
return msg;
|
||||
}
|
||||
close();
|
||||
return;
|
||||
|
||||
if(chrono.getMillis() > messageWaitTimeout) {
|
||||
//if(1) {
|
||||
//throw runtime_error("Timeout waiting for message");
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
sendTextMessage("Timeout waiting for message",-1, true);
|
||||
DisplayErrorMessage("Timeout waiting for message");
|
||||
quit= true;
|
||||
close();
|
||||
return msg;
|
||||
}
|
||||
// Sleep ever second we wait to let other threads work
|
||||
//else if(chrono.getMillis() % 1000 == 0) {
|
||||
//sleep(0);
|
||||
//}
|
||||
|
||||
//sleep(waitSleepTime);
|
||||
}
|
||||
|
||||
if(chrono.getMillis() > messageWaitTimeout) {
|
||||
//if(1) {
|
||||
//throw runtime_error("Timeout waiting for message");
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
sendTextMessage("Timeout waiting for message",-1, true);
|
||||
DisplayErrorMessage("Timeout waiting for message");
|
||||
quit= true;
|
||||
close();
|
||||
return;
|
||||
}
|
||||
// Sleep ever second we wait to let other threads work
|
||||
else if(chrono.getMillis() % 1000 == 0) {
|
||||
//sleep(0);
|
||||
}
|
||||
|
||||
//sleep(waitSleepTime);
|
||||
waitLoopCount++;
|
||||
}
|
||||
|
||||
if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] waiting took %lld msecs, waitLoopCount = %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis(),waitLoopCount);
|
||||
if(chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] waiting took %lld msecs, waitLoopCount = %d, msg = %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis(),waitLoopCount,msg);
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
void ClientInterface::quitGame(bool userManuallyQuit)
|
||||
|
|
|
@ -110,7 +110,7 @@ public:
|
|||
protected:
|
||||
|
||||
Mutex * getServerSynchAccessor() { return NULL; }
|
||||
void waitForMessage();
|
||||
NetworkMessageType waitForMessage();
|
||||
bool shouldDiscardNetworkMessage(NetworkMessageType networkMessageType);
|
||||
};
|
||||
|
||||
|
|
|
@ -58,9 +58,7 @@ NetworkMessageType NetworkInterface::getNextMessageType(bool checkHasDataFirst)
|
|||
int dataSize = socket->getDataToRead();
|
||||
if(dataSize >= sizeof(messageType)){
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] socket->getDataToRead() dataSize = %d\n",__FILE__,__FUNCTION__,__LINE__,dataSize);
|
||||
|
||||
int iPeek = socket->peek(&messageType, sizeof(messageType));
|
||||
|
||||
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 {
|
||||
|
|
|
@ -742,19 +742,28 @@ void ServerInterface::dispatchPendingChatMessages(std::vector <string> &errorMsg
|
|||
}
|
||||
|
||||
void ServerInterface::update() {
|
||||
//Chrono chrono;
|
||||
//chrono.start();
|
||||
|
||||
std::vector <string> errorMsgList;
|
||||
try {
|
||||
// The first thing we will do is check all clients to ensure they have
|
||||
// properly identified themselves within the alloted time period
|
||||
validateConnectedClients();
|
||||
|
||||
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] method running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||
|
||||
processTextMessageQueue();
|
||||
processBroadCastMessageQueue();
|
||||
|
||||
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] method running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||
|
||||
std::map<PLATFORM_SOCKET,bool> socketTriggeredList;
|
||||
//update all slots
|
||||
updateSocketTriggeredList(socketTriggeredList);
|
||||
|
||||
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] method running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||
|
||||
if(gameHasBeenInitiated == false || socketTriggeredList.size() > 0) {
|
||||
std::map<int,ConnectionSlotEvent> eventList;
|
||||
bool hasData = Socket::hasDataToRead(socketTriggeredList);
|
||||
|
@ -768,22 +777,34 @@ void ServerInterface::update() {
|
|||
signalClientsToRecieveData(socketTriggeredList, eventList, mapSlotSignalledList);
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ============ Step #2\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] method running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||
|
||||
// Step #2 check all connection slot worker threads for completed status
|
||||
checkForCompletedClients(mapSlotSignalledList,errorMsgList, eventList);
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ============ Step #3\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] method running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||
|
||||
// Step #3 check clients for any lagging scenarios and try to deal with them
|
||||
checForLaggingClients(mapSlotSignalledList, eventList, socketTriggeredList,errorMsgList);
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ============ Step #4\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] method running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||
|
||||
// Step #4 dispatch network commands to the pending list so that they are done in proper order
|
||||
executeNetworkCommandsFromClients();
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] ============ Step #5\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] method running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||
|
||||
// Step #5 dispatch pending chat messages
|
||||
dispatchPendingChatMessages(errorMsgList);
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] method running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||
}
|
||||
|
||||
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] method running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||
}
|
||||
}
|
||||
catch(const exception &ex) {
|
||||
|
@ -798,9 +819,9 @@ void ServerInterface::update() {
|
|||
DisplayErrorMessage(sErr);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] method running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||
}
|
||||
|
||||
void ServerInterface::updateKeyframe(int frameCount) {
|
||||
|
@ -1148,6 +1169,18 @@ bool ServerInterface::launchGame(const GameSettings *gameSettings) {
|
|||
}
|
||||
}
|
||||
if(bOkToStart == true) {
|
||||
|
||||
/*
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],string(__FILE__) + "_" + intToStr(__LINE__) + "_" + intToStr(i));
|
||||
ConnectionSlot *connectionSlot= slots[i];
|
||||
if(connectionSlot != NULL &&
|
||||
connectionSlot->isConnected()) {
|
||||
connectionSlot->getSocket()->setBlock(true);
|
||||
}
|
||||
}
|
||||
*/
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] needToRepublishToMasterserver = %d\n",__FILE__,__FUNCTION__,__LINE__,needToRepublishToMasterserver);
|
||||
|
||||
serverSocket.stopBroadCastThread();
|
||||
|
@ -1187,19 +1220,6 @@ bool ServerInterface::launchGame(const GameSettings *gameSettings) {
|
|||
delete ftpServer;
|
||||
ftpServer = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
for(int i= 0; exitServer == false && i < GameConstants::maxPlayers; ++i) {
|
||||
MutexSafeWrapper safeMutexSlot(&slotAccessorMutexes[i],string(__FILE__) + "_" + intToStr(__LINE__) + "_" + intToStr(i));
|
||||
ConnectionSlot *connectionSlot= slots[i];
|
||||
if(connectionSlot != NULL &&
|
||||
connectionSlot->isConnected()) {
|
||||
connectionSlot->getSocket()->setBlock(true);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
return bOkToStart;
|
||||
|
|
|
@ -36,6 +36,7 @@ Faction::Faction() {
|
|||
texture = NULL;
|
||||
//lastResourceTargettListPurge = 0;
|
||||
cachingDisabled=false;
|
||||
factionDisconnectHandled=false;
|
||||
}
|
||||
|
||||
Faction::~Faction() {
|
||||
|
|
|
@ -84,6 +84,8 @@ private:
|
|||
|
||||
bool thisFaction;
|
||||
|
||||
bool factionDisconnectHandled;
|
||||
|
||||
bool cachingDisabled;
|
||||
std::map<Vec2i, std::vector<FactionPathSuccessCache> > successfulPathFinderTargetList;
|
||||
std::map<Vec2i,int> cacheResourceTargetList;
|
||||
|
@ -105,6 +107,9 @@ public:
|
|||
int factionIndex, int teamIndex, int startLocationIndex, bool thisFaction, bool giveResources);
|
||||
void end();
|
||||
|
||||
bool getFactionDisconnectHandled() const { return factionDisconnectHandled;}
|
||||
void setFactionDisconnectHandled(bool value) { factionDisconnectHandled=value;}
|
||||
|
||||
//get
|
||||
const Resource *getResource(const ResourceType *rt) const;
|
||||
const Resource *getResource(int i) const {return &resources[i];}
|
||||
|
|
|
@ -844,7 +844,7 @@ void Socket::disconnectSocket() {
|
|||
::closesocket(sock);
|
||||
sock = -1;
|
||||
#endif
|
||||
safeMutex.ReleaseLock();
|
||||
//safeMutex.ReleaseLock();
|
||||
}
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] END closing socket = %d...\n",__FILE__,__FUNCTION__,sock);
|
||||
|
@ -1041,7 +1041,7 @@ int Socket::send(const void *data, int dataSize) {
|
|||
#else
|
||||
bytesSent = ::send(sock, (const char *)data, dataSize, MSG_NOSIGNAL | MSG_DONTWAIT);
|
||||
#endif
|
||||
safeMutex.ReleaseLock();
|
||||
//safeMutex.ReleaseLock();
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
}
|
||||
|
||||
|
@ -1078,7 +1078,7 @@ int Socket::send(const void *data, int dataSize) {
|
|||
break;
|
||||
}
|
||||
|
||||
safeMutex.ReleaseLock();
|
||||
//safeMutex.ReleaseLock();
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #2 EAGAIN during send, trying again returned: %d\n",__FILE__,__FUNCTION__,__LINE__,bytesSent);
|
||||
}
|
||||
|
@ -1124,7 +1124,7 @@ int Socket::send(const void *data, int dataSize) {
|
|||
break;
|
||||
}
|
||||
|
||||
safeMutex.ReleaseLock();
|
||||
//safeMutex.ReleaseLock();
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] retry send returned: %d\n",__FILE__,__FUNCTION__,__LINE__,bytesSent);
|
||||
}
|
||||
|
@ -1171,7 +1171,7 @@ int Socket::receive(void *data, int dataSize) {
|
|||
if(isSocketValid() == true) {
|
||||
MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__));
|
||||
bytesReceived = recv(sock, reinterpret_cast<char*>(data), dataSize, 0);
|
||||
safeMutex.ReleaseLock();
|
||||
//safeMutex.ReleaseLock();
|
||||
}
|
||||
if(bytesReceived < 0 && getLastSocketError() != PLATFORM_SOCKET_TRY_AGAIN) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] ERROR READING SOCKET DATA error while sending socket data, bytesSent = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,bytesReceived,getLastSocketErrorFormattedText().c_str());
|
||||
|
@ -1193,7 +1193,7 @@ int Socket::receive(void *data, int dataSize) {
|
|||
else if(Socket::isReadable() == true) {
|
||||
MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__));
|
||||
bytesReceived = recv(sock, reinterpret_cast<char*>(data), dataSize, 0);
|
||||
safeMutex.ReleaseLock();
|
||||
//safeMutex.ReleaseLock();
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #2 EAGAIN during receive, trying again returned: %d\n",__FILE__,__FUNCTION__,__LINE__,bytesReceived);
|
||||
}
|
||||
|
@ -1211,8 +1211,8 @@ int Socket::receive(void *data, int dataSize) {
|
|||
}
|
||||
|
||||
int Socket::peek(void *data, int dataSize,bool mustGetData) {
|
||||
//Chrono chrono;
|
||||
//chrono.start();
|
||||
Chrono chrono;
|
||||
chrono.start();
|
||||
|
||||
const int MAX_PEEK_WAIT_SECONDS = 3;
|
||||
|
||||
|
@ -1220,14 +1220,15 @@ int Socket::peek(void *data, int dataSize,bool mustGetData) {
|
|||
if(isSocketValid() == true) {
|
||||
//if(chrono.getMillis() > 1) printf("In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||
|
||||
MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__) + "_" + intToStr(sock) + "_" + intToStr(dataSize));
|
||||
//MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__) + "_" + intToStr(sock) + "_" + intToStr(dataSize));
|
||||
MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + string("_") + intToStr(__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());
|
||||
|
||||
err = recv(sock, reinterpret_cast<char*>(data), dataSize, MSG_PEEK);
|
||||
safeMutex.ReleaseLock();
|
||||
//safeMutex.ReleaseLock();
|
||||
|
||||
//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) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"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());
|
||||
|
||||
|
@ -1249,6 +1250,7 @@ int Socket::peek(void *data, int dataSize,bool mustGetData) {
|
|||
time_t tStartTimer = time(NULL);
|
||||
while((err < 0 && getLastSocketError() == PLATFORM_SOCKET_TRY_AGAIN) &&
|
||||
(difftime(time(NULL),tStartTimer) <= MAX_PEEK_WAIT_SECONDS)) {
|
||||
/*
|
||||
if(isConnected() == false) {
|
||||
int iErr = getLastSocketError();
|
||||
disconnectSocket();
|
||||
|
@ -1256,11 +1258,14 @@ int Socket::peek(void *data, int dataSize,bool mustGetData) {
|
|||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"[%s::%s Line: %d] DISCONNECTED SOCKET error while peeking socket data, err = %d, error = %s\n",__FILE__,__FUNCTION__,__LINE__,err,getLastSocketErrorFormattedText(&iErr).c_str());
|
||||
break;
|
||||
}
|
||||
else if(Socket::isReadable() == true) {
|
||||
MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__));
|
||||
*/
|
||||
if(Socket::isReadable() == true) {
|
||||
//MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__) + "_" + intToStr(sock) + "_" + intToStr(dataSize));
|
||||
MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + string("_") + intToStr(__LINE__));
|
||||
err = recv(sock, reinterpret_cast<char*>(data), dataSize, MSG_PEEK);
|
||||
safeMutex.ReleaseLock();
|
||||
//safeMutex.ReleaseLock();
|
||||
|
||||
if(chrono.getMillis() > 1) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] action running for msecs: %lld\n",__FILE__,__FUNCTION__,__LINE__,(long long int)chrono.getMillis());
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #2 EAGAIN during peek, trying again returned: %d\n",__FILE__,__FUNCTION__,__LINE__,err);
|
||||
}
|
||||
}
|
||||
|
@ -1326,7 +1331,7 @@ bool Socket::isReadable() {
|
|||
{
|
||||
MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__));
|
||||
i= select((int)sock + 1, &set, NULL, NULL, &tv);
|
||||
safeMutex.ReleaseLock();
|
||||
//safeMutex.ReleaseLock();
|
||||
}
|
||||
if(i < 0) {
|
||||
//if(difftime(time(NULL),lastDebugEvent) >= 1) {
|
||||
|
@ -1365,7 +1370,7 @@ bool Socket::isWritable(bool waitOnDelayedResponse) {
|
|||
{
|
||||
MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__));
|
||||
i = select((int)sock + 1, NULL, &set, NULL, &tv);
|
||||
safeMutex.ReleaseLock();
|
||||
//safeMutex.ReleaseLock();
|
||||
}
|
||||
if(i < 0 ) {
|
||||
//if(difftime(time(NULL),lastDebugEvent) >= 1) {
|
||||
|
@ -1548,7 +1553,7 @@ void ClientSocket::connect(const Ip &ip, int port)
|
|||
{
|
||||
MutexSafeWrapper safeMutex(&dataSynchAccessor,string(__FILE__) + "_" + intToStr(__LINE__));
|
||||
err = select((int)sock + 1, NULL, &myset, NULL, &tv);
|
||||
safeMutex.ReleaseLock();
|
||||
//safeMutex.ReleaseLock();
|
||||
}
|
||||
|
||||
if (err < 0 && getLastSocketError() != PLATFORM_SOCKET_INTERRUPTED) {
|
||||
|
|
Loading…
Reference in New Issue