Merge pull request #2503 from birarda/master

increase NodeList send buffer size to 1MB
This commit is contained in:
Philip Rosedale 2014-03-26 12:00:43 -07:00
commit 020f4b020e
4 changed files with 37 additions and 7 deletions

View file

@ -32,6 +32,7 @@ const unsigned int AVATAR_DATA_SEND_INTERVAL_MSECS = (1.0f / 60.0f) * 1000;
AvatarMixer::AvatarMixer(const QByteArray& packet) :
ThreadedAssignment(packet),
_broadcastThread(),
_lastFrameTimestamp(QDateTime::currentMSecsSinceEpoch()),
_trailingSleepRatio(1.0f),
_performanceThrottlingRatio(0.0f),
@ -44,6 +45,11 @@ AvatarMixer::AvatarMixer(const QByteArray& packet) :
connect(NodeList::getInstance(), &NodeList::nodeKilled, this, &AvatarMixer::nodeKilled);
}
AvatarMixer::~AvatarMixer() {
_broadcastThread.quit();
_broadcastThread.wait();
}
void attachAvatarDataToNode(Node* newNode) {
if (!newNode->getLinkedData()) {
newNode->setLinkedData(new AvatarMixerClientData());
@ -309,18 +315,15 @@ void AvatarMixer::run() {
nodeList->linkedDataCreateCallback = attachAvatarDataToNode;
// create a thead for broadcast of avatar data
QThread* broadcastThread = new QThread(this);
// setup the timer that will be fired on the broadcast thread
QTimer* broadcastTimer = new QTimer();
broadcastTimer->setInterval(AVATAR_DATA_SEND_INTERVAL_MSECS);
broadcastTimer->moveToThread(broadcastThread);
broadcastTimer->moveToThread(&_broadcastThread);
// connect appropriate signals and slots
connect(broadcastTimer, &QTimer::timeout, this, &AvatarMixer::broadcastAvatarData, Qt::DirectConnection);
connect(broadcastThread, SIGNAL(started()), broadcastTimer, SLOT(start()));
connect(&_broadcastThread, SIGNAL(started()), broadcastTimer, SLOT(start()));
// start the broadcastThread
broadcastThread->start();
_broadcastThread.start();
}

View file

@ -15,7 +15,7 @@
class AvatarMixer : public ThreadedAssignment {
public:
AvatarMixer(const QByteArray& packet);
~AvatarMixer();
public slots:
/// runs the avatar mixer
void run();
@ -30,6 +30,8 @@ public slots:
private:
void broadcastAvatarData();
QThread _broadcastThread;
quint64 _lastFrameTimestamp;
float _trailingSleepRatio;

View file

@ -86,6 +86,29 @@ NodeList::NodeList(char newOwnerType, unsigned short int newSocketListenPort) :
_packetStatTimer.start();
}
void NodeList::changeSendSocketBufferSize(int numSendBytes) {
// 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
getsockopt(_nodeSocket.socketDescriptor(), SOL_SOCKET, SO_SNDBUF, reinterpret_cast<char*>(&oldBufferSize), &sizeOfInt);
const int LARGER_SNDBUF_SIZE = 1048576;
setsockopt(_nodeSocket.socketDescriptor(), SOL_SOCKET, SO_SNDBUF, reinterpret_cast<const char*>(&LARGER_SNDBUF_SIZE),
sizeof(LARGER_SNDBUF_SIZE));
int newBufferSize = 0;
getsockopt(_nodeSocket.socketDescriptor(), SOL_SOCKET, SO_SNDBUF, reinterpret_cast<char*>(&newBufferSize), &sizeOfInt);
qDebug() << "Changed socket send buffer size from" << oldBufferSize << "to" << newBufferSize << "bytes";
}
bool NodeList::packetVersionAndHashMatch(const QByteArray& packet) {
PacketType checkType = packetTypeForPacket(packet);
if (packet[1] != versionForPacketType(checkType)

View file

@ -160,6 +160,8 @@ private:
void requestAuthForDomainServer();
void activateSocketFromNodeCommunication(const QByteArray& packet, const SharedNodePointer& sendingNode);
void timePingReply(const QByteArray& packet, const SharedNodePointer& sendingNode);
void changeSendSocketBufferSize(int numSendBytes);
NodeHash _nodeHash;
QMutex _nodeHashMutex;