mirror of
https://github.com/overte-org/overte.git
synced 2025-08-11 01:23:17 +02:00
fixed PPS bugs in threaded version of PacketSender class
This commit is contained in:
parent
c6981d1912
commit
8baa863242
2 changed files with 9 additions and 4 deletions
|
@ -85,6 +85,7 @@ bool PacketSender::process() {
|
||||||
int packetsLeft = _packets.size();
|
int packetsLeft = _packets.size();
|
||||||
bool keepGoing = packetsLeft > 0;
|
bool keepGoing = packetsLeft > 0;
|
||||||
while (keepGoing) {
|
while (keepGoing) {
|
||||||
|
uint64_t SEND_INTERVAL_USECS = (_packetsPerSecond == 0) ? USECS_PER_SECOND : (USECS_PER_SECOND / _packetsPerSecond);
|
||||||
|
|
||||||
NetworkPacket& packet = _packets.front();
|
NetworkPacket& packet = _packets.front();
|
||||||
|
|
||||||
|
@ -110,11 +111,15 @@ bool PacketSender::process() {
|
||||||
|
|
||||||
// dynamically sleep until we need to fire off the next set of voxels we only sleep in threaded mode
|
// dynamically sleep until we need to fire off the next set of voxels we only sleep in threaded mode
|
||||||
if (keepGoing) {
|
if (keepGoing) {
|
||||||
|
now = usecTimestampNow();
|
||||||
uint64_t elapsed = now - _lastSendTime;
|
uint64_t elapsed = now - _lastSendTime;
|
||||||
int usecToSleep = std::max(SEND_INTERVAL_USECS, SEND_INTERVAL_USECS - elapsed);
|
int usecToSleep = SEND_INTERVAL_USECS - elapsed;
|
||||||
|
|
||||||
// we only sleep in non-threaded mode
|
// we only sleep in non-threaded mode
|
||||||
if (usecToSleep > 0) {
|
if (usecToSleep > 0) {
|
||||||
|
if (usecToSleep > SEND_INTERVAL_USECS) {
|
||||||
|
usecToSleep = SEND_INTERVAL_USECS;
|
||||||
|
}
|
||||||
usleep(usecToSleep);
|
usleep(usecToSleep);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ public:
|
||||||
/// \thread any thread, typically the application thread
|
/// \thread any thread, typically the application thread
|
||||||
void queuePacketForSending(sockaddr& address, unsigned char* packetData, ssize_t packetLength);
|
void queuePacketForSending(sockaddr& address, unsigned char* packetData, ssize_t packetLength);
|
||||||
|
|
||||||
void setPacketsPerSecond(int packetsPerSecond) { _packetsPerSecond = std::min(MINIMUM_PACKETS_PER_SECOND, packetsPerSecond); }
|
void setPacketsPerSecond(int packetsPerSecond) { _packetsPerSecond = std::max(MINIMUM_PACKETS_PER_SECOND, packetsPerSecond); }
|
||||||
int getPacketsPerSecond() const { return _packetsPerSecond; }
|
int getPacketsPerSecond() const { return _packetsPerSecond; }
|
||||||
|
|
||||||
void setPacketSenderNotify(PacketSenderNotify* notify) { _notify = notify; }
|
void setPacketSenderNotify(PacketSenderNotify* notify) { _notify = notify; }
|
||||||
|
|
Loading…
Reference in a new issue