From 207f3a524818aeccd1d8d4e8259a685e06e296cb Mon Sep 17 00:00:00 2001 From: Aaron Bedra Date: Sat, 13 Jan 2024 12:57:50 -0600 Subject: [PATCH] Fix broken state --- simple_websocket.hpp | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/simple_websocket.hpp b/simple_websocket.hpp index 0afac91..45558ce 100644 --- a/simple_websocket.hpp +++ b/simple_websocket.hpp @@ -5,6 +5,7 @@ #include #include #include +#include namespace SimpleWebSocket { template @@ -287,6 +288,32 @@ namespace SimpleWebSocket { std::variant value_; }; + struct Workflow final { + explicit Workflow(std::function runFn, + std::function successFn, + std::function recoveryFn) + : runFn_(std::move(runFn)) + , successFn_(std::move(successFn)) + , recoveryFn_(std::move(recoveryFn)) + { } + + void runUntilCancelled() { + WorkflowResult workflowResult = runFn_(); + workflowResult.template match(recoveryFn_, successFn_); + + while (!workflowResult.complete()) { + workflowResult = runFn_(); + workflowResult.template match(recoveryFn_, successFn_); + } + } + + private: + const std::function runFn_; + const std::function successFn_; + const std::function recoveryFn_; + }; + + struct ExecutionContext final { ExecutionContext(std::string host, uint16_t port, std::string uri) : host_(std::move(host)), port_(port), uri_(std::move(uri)) {} @@ -316,7 +343,8 @@ namespace SimpleWebSocket { #include #include #include -#include +#include +#include namespace SimpleWebSocket::Poco { constexpr int PING_FRAME = static_cast(::Poco::Net::WebSocket::FRAME_FLAG_FIN) | @@ -384,10 +412,6 @@ namespace SimpleWebSocket::Poco { return Wrapper{::Poco::Net::WebSocket{session, request, response}}; } -#if __has_include() -#include -#include - template inline Wrapper tls_wrapper(const std::string& host, ::Poco::UInt16 port, @@ -399,6 +423,5 @@ namespace SimpleWebSocket::Poco { return Wrapper{::Poco::Net::WebSocket{session, request, response}}; } -#endif } #endif \ No newline at end of file