From 4e77afb4b25e95b359b3bb0a12c4f7aa9914f3d5 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 25 Mar 2014 13:38:02 -0700 Subject: [PATCH] block and wait for bytes to be written during broadcastAvatarData loop --- assignment-client/src/avatars/AvatarMixer.cpp | 6 ++---- libraries/shared/src/NodeList.cpp | 8 +------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/assignment-client/src/avatars/AvatarMixer.cpp b/assignment-client/src/avatars/AvatarMixer.cpp index 65e0acd4a6..5eb3e54389 100644 --- a/assignment-client/src/avatars/AvatarMixer.cpp +++ b/assignment-client/src/avatars/AvatarMixer.cpp @@ -54,10 +54,6 @@ const float BILLBOARD_AND_IDENTITY_SEND_PROBABILITY = 1.0f / 300.0f; // NOTE: some additional optimizations to consider. // 1) use the view frustum to cull those avatars that are out of view. Since avatar data doesn't need to be present // if the avatar is not in view or in the keyhole. -// 2) after culling for view frustum, sort order the avatars by distance, send the closest ones first. -// 3) if we need to rate limit the amount of data we send, we can use a distance weighted "semi-random" function to -// determine which avatars are included in the packet stream -// 4) we should optimize the avatar data format to be more compact (100 bytes is pretty wasteful). void AvatarMixer::broadcastAvatarData() { static QByteArray mixedAvatarByteArray; @@ -139,6 +135,8 @@ void AvatarMixer::broadcastAvatarData() { ++_sumIdentityPackets; } + + nodeList->getNodeSocket().waitForBytesWritten(-1); } } } diff --git a/libraries/shared/src/NodeList.cpp b/libraries/shared/src/NodeList.cpp index 0cc343b460..cda2963f53 100644 --- a/libraries/shared/src/NodeList.cpp +++ b/libraries/shared/src/NodeList.cpp @@ -171,13 +171,7 @@ qint64 NodeList::writeDatagram(const QByteArray& datagram, const HifiSockAddr& d ++_numCollectedPackets; _numCollectedBytes += datagram.size(); - qint64 bytesWritten = _nodeSocket.writeDatagram(datagramCopy, - destinationSockAddr.getAddress(), - destinationSockAddr.getPort()); - - // ask the underlying QUdpSocket to flush its buffers to avoid filling them up - _nodeSocket.flush(); - return bytesWritten; + return _nodeSocket.writeDatagram(datagramCopy, destinationSockAddr.getAddress(), destinationSockAddr.getPort()); }