Skip to content

Commit

Permalink
Fix broken state
Browse files Browse the repository at this point in the history
  • Loading branch information
abedra committed Jan 13, 2024
1 parent aa67ab4 commit 207f3a5
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions simple_websocket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <vector>
#include <variant>
#include <memory>
#include <functional>

namespace SimpleWebSocket {
template<class... As>
Expand Down Expand Up @@ -287,6 +288,32 @@ namespace SimpleWebSocket {
std::variant<Failure, std::monostate> value_;
};

struct Workflow final {
explicit Workflow(std::function<WorkflowResult()> runFn,
std::function<void(const std::monostate &)> successFn,
std::function<void(const Failure &)> recoveryFn)
: runFn_(std::move(runFn))
, successFn_(std::move(successFn))
, recoveryFn_(std::move(recoveryFn))
{ }

void runUntilCancelled() {
WorkflowResult workflowResult = runFn_();
workflowResult.template match<void>(recoveryFn_, successFn_);

while (!workflowResult.complete()) {
workflowResult = runFn_();
workflowResult.template match<void>(recoveryFn_, successFn_);
}
}

private:
const std::function<WorkflowResult()> runFn_;
const std::function<void(const std::monostate &)> successFn_;
const std::function<void(const Failure &)> recoveryFn_;
};


struct ExecutionContext final {
ExecutionContext(std::string host, uint16_t port, std::string uri)
: host_(std::move(host)), port_(port), uri_(std::move(uri)) {}
Expand Down Expand Up @@ -316,7 +343,8 @@ namespace SimpleWebSocket {
#include <Poco/Net/HTTPClientSession.h>
#include <Poco/Net/HTTPRequest.h>
#include <Poco/Net/HTTPResponse.h>
#include <Poco/Net/WebSocket.h>
#include <Poco/Net/NetSSL.h>
#include <Poco/Net/HTTPSClientSession.h>

namespace SimpleWebSocket::Poco {
constexpr int PING_FRAME = static_cast<int>(::Poco::Net::WebSocket::FRAME_FLAG_FIN) |
Expand Down Expand Up @@ -384,10 +412,6 @@ namespace SimpleWebSocket::Poco {
return Wrapper<SIZE>{::Poco::Net::WebSocket{session, request, response}};
}

#if __has_include(<Poco/Net/SSLManager.h>)
#include <Poco/Net/SSLManager.h>
#include <Poco/Net/HTTPSClientSession.h>

template<int SIZE>
inline Wrapper<SIZE> tls_wrapper(const std::string& host,
::Poco::UInt16 port,
Expand All @@ -399,6 +423,5 @@ namespace SimpleWebSocket::Poco {

return Wrapper<SIZE>{::Poco::Net::WebSocket{session, request, response}};
}
#endif
}
#endif

0 comments on commit 207f3a5

Please sign in to comment.