mirror of
https://github.com/overte-org/overte.git
synced 2025-04-26 20:36:15 +02:00
remove the ControlSender and perform sync in Socket
This commit is contained in:
parent
a31053d450
commit
50a7ef7c20
4 changed files with 19 additions and 110 deletions
|
@ -1,40 +0,0 @@
|
||||||
//
|
|
||||||
// ControlSender.cpp
|
|
||||||
// libraries/networking/src/udt
|
|
||||||
//
|
|
||||||
// Created by Stephen Birarda on 2015-07-27.
|
|
||||||
// Copyright 2015 High Fidelity, Inc.
|
|
||||||
//
|
|
||||||
// Distributed under the Apache License, Version 2.0.
|
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
|
||||||
//
|
|
||||||
|
|
||||||
#include <chrono>
|
|
||||||
#include <thread>
|
|
||||||
|
|
||||||
#include <QtCore/QCoreApplication>
|
|
||||||
#include <QtCore/QDebug>
|
|
||||||
|
|
||||||
#include "ControlSender.h"
|
|
||||||
|
|
||||||
using namespace udt;
|
|
||||||
|
|
||||||
void ControlSender::loop() {
|
|
||||||
while (!_isStopped) {
|
|
||||||
// grab the time now
|
|
||||||
auto start = std::chrono::high_resolution_clock::now();
|
|
||||||
|
|
||||||
// for each of the connections managed by the udt::Socket, we need to ask for the ACK value to send
|
|
||||||
|
|
||||||
// since we're infinitely looping, give the thread a chance to process events
|
|
||||||
QCoreApplication::processEvents();
|
|
||||||
|
|
||||||
auto end = std::chrono::high_resolution_clock::now();
|
|
||||||
|
|
||||||
std::chrono::duration<double, std::micro> elapsed = end - start;
|
|
||||||
int timeToSleep = _synInterval - (int) elapsed.count();
|
|
||||||
|
|
||||||
// based on how much time it took us to process, let's figure out how much time we have need to sleep
|
|
||||||
std::this_thread::sleep_for(std::chrono::microseconds(timeToSleep));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
//
|
|
||||||
// ControlSender.h
|
|
||||||
// libraries/networking/src/udt
|
|
||||||
//
|
|
||||||
// Created by Stephen Birarda on 2015-07-27.
|
|
||||||
// Copyright 2015 High Fidelity, Inc.
|
|
||||||
//
|
|
||||||
// Distributed under the Apache License, Version 2.0.
|
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
|
||||||
//
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef hifi_ControlSender_h
|
|
||||||
#define hifi_ControlSender_h
|
|
||||||
|
|
||||||
#include <QtCore/QObject>
|
|
||||||
|
|
||||||
namespace udt {
|
|
||||||
|
|
||||||
// Handles the sending of periodic control packets for all active UDT reliable connections
|
|
||||||
// Currently the interval for all connections is the same, so one thread is sufficient to manage all
|
|
||||||
class ControlSender : public QObject {
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
ControlSender(QObject* parent = 0) : QObject(parent) {};
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
void loop(); // infinitely loops and sleeps to manage rate of control packet sending
|
|
||||||
void stop() { _isStopped = true; } // stops the loop
|
|
||||||
|
|
||||||
private:
|
|
||||||
int _synInterval = 10 * 1000;
|
|
||||||
bool _isStopped { false };
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // hifi_ControlSender_h
|
|
|
@ -24,37 +24,11 @@ Socket::Socket(QObject* parent) :
|
||||||
{
|
{
|
||||||
connect(&_udpSocket, &QUdpSocket::readyRead, this, &Socket::readPendingDatagrams);
|
connect(&_udpSocket, &QUdpSocket::readyRead, this, &Socket::readPendingDatagrams);
|
||||||
|
|
||||||
// make a QThread for the ControlSender to live on
|
// make sure our synchronization method is called every SYN interval
|
||||||
QThread* controlThread = new QThread(this);
|
connect(&_synTimer, &QTimer::timeout, this, &Socket::rateControlSync);
|
||||||
|
|
||||||
// setup the ControlSender and parent it
|
// start our timer for the synchronization time interval
|
||||||
_controlSender = new ControlSender;
|
_synTimer->start(_synInterval);
|
||||||
|
|
||||||
// move the ControlSender to its thread
|
|
||||||
_controlSender->moveToThread(controlThread);
|
|
||||||
|
|
||||||
// start the ControlSender once the thread is started
|
|
||||||
connect(controlThread, &QThread::started, _controlSender, &ControlSender::loop);
|
|
||||||
|
|
||||||
// make sure the control thread is named so we can identify it
|
|
||||||
controlThread->setObjectName("UDT Control Thread");
|
|
||||||
|
|
||||||
// start the control thread
|
|
||||||
controlThread->start();
|
|
||||||
}
|
|
||||||
|
|
||||||
Socket::~Socket() {
|
|
||||||
if (_controlSender) {
|
|
||||||
QThread* controlThread = _controlSender->thread();
|
|
||||||
|
|
||||||
// tell the control sender to stop and be deleted so we can wait on its thread
|
|
||||||
_controlSender->stop();
|
|
||||||
_controlSender->deleteLater();
|
|
||||||
|
|
||||||
// make sure the control thread goes down
|
|
||||||
controlThread->quit();
|
|
||||||
controlThread->wait();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Socket::rebind() {
|
void Socket::rebind() {
|
||||||
|
@ -148,3 +122,14 @@ void Socket::readPendingDatagrams() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Socket::rateControlSync() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (_synTimer.interval() != _synInterval) {
|
||||||
|
// if the _synTimer interval doesn't match the current _synInterval (changes when the CC factory is changed)
|
||||||
|
// then restart it now with the right interval
|
||||||
|
_synTimer.start(_synInterval);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
|
#include <QtCore/QTimer>
|
||||||
#include <QtNetwork/QUdpSocket>
|
#include <QtNetwork/QUdpSocket>
|
||||||
|
|
||||||
#include "../HifiSockAddr.h"
|
#include "../HifiSockAddr.h"
|
||||||
|
@ -61,6 +62,7 @@ public:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void readPendingDatagrams();
|
void readPendingDatagrams();
|
||||||
|
void rateControlSync();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QUdpSocket _udpSocket { this };
|
QUdpSocket _udpSocket { this };
|
||||||
|
@ -71,7 +73,8 @@ private:
|
||||||
|
|
||||||
std::unordered_map<HifiSockAddr, SeqNum> _packetSequenceNumbers;
|
std::unordered_map<HifiSockAddr, SeqNum> _packetSequenceNumbers;
|
||||||
|
|
||||||
ControlSender* _controlSender { nullptr };
|
int32_t _synInterval;
|
||||||
|
QTimer _synTimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace udt
|
} // namespace udt
|
||||||
|
|
Loading…
Reference in a new issue