mirror of
https://github.com/lubosz/overte.git
synced 2025-04-13 14:52:36 +02:00
Timebox readPendingDatagrams
This commit is contained in:
parent
8a95c58f86
commit
bcbbe884c7
1 changed files with 10 additions and 1 deletions
|
@ -315,9 +315,18 @@ void Socket::checkForReadyReadBackup() {
|
|||
}
|
||||
|
||||
void Socket::readPendingDatagrams() {
|
||||
using namespace std::chrono;
|
||||
static const auto MAX_PROCESS_TIME { 100ms };
|
||||
const auto abortTime = system_clock::now() + MAX_PROCESS_TIME;
|
||||
int packetSizeWithHeader = -1;
|
||||
|
||||
while (_udpSocket.hasPendingDatagrams() && (packetSizeWithHeader = _udpSocket.pendingDatagramSize()) != -1) {
|
||||
while (_udpSocket.hasPendingDatagrams() &&
|
||||
(packetSizeWithHeader = _udpSocket.pendingDatagramSize()) != -1) {
|
||||
if (system_clock::now() > abortTime) {
|
||||
// We've been running for too long, stop processing packets for now
|
||||
// Once we've processed the event queue, we'll come back to packet processing
|
||||
break;
|
||||
}
|
||||
|
||||
// we're reading a packet so re-start the readyRead backup timer
|
||||
_readyReadBackupTimer->start();
|
||||
|
|
Loading…
Reference in a new issue