Skip to content

Commit 207f3a5

Browse files
committed
Fix broken state
1 parent aa67ab4 commit 207f3a5

1 file changed

Lines changed: 29 additions & 6 deletions

File tree

simple_websocket.hpp

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <vector>
66
#include <variant>
77
#include <memory>
8+
#include <functional>
89

910
namespace SimpleWebSocket {
1011
template<class... As>
@@ -287,6 +288,32 @@ namespace SimpleWebSocket {
287288
std::variant<Failure, std::monostate> value_;
288289
};
289290

291+
struct Workflow final {
292+
explicit Workflow(std::function<WorkflowResult()> runFn,
293+
std::function<void(const std::monostate &)> successFn,
294+
std::function<void(const Failure &)> recoveryFn)
295+
: runFn_(std::move(runFn))
296+
, successFn_(std::move(successFn))
297+
, recoveryFn_(std::move(recoveryFn))
298+
{ }
299+
300+
void runUntilCancelled() {
301+
WorkflowResult workflowResult = runFn_();
302+
workflowResult.template match<void>(recoveryFn_, successFn_);
303+
304+
while (!workflowResult.complete()) {
305+
workflowResult = runFn_();
306+
workflowResult.template match<void>(recoveryFn_, successFn_);
307+
}
308+
}
309+
310+
private:
311+
const std::function<WorkflowResult()> runFn_;
312+
const std::function<void(const std::monostate &)> successFn_;
313+
const std::function<void(const Failure &)> recoveryFn_;
314+
};
315+
316+
290317
struct ExecutionContext final {
291318
ExecutionContext(std::string host, uint16_t port, std::string uri)
292319
: host_(std::move(host)), port_(port), uri_(std::move(uri)) {}
@@ -316,7 +343,8 @@ namespace SimpleWebSocket {
316343
#include <Poco/Net/HTTPClientSession.h>
317344
#include <Poco/Net/HTTPRequest.h>
318345
#include <Poco/Net/HTTPResponse.h>
319-
#include <Poco/Net/WebSocket.h>
346+
#include <Poco/Net/NetSSL.h>
347+
#include <Poco/Net/HTTPSClientSession.h>
320348

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

387-
#if __has_include(<Poco/Net/SSLManager.h>)
388-
#include <Poco/Net/SSLManager.h>
389-
#include <Poco/Net/HTTPSClientSession.h>
390-
391415
template<int SIZE>
392416
inline Wrapper<SIZE> tls_wrapper(const std::string& host,
393417
::Poco::UInt16 port,
@@ -399,6 +423,5 @@ namespace SimpleWebSocket::Poco {
399423

400424
return Wrapper<SIZE>{::Poco::Net::WebSocket{session, request, response}};
401425
}
402-
#endif
403426
}
404427
#endif

0 commit comments

Comments
 (0)