summaryrefslogtreecommitdiffstats
path: root/source/core/slang-http.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2021-11-30 16:34:52 -0500
committerGitHub <noreply@github.com>2021-11-30 16:34:52 -0500
commitace4e334bc5fb299d2890b5e3f35dfd84ea32606 (patch)
tree9a18aa01dda4c8e8b7305bddfd7009fdb8e11a95 /source/core/slang-http.cpp
parentdd18f2bff2abd13548742e30c25a31b9ea9a0cbd (diff)
Use test-server on CI (#2034)
* #include an absolute path didn't work - because paths were taken to always be relative. * Vary what SpawnType is used, if one isn't explicitly set. * Terminate on linux if exec fails. * Use a more sophisticated sleeping mechanism. * Attempt to make CI tests to work on aarch64 debug. Small fixes.
Diffstat (limited to 'source/core/slang-http.cpp')
-rw-r--r--source/core/slang-http.cpp49
1 files changed, 47 insertions, 2 deletions
diff --git a/source/core/slang-http.cpp b/source/core/slang-http.cpp
index 6a4bb4f92..bb5994635 100644
--- a/source/core/slang-http.cpp
+++ b/source/core/slang-http.cpp
@@ -287,6 +287,46 @@ SlangResult HTTPPacketConnection::update()
return m_readResult;
}
+
+namespace { // anonymous
+
+// Handles binary backoff like sleeping mechanism.
+struct SleepState
+{
+ void sleep()
+ {
+ Process::sleepCurrentThread(m_intervalInMs);
+ _update();
+ }
+ void reset()
+ {
+ m_intervalInMs = 0;
+ m_count = 0;
+ }
+ void _update()
+ {
+ const Int maxIntervalInMs = 32;
+ const Int initialCountThreshold = 4;
+
+ ++m_count;
+
+ const Int countThreshold = (m_intervalInMs == 0) ? initialCountThreshold : 1;
+
+ // If we hit the count change the interval
+ if (m_count >= countThreshold)
+ {
+ m_intervalInMs = (m_intervalInMs == 0) ? 1 : Math::Min(m_intervalInMs * 2, maxIntervalInMs);
+ // Reset the count
+ m_count = 0;
+ }
+ }
+
+ Int m_intervalInMs = 0;
+ Int m_count = 0;
+};
+
+} // anonymous
+
SlangResult HTTPPacketConnection::waitForResult(Int timeOutInMs)
{
m_readResult = SLANG_OK;
@@ -300,6 +340,8 @@ SlangResult HTTPPacketConnection::waitForResult(Int timeOutInMs)
startTick = Process::getClockTick();
}
+ SleepState sleepState;
+
while (m_readState == ReadState::Header ||
m_readState == ReadState::Content)
{
@@ -320,8 +362,11 @@ SlangResult HTTPPacketConnection::waitForResult(Int timeOutInMs)
if (prevCount == m_readStream->getCount())
{
- // Yield if it appears nothing was read.
- Process::sleepCurrentThread(0);
+ sleepState.sleep();
+ }
+ else
+ {
+ sleepState.reset();
}
}