don't change the socket buffer sizes if it is already larger

This commit is contained in:
Stephen Birarda 2014-08-14 10:36:54 -07:00
parent ec260dbab2
commit 64c11ebf8f

View file

@ -82,7 +82,7 @@ LimitedNodeList::LimitedNodeList(unsigned short socketListenPort, unsigned short
qDebug() << "NodeList DTLS socket is listening on" << _dtlsSocket->localPort();
}
const int LARGER_BUFFER_SIZE = 1048576;
const int LARGER_BUFFER_SIZE = 2097152;
changeSocketBufferSizes(LARGER_BUFFER_SIZE);
_packetStatTimer.start();
@ -147,12 +147,21 @@ void LimitedNodeList::changeSocketBufferSizes(int numBytes) {
setsockopt(_nodeSocket.socketDescriptor(), SOL_SOCKET, bufferOpt, reinterpret_cast<const char*>(&numBytes),
sizeof(numBytes));
int newBufferSize = 0;
getsockopt(_nodeSocket.socketDescriptor(), SOL_SOCKET, bufferOpt, reinterpret_cast<char*>(&newBufferSize), &sizeOfInt);
QString bufferTypeString = (i == 0) ? "send" : "receive";
qDebug() << "Changed socket" << bufferTypeString << "buffer size from" << oldBufferSize << "to" << newBufferSize << "bytes";
if (oldBufferSize < numBytes) {
int newBufferSize = 0;
getsockopt(_nodeSocket.socketDescriptor(), SOL_SOCKET, bufferOpt, reinterpret_cast<char*>(&newBufferSize), &sizeOfInt);
qDebug() << "Changed socket" << bufferTypeString << "buffer size from" << oldBufferSize << "to"
<< newBufferSize << "bytes";
} else {
// don't make the buffer smaller
qDebug() << "Did not change socket" << bufferTypeString << "buffer size from" << oldBufferSize
<< "since it is larger than desired size of" << numBytes;
}
}