Merge pull request #5809 from birarda/phrc

timing fixes for default time_point on windows
This commit is contained in:
Ryan Huffman 2015-09-15 15:29:30 -07:00
commit 8c3d8bc7de
8 changed files with 26 additions and 34 deletions

View file

@ -34,7 +34,6 @@ void CongestionControl::setPacketSendPeriod(double newSendPeriod) {
}
DefaultCC::DefaultCC() :
_lastRCTime(p_high_resolution_clock::now()),
_slowStartLastAck(_sendCurrSeqNum),
_lastDecreaseMaxSeq(SequenceNumber {SequenceNumber::MAX })
{

View file

@ -108,7 +108,8 @@ public:
private:
void stopSlowStart(); // stops the slow start on loss or timeout
p_high_resolution_clock::time_point _lastRCTime; // last rate increase time
p_high_resolution_clock::time_point _lastRCTime = p_high_resolution_clock::now(); // last rate increase time
bool _slowStart { true }; // if in slow start phase
SequenceNumber _slowStartLastAck; // last ACKed seq num
bool _loss { false }; // if loss happened since last rate increase

View file

@ -28,7 +28,6 @@ using namespace udt;
using namespace std::chrono;
Connection::Connection(Socket* parentSocket, HifiSockAddr destination, std::unique_ptr<CongestionControl> congestionControl) :
_connectionStart(p_high_resolution_clock::now()),
_parentSocket(parentSocket),
_destination(destination),
_congestionControl(move(congestionControl))
@ -278,11 +277,11 @@ void Connection::sendACK(bool wasCausedBySyncTimeout) {
// pack in the receive speed and estimatedBandwidth
ackPacket->writePrimitive(packetReceiveSpeed);
ackPacket->writePrimitive(estimatedBandwidth);
// record this as the last ACK send time
lastACKSendTime = p_high_resolution_clock::now();
}
// record this as the last ACK send time
lastACKSendTime = p_high_resolution_clock::now();
// have the socket send off our packet
_parentSocket->writeBasePacket(*ackPacket, _destination);
@ -534,7 +533,8 @@ void Connection::processACK(std::unique_ptr<ControlPacket> controlPacket) {
// This will be the case if it has been longer than the sync interval OR
// it looks like they haven't received our ACK2 for this ACK
auto currentTime = p_high_resolution_clock::now();
static p_high_resolution_clock::time_point lastACK2SendTime;
static p_high_resolution_clock::time_point lastACK2SendTime =
p_high_resolution_clock::now() - std::chrono::microseconds(_synInterval);
microseconds sinceLastACK2 = duration_cast<microseconds>(currentTime - lastACK2SendTime);
@ -779,7 +779,7 @@ void Connection::resetReceiveState() {
// clear the loss list and _lastNAKTime
_lossList.clear();
_lastNAKTime = p_high_resolution_clock::time_point();
_lastNAKTime = p_high_resolution_clock::now();
// the _nakInterval need not be reset, that will happen on loss

View file

@ -114,13 +114,14 @@ private:
int _nakInterval { -1 }; // NAK timeout interval, in microseconds, set on loss
int _minNAKInterval { 100000 }; // NAK timeout interval lower bound, default of 100ms
p_high_resolution_clock::time_point _lastNAKTime;
p_high_resolution_clock::time_point _lastNAKTime = p_high_resolution_clock::now();
bool _hasReceivedHandshake { false }; // flag for receipt of handshake from server
bool _hasReceivedHandshakeACK { false }; // flag for receipt of handshake ACK from client
p_high_resolution_clock::time_point _connectionStart; // holds the time_point for creation of this connection
p_high_resolution_clock::time_point _connectionStart = p_high_resolution_clock::now(); // holds the time_point for creation of this connection
p_high_resolution_clock::time_point _lastReceiveTime; // holds the last time we received anything from sender
bool _isReceivingData { false }; // flag used for expiry of receipt portion of connection
LossList _lossList; // List of all missing packets

View file

@ -93,15 +93,16 @@ int32_t PacketTimeWindow::getEstimatedBandwidth() const {
}
void PacketTimeWindow::onPacketArrival() {
// take the current time
auto now = p_high_resolution_clock::now();
// record the interval between this packet and the last one
_packetIntervals[_currentPacketInterval++] = duration_cast<microseconds>(now - _lastPacketTime).count();
// reset the currentPacketInterval index when it wraps
if (_currentPacketInterval == _numPacketIntervals) {
_currentPacketInterval = 0;
if (_packetIntervals.size() > 0) {
// record the interval between this packet and the last one
_packetIntervals[_currentPacketInterval++] = duration_cast<microseconds>(now - _lastPacketTime).count();
// reset the currentPacketInterval index when it wraps
_currentPacketInterval %= _numPacketIntervals;
}
// remember this as the last packet arrival time
@ -120,7 +121,5 @@ void PacketTimeWindow::onProbePair2Arrival() {
_probeIntervals[_currentProbeInterval++] = duration_cast<microseconds>(now - _firstProbeTime).count();
// reset the currentProbeInterval index when it wraps
if (_currentProbeInterval == _numProbeIntervals) {
_currentProbeInterval = 0;
}
_currentProbeInterval %= _numProbeIntervals;
}

View file

@ -42,8 +42,8 @@ private:
std::vector<int> _packetIntervals; // vector of microsecond intervals between packet arrivals
std::vector<int> _probeIntervals; // vector of microsecond intervals between probe pair arrivals
p_high_resolution_clock::time_point _lastPacketTime; // the time_point when last packet arrived
p_high_resolution_clock::time_point _firstProbeTime; // the time_point when first probe in pair arrived
p_high_resolution_clock::time_point _lastPacketTime = p_high_resolution_clock::now(); // the time_point when last packet arrived
p_high_resolution_clock::time_point _firstProbeTime = p_high_resolution_clock::now(); // the time_point when first probe in pair arrived
};
}

View file

@ -279,17 +279,13 @@ void SendQueue::run() {
if (!_hasReceivedHandshakeACK) {
// we haven't received a handshake ACK from the client
// if it has been at least 100ms since we last sent a handshake, send another now
// hold the time of last send in a static
static auto lastSendHandshake = p_high_resolution_clock::time_point();
static const auto HANDSHAKE_RESEND_INTERVAL_MS = std::chrono::milliseconds(100);
// calculation the duration since the last handshake send
auto sinceLastHandshake = std::chrono::duration_cast<std::chrono::milliseconds>(p_high_resolution_clock::now()
- lastSendHandshake);
// hold the time of last send in a static
static auto lastSendHandshake = p_high_resolution_clock::now() - HANDSHAKE_RESEND_INTERVAL_MS;
if (sinceLastHandshake >= HANDSHAKE_RESEND_INTERVAL_MS) {
if (p_high_resolution_clock::now() - lastSendHandshake >= HANDSHAKE_RESEND_INTERVAL_MS) {
// it has been long enough since last handshake, send another
static auto handshakePacket = ControlPacket::create(ControlPacket::Handshake, 0);
@ -299,9 +295,7 @@ void SendQueue::run() {
}
// we wait for the ACK or the re-send interval to expire
_handshakeACKCondition.wait_until(handshakeLock,
p_high_resolution_clock::now()
+ HANDSHAKE_RESEND_INTERVAL_MS);
_handshakeACKCondition.wait_until(handshakeLock, p_high_resolution_clock::now() + HANDSHAKE_RESEND_INTERVAL_MS);
// Once we're here we've either received the handshake ACK or it's going to be time to re-send a handshake.
// Either way let's continue processing - no packets will be sent if no handshake ACK has been received.

View file

@ -45,8 +45,6 @@ class SendQueue : public QObject {
Q_OBJECT
public:
using time_point = p_high_resolution_clock::time_point;
static std::unique_ptr<SendQueue> create(Socket* socket, HifiSockAddr destination);
void queuePacket(std::unique_ptr<Packet> packet);