1
0
forked from mirrors/0ad

Thread the NetClient session.

This threads the netclient session, which avoids timeouts when the
main-thread is not polling (map creation, very long simulation frames).

Unlike the NetServer, which should be as independent as possible from
the main thread, the NetClient is fundamentally tied to the game thread.
Therefore, this only threads the session object.
To ensure good performance and ease-of-use, lock-free queues for
in/out-going messages are used.

This fixes artificial timeouts, while also improving actual ping reports
(since frame-time is no longer a factor).
It effectively reverts D1513/eda236522c and 2e7e1c0b2b, all hacks around
lag-timeouts (and bits of 1a3fb29ff3).

Based on a patch by: Stan
Comments by: Vladislavbelov
Fixes #3700, refs #3373

Differential Revision: https://code.wildfiregames.com/D2848
This was SVN commit r24518.
This commit is contained in:
wraitii
2021-01-06 15:26:11 +00:00
parent 8ae3c09dc0
commit 2d40068cd1
8 changed files with 166 additions and 189 deletions
+1 -10
View File
@@ -56,7 +56,7 @@
#define DEFAULT_SERVER_NAME L"Unnamed Server"
static const int CHANNEL_COUNT = 1;
constexpr int CHANNEL_COUNT = 1;
/**
* enet_host_service timeout (msecs).
@@ -1112,8 +1112,6 @@ bool CNetServerWorker::OnAuthenticate(void* context, CFsmEvent* event)
// the most efficient client to request a copy from
CNetServerSession* sourceSession = server.m_Sessions.at(0);
session->SetLongTimeout(true);
sourceSession->GetFileTransferer().StartTask(
shared_ptr<CNetFileReceiveTask>(new CNetFileReceiveTask_ServerRejoin(server, newHostID))
);
@@ -1291,8 +1289,6 @@ bool CNetServerWorker::OnLoadedGame(void* context, CFsmEvent* event)
CNetServerSession* loadedSession = (CNetServerSession*)context;
CNetServerWorker& server = loadedSession->GetServer();
loadedSession->SetLongTimeout(false);
// We're in the loading state, so wait until every client has loaded
// before starting the game
ENSURE(server.m_State == SERVER_STATE_LOADING);
@@ -1390,8 +1386,6 @@ bool CNetServerWorker::OnRejoined(void* context, CFsmEvent* event)
session->SendMessage(&pausedMessage);
}
session->SetLongTimeout(false);
return true;
}
@@ -1488,10 +1482,7 @@ void CNetServerWorker::StartGame()
m_ServerTurnManager = new CNetServerTurnManager(*this);
for (CNetServerSession* session : m_Sessions)
{
m_ServerTurnManager->InitialiseClient(session->GetHostID(), 0); // TODO: only for non-observers
session->SetLongTimeout(true);
}
m_State = SERVER_STATE_LOADING;