[*] Bug fixes. Socket stat math didn't make much sense.

This commit is contained in:
Reece Wilson 2021-11-07 20:17:02 +00:00
parent 3a62400ac1
commit f6b254e436
2 changed files with 9 additions and 5 deletions

View File

@ -13,7 +13,8 @@ namespace Aurora::IO::Net
{ {
inline AuUInt32 GetBytesPerMS(AuUInt32 timeNow) inline AuUInt32 GetBytesPerMS(AuUInt32 timeNow)
{ {
return (double(bytesTransferred) / (double(frameStart - timeNow) + std::numeric_limits<double>::epsilon())); if (!frameLastEnd) return bytesTransferred;
return (double(bytesTransferred) / (double(timeNow - frameLastEnd) + std::numeric_limits<double>::epsilon()));
} }
inline AuUInt32 GetBytesPerSecondNormalized(AuUInt32 timeNow) inline AuUInt32 GetBytesPerSecondNormalized(AuUInt32 timeNow)
@ -27,10 +28,10 @@ namespace Aurora::IO::Net
// Some useful variables... // Some useful variables...
auto frameAtPoint = GetBytesPerMS(timeNow); auto frameAtPoint = GetBytesPerMS(timeNow);
auto timeElapsed = frameStart - timeNow; auto timeElapsed = timeNow - frameLastEnd; // time elapsed since last packet dispatch finish. makes sense to use this is the packet delta of a high bandwidth stream
// Edge case: we aren't receiving much data. if we have more than 1 second of data, we should just average it // Edge case: we aren't receiving much data. if we have more than 1 second of data, we should use the stream average
if (timeElapsed > 1000) return frameAtPoint / 1000; // from ms if (timeElapsed > 1000) return frameAtPoint * 1000; // from ms
// else assume constant usage will continue to trend for at least another second // else assume constant usage will continue to trend for at least another second
// the actual extrapolation // the actual extrapolation
auto weight = double(1000) / double(timeElapsed); auto weight = double(1000) / double(timeElapsed);
@ -40,7 +41,7 @@ namespace Aurora::IO::Net
inline AuUInt32 GetLastBytesPerSecond() inline AuUInt32 GetLastBytesPerSecond()
{ {
AU_LOCK_GUARD(lock); AU_LOCK_GUARD(lock);
return (double(lastBytesTransferred) / (double(frameLastEnd - frameLastStart) + std::numeric_limits<double>::epsilon())) / 1000; return double(lastBytesTransferred) / (double(frameLastEnd - frameLastStart) + std::numeric_limits<double>::epsilon()) * 1000.f;
} }
inline void Reset() inline void Reset()
@ -49,6 +50,7 @@ namespace Aurora::IO::Net
frameStart = 0; frameStart = 0;
frameLastEnd = 0; frameLastEnd = 0;
frameLastStart = 0; frameLastStart = 0;
frameZero = true;
lastBytesTransferred = 0; lastBytesTransferred = 0;
} }

View File

@ -180,5 +180,7 @@ namespace Aurora::Locale::Encoding::UTF32
return 5; return 5;
else if (cp < 0x80000000) else if (cp < 0x80000000)
return 6; return 6;
else
return 0;
} }
} }