summaryrefslogtreecommitdiffstats
path: root/source/core
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2021-11-23 16:23:15 -0500
committerGitHub <noreply@github.com>2021-11-23 16:23:15 -0500
commit9e084ffab37c276d40931a58633041a2e10de623 (patch)
treed85aa490968cdd3fe4bbcf305b593c6b86587685 /source/core
parentfd46034bf2de59b8ad51743e62b26359678432f7 (diff)
JSON-RPC test server (#2026)
* #include an absolute path didn't work - because paths were taken to always be relative. * Use 'Process' to communicate with an command line tool. * Remove slang-win-stream * Tidy up windows ProcessUtil. * First version of BufferedReadStream. * Windows working IPC for steams. * Test proxy count option. * Split Process/ProcessUtil. Process is platform dependant. ProcessUtil are functions that are platform independent. * First implementation of Unix Process interface. * Unix process compiles on cygwin. * Fix typo in unix process. * Separate unix pipe stream error of invalid access, from pipe availability. * Fix in standard line extraction. * Make fd non blocking. * Fix issues with Windows Process streams. * Added UnixPipe. * Some fixes around UnixPipeStream. * Make a unix stream closed explicit. * Hack to debug linux process/stream. * Revert to old linux pipe handling. * Pass executable path for unit tests. Split out CommandLine into own source. * Small improvements in process/command line. * Check process behavior with crash. * Make stderr and stdout unbuffered for crash testing. * Only turn disable buffering in crash test. * Disable crash test on CI. * Fix crash on clang/linux. * Enable crash test. Remove _appendBuffer as can use StreamUtil functionality. * Added inital processing for http headers. * Small improvements to HttpHeader. * First pass HTTPPacketConnection working on windows. * Enable other Process communication tests. * Update comments. * WIP JSON RPC. * Add terminate to Process. Made JSONRPC a Util. * Small tidy up around HTTPPacketConnection. * Improve process termination options. * WIP for test-server. * Add diagnostics error handling to test-server. * Improved JSON support. Parsing/creating JSON-RPC messages. * WIP JSONRPC parsing. * First pass RttiInfo support. * WIP converting between JSON/native types. * Project files. * Split out RttiUtil. Made RttiInfo constuction thread safe. * WIP RTTI<->JSON. * Add diagnostics to JSON<->native conversions. * Make RttiInfo for structs globals. Avoids problem around derived types (like pointers), being able to cause an abort. * Add pointer support to RTTI. Fixed some compilation issues on linux. * Add fixed array support. * Added Rtti unit test. * Add rtti unit test. * Split out quoted/unquoted key handling. Fix bugs in JSON value/container. Added JSON native test. * Make default array allocator use malloc/free. Remove the new[] handler (doesn't work on visuals studio). * Fix for linux warning. * Remove some test code. * Fix issues on x86 win. * Fix warning on aarch64. * Fix some bugs in JSON parsing/handling. Make Rtti work copy/dtor/ctor struct types. * Testing JSON<->native with fixed array. Make makeArrayView explicit if it's just a single value. Added array type. * Fix getting arrayView. * Improve JSON diagnostic name. * First pass refactor using Rtti for JSON RPC. * First pass of test server using RTTI/JSON-RPC. * Added JSONRPCConnection. * Fix some naming issues. * First pass of test-server working. * Added unit test support for JSON-RPC test server. * Fix compilation issues on linux around template handling. * Typo fix. * Fix a bug around SourceLoc lookup with JSONContainer. * Set the console type to console for ISlangWriters. * Small improvements to test-server. * Small improvements in test-server. * Small fix.
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;