Scale back on first dropped packet, use Qt send/receive buffer size options

rather than setsockopt/getsockopt.
This commit is contained in:
Andrzej Kapolka 2014-12-30 12:30:38 -08:00
parent 0914101b3e
commit c9b3b5ff7d
2 changed files with 14 additions and 21 deletions

View file

@ -353,7 +353,7 @@ void DatagramSequencer::sendRecordLost(const SendRecord& record) {
if (_packetDropCount == 0 || record.packetNumber == _lastPacketDropped + 1) {
_packetDropCount++;
_lastPacketDropped = record.packetNumber;
const int CONSECUTIVE_DROPS_BEFORE_REDUCTION = 3;
const int CONSECUTIVE_DROPS_BEFORE_REDUCTION = 1;
if (_packetDropCount >= CONSECUTIVE_DROPS_BEFORE_REDUCTION && record.packetNumber >= _packetRateDecreasePacketNumber) {
_packetsPerGroup = qMax(_packetsPerGroup * 0.5f, 1.0f);
_slowStartThreshold = _packetsPerGroup;

View file

@ -147,28 +147,21 @@ QUdpSocket& LimitedNodeList::getDTLSSocket() {
}
void LimitedNodeList::changeSocketBufferSizes(int numBytes) {
// change the socket send buffer size to be 1MB
int oldBufferSize = 0;
#ifdef Q_OS_WIN
int sizeOfInt = sizeof(oldBufferSize);
#else
unsigned int sizeOfInt = sizeof(oldBufferSize);
#endif
for (int i = 0; i < 2; i++) {
int bufferOpt = (i == 0) ? SO_SNDBUF : SO_RCVBUF;
getsockopt(_nodeSocket.socketDescriptor(), SOL_SOCKET, bufferOpt, reinterpret_cast<char*>(&oldBufferSize), &sizeOfInt);
setsockopt(_nodeSocket.socketDescriptor(), SOL_SOCKET, bufferOpt, reinterpret_cast<const char*>(&numBytes),
sizeof(numBytes));
QString bufferTypeString = (i == 0) ? "send" : "receive";
QAbstractSocket::SocketOption bufferOpt;
QString bufferTypeString;
if (i == 0) {
bufferOpt = QAbstractSocket::SendBufferSizeSocketOption;
bufferTypeString = "send";
} else {
bufferOpt = QAbstractSocket::ReceiveBufferSizeSocketOption;
bufferTypeString = "receive";
}
int oldBufferSize = _nodeSocket.socketOption(bufferOpt).toInt();
if (oldBufferSize < numBytes) {
int newBufferSize = 0;
getsockopt(_nodeSocket.socketDescriptor(), SOL_SOCKET, bufferOpt, reinterpret_cast<char*>(&newBufferSize), &sizeOfInt);
_nodeSocket.setSocketOption(bufferOpt, numBytes);
int newBufferSize = _nodeSocket.socketOption(bufferOpt).toInt();
qDebug() << "Changed socket" << bufferTypeString << "buffer size from" << oldBufferSize << "to"
<< newBufferSize << "bytes";