@@ -311,6 +311,7 @@ void Client::connect(Address address, bool is_local_server)
311
311
{
312
312
initLocalMapSaving (address, m_address_name, is_local_server);
313
313
314
+ // Since we use TryReceive() a timeout here would be ineffective anyway
314
315
m_con->SetTimeoutMs (0 );
315
316
m_con->Connect (address);
316
317
}
@@ -795,36 +796,31 @@ void Client::initLocalMapSaving(const Address &address,
795
796
796
797
void Client::ReceiveAll ()
797
798
{
799
+ NetworkPacket pkt;
798
800
u64 start_ms = porting::getTimeMs ();
799
- for (;;)
800
- {
801
+ const u64 budget = 100 ;
802
+ for (;;) {
801
803
// Limit time even if there would be huge amounts of data to
802
804
// process
803
- if (porting::getTimeMs () > start_ms + 100 )
805
+ if (porting::getTimeMs () > start_ms + budget) {
806
+ infostream << " Client::ReceiveAll(): "
807
+ " Packet processing budget exceeded." << std::endl;
804
808
break ;
809
+ }
805
810
811
+ pkt.clear ();
806
812
try {
807
- Receive ();
808
- g_profiler->graphAdd (" client_received_packets" , 1 );
809
- }
810
- catch (con::NoIncomingDataException &e) {
811
- break ;
812
- }
813
- catch (con::InvalidIncomingDataException &e) {
814
- infostream<<" Client::ReceiveAll(): "
813
+ if (!m_con->TryReceive (&pkt))
814
+ break ;
815
+ ProcessData (&pkt);
816
+ } catch (const con::InvalidIncomingDataException &e) {
817
+ infostream << " Client::ReceiveAll(): "
815
818
" InvalidIncomingDataException: what()="
816
- << e.what ()<< std::endl;
819
+ << e.what () << std::endl;
817
820
}
818
821
}
819
822
}
820
823
821
- void Client::Receive ()
822
- {
823
- NetworkPacket pkt;
824
- m_con->Receive (&pkt);
825
- ProcessData (&pkt);
826
- }
827
-
828
824
inline void Client::handleCommand (NetworkPacket* pkt)
829
825
{
830
826
const ToClientCommandHandler& opHandle = toClientCommandTable[pkt->getCommand ()];
@@ -841,6 +837,7 @@ void Client::ProcessData(NetworkPacket *pkt)
841
837
842
838
// infostream<<"Client: received command="<<command<<std::endl;
843
839
m_packetcounter.add ((u16)command);
840
+ g_profiler->graphAdd (" client_received_packets" , 1 );
844
841
845
842
/*
846
843
If this check is removed, be sure to change the queue
0 commit comments