diff options
author | Gabriel Pérez-Cerezo <gabriel@gpcf.eu> | 2019-11-28 12:30:21 +0100 |
---|---|---|
committer | Gabriel Pérez-Cerezo <gabriel@gpcf.eu> | 2019-11-28 12:30:21 +0100 |
commit | ddab98412f3fc47eedfa74f8a4edafd324e59707 (patch) | |
tree | 7087657e4b9d90e2e0559bfdc25cf2b3b52e51fe /src/network/connection.cpp | |
parent | 6dc7177a5de51f1329c1be04e7f07be64d5cc76c (diff) | |
download | minetest-ddab98412f3fc47eedfa74f8a4edafd324e59707.tar.gz minetest-ddab98412f3fc47eedfa74f8a4edafd324e59707.tar.bz2 minetest-ddab98412f3fc47eedfa74f8a4edafd324e59707.zip |
Add static_save and prevent UDP connect exhaustionslifo-fixes
This merges two pull requests from 5.0
Diffstat (limited to 'src/network/connection.cpp')
-rw-r--r-- | src/network/connection.cpp | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/network/connection.cpp b/src/network/connection.cpp index fb3ba92ae..a504bbc08 100644 --- a/src/network/connection.cpp +++ b/src/network/connection.cpp @@ -2884,16 +2884,21 @@ void Connection::Disconnect() putCommand(c); } -void Connection::Receive(NetworkPacket* pkt) +bool Connection::Receive(NetworkPacket *pkt, u32 timeout) { + /* + Note that this function can potentially wait infinitely if non-data + events keep happening before the timeout expires. + This is not considered to be a problem (is it?) + */ for(;;) { - ConnectionEvent e = waitEvent(m_bc_receive_timeout); + ConnectionEvent e = waitEvent(timeout); if (e.type != CONNEVENT_NONE) LOG(dout_con << getDesc() << ": Receive: got event: " << e.describe() << std::endl); switch(e.type) { case CONNEVENT_NONE: - throw NoIncomingDataException("No incoming data"); + return false; case CONNEVENT_DATA_RECEIVED: // Data size is lesser than command size, ignoring packet if (e.data.getSize() < 2) { @@ -2901,7 +2906,7 @@ void Connection::Receive(NetworkPacket* pkt) } pkt->putRawPacket(*e.data, e.data.getSize(), e.peer_id); - return; + return true; case CONNEVENT_PEER_ADDED: { UDPPeer tmp(e.peer_id, e.address, this); if (m_bc_peerhandler) @@ -2919,7 +2924,19 @@ void Connection::Receive(NetworkPacket* pkt) "(port already in use?)"); } } - throw NoIncomingDataException("No incoming data"); + return false; +} + +void Connection::Receive(NetworkPacket *pkt) +{ + bool any = Receive(pkt, m_bc_receive_timeout); + if (!any) + throw NoIncomingDataException("No incoming data"); +} + +bool Connection::TryReceive(NetworkPacket *pkt) +{ + return Receive(pkt, 0); } void Connection::Send(u16 peer_id, u8 channelnum, |