Skip to content
This repository has been archived by the owner on Dec 9, 2021. It is now read-only.

Commit

Permalink
An issue that appears when someone disconnects while ping is being up…
Browse files Browse the repository at this point in the history
…dated seems to be fixed.
  • Loading branch information
Flone-dnb committed Dec 14, 2019
1 parent 0dc492c commit 217c7f1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ide/SilentServer.pro.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.10.1, 2019-12-13T19:30:51. -->
<!-- Written by QtCreator 4.10.1, 2019-12-14T18:51:08. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
Expand Down
32 changes: 26 additions & 6 deletions src/Model/ServerService/serverservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,9 @@ void ServerService::listenForNewTCPConnections()
mtxConnectDisconnect .unlock();


if (bTextListen == false) break;


SOCKET newConnectedSocket;
newConnectedSocket = accept(listenTCPSocket, reinterpret_cast<sockaddr*>(&connectedWith), &iLen);

Expand Down Expand Up @@ -727,7 +730,7 @@ void ServerService::prepareForVoiceConnection()
sockaddr_in myAddr;
memset(myAddr.sin_zero, 0, sizeof(myAddr.sin_zero));
myAddr.sin_family = AF_INET;
myAddr.sin_port = htons(SERVER_PORT);
myAddr.sin_port = htons(pSettingsManager ->getCurrentSettings() ->iPort);
myAddr.sin_addr.s_addr = htonl(INADDR_ANY);


Expand Down Expand Up @@ -829,8 +832,9 @@ void ServerService::listenForMessage(UserStruct* userToListen)
}
}

clock_t timePassed = clock() - userToListen->keepAliveTimer;
clock_t timePassed = clock() - userToListen->keepAliveTimer;
float timePassedInSeconds = static_cast<float>(timePassed)/CLOCKS_PER_SEC;

if (timePassedInSeconds > INTERVAL_KEEPALIVE_SEC)
{
// User was inactive for INTERVAL_KEEPALIVE_SEC seconds
Expand Down Expand Up @@ -870,7 +874,18 @@ void ServerService::listenForMessage(UserStruct* userToListen)
}
}

std::this_thread::sleep_for(std::chrono::milliseconds(INTERVAL_TCP_MESSAGE_MS));
for (size_t i = 0; i < INTERVAL_TCP_ACCEPT_MS / 25; i++)
{
if (userToListen ->bConnectedToTextChat)
{
std::this_thread::sleep_for(std::chrono::milliseconds(25));
}
else
{
return;
}
}
//std::this_thread::sleep_for(std::chrono::milliseconds(INTERVAL_TCP_MESSAGE_MS));
}
}

Expand Down Expand Up @@ -1536,12 +1551,13 @@ void ServerService::responseToFIN(UserStruct* userToClose, bool bUserLost)
mtxUDPPackets .unlock();
}

mtxConnectDisconnect .unlock();
//mtxConnectDisconnect .unlock();

// Wait for listenForMessage() to end.
std::this_thread::sleep_for( std::chrono::milliseconds(INTERVAL_TCP_MESSAGE_MS) );
//std::this_thread::sleep_for( std::chrono::milliseconds(INTERVAL_TCP_MESSAGE_MS) );
std::this_thread::sleep_for( std::chrono::milliseconds(25) ); // 25 because look end of listenForMessage().

mtxConnectDisconnect .lock();
//mtxConnectDisconnect .lock();


iUsersConnectedCount--;
Expand Down Expand Up @@ -1818,6 +1834,8 @@ void ServerService::shutdownAllUsers()
{
if (users.size() != 0)
{
mtxConnectDisconnect .lock();

pLogManager ->printAndLog( "Shutting down...\n");

pMainWindow->updateOnlineUsersCount(0);
Expand Down Expand Up @@ -2003,6 +2021,8 @@ void ServerService::shutdownAllUsers()
bWinSockStarted = false;
}
}

mtxConnectDisconnect .unlock();
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/Model/net_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// TCP / UDP
#define INTERVAL_TCP_ACCEPT_MS 300
#define INTERVAL_TCP_MESSAGE_MS 120
#define INTERVAL_TCP_MESSAGE_MS 150 // must be a multiple of 25, see listenForMessage().
#define INTERVAL_UDP_MESSAGE_MS 2
#define ANTI_SPAM_MINIMUM_TIME_SEC 2.0f
#define INTERVAL_REFRESH_WRONG_PACKETS_SEC 30
Expand Down

0 comments on commit 217c7f1

Please sign in to comment.