don't require a sendQueue for control packet sending

This commit is contained in:
Stephen Birarda 2015-07-31 09:56:50 -07:00
parent f2ab2fb08a
commit 98a53cbd72
6 changed files with 30 additions and 18 deletions

View file

@ -30,6 +30,8 @@ Connection::Connection(Socket* parentSocket, HifiSockAddr destination, unique_pt
_destination(destination),
_congestionControl(move(congestionControl))
{
Q_ASSERT_X(socket, "Connection::Connection", "Must be called with a valid Socket*");
// setup default SYN, RTT and RTT Variance based on the SYN interval in CongestionControl object
_synInterval = _congestionControl->synInterval();
_rtt = _synInterval * 10;
@ -132,8 +134,8 @@ void Connection::sendACK(bool wasCausedBySyncTimeout) {
lastACKSendTime = high_resolution_clock::now();
}
// have the send queue send off our packet
_sendQueue->sendPacket(*ackPacket);
// have the socket send off our packet
_parentSocket->writeBasePacket(*ackPacket, _destination);
// write this ACK to the map of sent ACKs
_sentACKs[_currentACKSubSequenceNumber] = { nextACKNumber, currentTime };
@ -162,8 +164,8 @@ void Connection::sendLightACK() {
// pack in the ACK
lightACKPacket->writePrimitive(nextACKNumber);
// have the send queue send off our packet immediately
_sendQueue->sendPacket(*lightACKPacket);
// have the socket send off our packet immediately
_parentSocket->writeBasePacket(*lightACKPacket, _destination);
_stats.recordSentLightACK();
}
@ -197,8 +199,8 @@ void Connection::sendNAK(SequenceNumber sequenceNumberRecieved) {
lossReport->writePrimitive(sequenceNumberRecieved - 1);
}
// have the send queue send off our packet immediately
_sendQueue->sendPacket(*lossReport);
// have the parent socket send off our packet immediately
_parentSocket->writeBasePacket(*lossReport, _destination);
// record our last NAK time
_lastNAKTime = high_resolution_clock::now();
@ -215,8 +217,8 @@ void Connection::sendTimeoutNAK() {
// Pack in the lost sequence numbers
_lossList.write(*lossListPacket);
// have our SendQueue send off this control packet
_sendQueue->sendPacket(*lossListPacket);
// have our parent socket send off this control packet
_parentSocket->writeBasePacket(*lossListPacket, _destination);
// record this as the last NAK time
_lastNAKTime = high_resolution_clock::now();

View file

@ -98,11 +98,11 @@ private:
HifiSockAddr _destination;
PacketTimeWindow _receiveWindow { 16, 64 }; // Window of interval between packets (16) and probes (64) for bandwidth and receive speed
std::unique_ptr<SendQueue> _sendQueue;
std::unique_ptr<CongestionControl> _congestionControl;
std::unique_ptr<SendQueue> _sendQueue;
// Data packet stat collection
int _totalReceivedDataPackets { 0 };
int _packetsSinceACK { 0 }; // The number of packets that have been received during the current ACK interval

View file

@ -28,6 +28,8 @@ using namespace std::chrono;
std::unique_ptr<SendQueue> SendQueue::create(Socket* socket, HifiSockAddr dest) {
auto queue = std::unique_ptr<SendQueue>(new SendQueue(socket, dest));
Q_ASSERT_X(socket, "SendQueue::create", "Must be called with a valid Socket*");
// Setup queue private thread
QThread* thread = new QThread();
thread->setObjectName("Networking: SendQueue " + dest.objectName()); // Name thread for easier debug
@ -65,10 +67,8 @@ void SendQueue::stop() {
_isRunning = false;
}
void SendQueue::sendPacket(const BasePacket& packet) {
if (_socket) {
_socket->writeDatagram(packet.getData(), packet.getDataSize(), _destination);
}
void SendQueue::sendPacket(const Packet& packet) {
_socket->writeDatagram(packet.getData(), packet.getDataSize(), _destination);
}
void SendQueue::ack(SequenceNumber ack) {

View file

@ -49,9 +49,6 @@ public:
int getPacketSendPeriod() const { return _packetSendPeriod; }
void setPacketSendPeriod(int newPeriod) { _packetSendPeriod = newPeriod; }
// Send a packet through the socket
void sendPacket(const BasePacket& packet);
public slots:
void stop();
@ -70,6 +67,8 @@ private:
SendQueue(SendQueue& other) = delete;
SendQueue(SendQueue&& other) = delete;
void sendPacket(const Packet& packet);
// Increments current sequence number and return it
SequenceNumber getNextSequenceNumber();

View file

@ -74,6 +74,16 @@ void Socket::setSystemBufferSizes() {
}
}
qint64 Socket::writeBasePacket(const udt::BasePacket& packet, const HifiSockAddr &sockAddr) {
// Since this is a base packet we have no way to know if this is reliable or not - we just fire it off
// this should not be called with an instance of Packet
Q_ASSERT_X(!dynamic_cast<const Packet*>(&packet),
"Socket::writeBasePacket", "Cannot send a Packet/NLPacket via writeBasePacket");
return writeDatagram(packet.getData(), packet.getDataSize(), sockAddr);
}
qint64 Socket::writePacket(const Packet& packet, const HifiSockAddr& sockAddr) {
Q_ASSERT_X(!packet.isReliable(), "Socket::writePacket", "Cannot send a reliable packet unreliably");

View file

@ -45,6 +45,7 @@ public:
quint16 localPort() const { return _udpSocket.localPort(); }
// Simple functions writing to the socket with no processing
qint64 writeBasePacket(const BasePacket& packet, const HifiSockAddr& sockAddr);
qint64 writePacket(const Packet& packet, const HifiSockAddr& sockAddr);
qint64 writePacket(std::unique_ptr<Packet> packet, const HifiSockAddr& sockAddr);
qint64 writeDatagram(const char* data, qint64 size, const HifiSockAddr& sockAddr);