diff options
Diffstat (limited to 'source/core/slang-http.cpp')
| -rw-r--r-- | source/core/slang-http.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/source/core/slang-http.cpp b/source/core/slang-http.cpp index 43be26c1c..6a4bb4f92 100644 --- a/source/core/slang-http.cpp +++ b/source/core/slang-http.cpp @@ -287,8 +287,19 @@ SlangResult HTTPPacketConnection::update() return m_readResult; } -SlangResult HTTPPacketConnection::waitForResult() +SlangResult HTTPPacketConnection::waitForResult(Int timeOutInMs) { + m_readResult = SLANG_OK; + + int64_t startTick = 0; + int64_t timeOutInTicks = -1; + + if (timeOutInMs >= 0) + { + timeOutInTicks = timeOutInMs * (Process::getClockFrequency() / 1000); + startTick = Process::getClockTick(); + } + while (m_readState == ReadState::Header || m_readState == ReadState::Content) { @@ -296,6 +307,17 @@ SlangResult HTTPPacketConnection::waitForResult() SLANG_RETURN_ON_FAIL(update()); + if (m_readState == ReadState::Done) + { + break; + } + + // We timed out + if (timeOutInTicks >= 0 && int64_t(Process::getClockTick()) - startTick >= timeOutInTicks) + { + break; + } + if (prevCount == m_readStream->getCount()) { // Yield if it appears nothing was read. |
