summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2019-11-19 20:23:00 +0100
committersfan5 <sfan5@live.de>2019-11-25 20:00:24 +0100
commit0b2f0914cc800bb3ae4c1f21e0c28cfdacc65f3f (patch)
tree84ac8f6d2aca9249808eea8dc25b6878b19422f0 /src
parent154080c8836942e438124af35cfc57ef1f304e73 (diff)
downloadminetest-0b2f0914cc800bb3ae4c1f21e0c28cfdacc65f3f.tar.gz
minetest-0b2f0914cc800bb3ae4c1f21e0c28cfdacc65f3f.tar.bz2
minetest-0b2f0914cc800bb3ae4c1f21e0c28cfdacc65f3f.zip
Improve client-side packet receiving
Diffstat (limited to 'src')
-rw-r--r--src/client/client.cpp35
-rw-r--r--src/client/client.h1
2 files changed, 16 insertions, 20 deletions
diff --git a/src/client/client.cpp b/src/client/client.cpp
index 5d4793c8a..315fcd410 100644
--- a/src/client/client.cpp
+++ b/src/client/client.cpp
@@ -311,6 +311,7 @@ void Client::connect(Address address, bool is_local_server)
{
initLocalMapSaving(address, m_address_name, is_local_server);
+ // Since we use TryReceive() a timeout here would be ineffective anyway
m_con->SetTimeoutMs(0);
m_con->Connect(address);
}
@@ -795,36 +796,31 @@ void Client::initLocalMapSaving(const Address &address,
void Client::ReceiveAll()
{
+ NetworkPacket pkt;
u64 start_ms = porting::getTimeMs();
- for(;;)
- {
+ const u64 budget = 100;
+ for(;;) {
// Limit time even if there would be huge amounts of data to
// process
- if(porting::getTimeMs() > start_ms + 100)
+ if (porting::getTimeMs() > start_ms + budget) {
+ infostream << "Client::ReceiveAll(): "
+ "Packet processing budget exceeded." << std::endl;
break;
+ }
+ pkt.clear();
try {
- Receive();
- g_profiler->graphAdd("client_received_packets", 1);
- }
- catch(con::NoIncomingDataException &e) {
- break;
- }
- catch(con::InvalidIncomingDataException &e) {
- infostream<<"Client::ReceiveAll(): "
+ if (!m_con->TryReceive(&pkt))
+ break;
+ ProcessData(&pkt);
+ } catch (const con::InvalidIncomingDataException &e) {
+ infostream << "Client::ReceiveAll(): "
"InvalidIncomingDataException: what()="
- <<e.what()<<std::endl;
+ << e.what() << std::endl;
}
}
}
-void Client::Receive()
-{
- NetworkPacket pkt;
- m_con->Receive(&pkt);
- ProcessData(&pkt);
-}
-
inline void Client::handleCommand(NetworkPacket* pkt)
{
const ToClientCommandHandler& opHandle = toClientCommandTable[pkt->getCommand()];
@@ -841,6 +837,7 @@ void Client::ProcessData(NetworkPacket *pkt)
//infostream<<"Client: received command="<<command<<std::endl;
m_packetcounter.add((u16)command);
+ g_profiler->graphAdd("client_received_packets", 1);
/*
If this check is removed, be sure to change the queue
diff --git a/src/client/client.h b/src/client/client.h
index 0e0765cae..10608ccf9 100644
--- a/src/client/client.h
+++ b/src/client/client.h
@@ -453,7 +453,6 @@ private:
bool is_local_server);
void ReceiveAll();
- void Receive();
void sendPlayerPos();