summaryrefslogtreecommitdiffstats
path: root/source/core
diff options
context:
space:
mode:
Diffstat (limited to 'source/core')
-rw-r--r--source/core/slang-http.cpp24
-rw-r--r--source/core/slang-http.h5
-rw-r--r--source/core/slang-writer.h1
3 files changed, 27 insertions, 3 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.
diff --git a/source/core/slang-http.h b/source/core/slang-http.h
index a298e9e27..784357273 100644
--- a/source/core/slang-http.h
+++ b/source/core/slang-http.h
@@ -123,8 +123,9 @@ public:
/// Write. Will potentially block if write stream is blocking.
SlangResult write(const void* content, size_t sizeInBytes);
- /// Blocks until some result - a packet, closure, or some kind of error
- SlangResult waitForResult();
+ /// Blocks until some result - a packet, closure, or some kind of error or timeout.
+ /// TimeOut of -1 means no timeout.
+ SlangResult waitForResult(Int timeOutInMs = -1);
/// Consume the content - so can read next content
void consumeContent();
diff --git a/source/core/slang-writer.h b/source/core/slang-writer.h
index 380823b39..7c768a22f 100644
--- a/source/core/slang-writer.h
+++ b/source/core/slang-writer.h
@@ -148,6 +148,7 @@ public:
Parent(flags),
m_builder(builder)
{}
+ ~StringWriter() {}
protected:
StringBuilder* m_builder;