-
Notifications
You must be signed in to change notification settings - Fork 72
Add dynamic endpoints to WebsocketAdapter #378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
NeejWeej
wants to merge
11
commits into
main
Choose a base branch
from
nk/websocket_dynamic
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
fcea900
Add dynamic websockets support
NeejWeej d70dce8
Allow setting websockets to use binary
NeejWeej 5664f56
Include websocket tests by default
NeejWeej 628ceb6
Disable dynamic_cast optimization introduced in clang17
NeejWeej 639c5aa
Remove comments, more delay for test
NeejWeej 8ca822c
Use rapidjson to parse headers, no more dict
NeejWeej 02de663
Merge branch 'main' into nk/websocket_dynamic
NeejWeej d6f288c
Dont use tuple to processMessage
NeejWeej bd882f7
Merge branch 'main' into nk/websocket_dynamic
NeejWeej 956e439
Merge branch 'main' into nk/websocket_dynamic
NeejWeej 584de8a
Fix wrong function call for ioc from boost beast
NeejWeej File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
cpp/csp/adapters/websocket/ClientConnectionRequestAdapter.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| #include <csp/adapters/websocket/ClientConnectionRequestAdapter.h> | ||
|
|
||
| namespace csp::adapters::websocket { | ||
|
|
||
| ClientConnectionRequestAdapter::ClientConnectionRequestAdapter( | ||
| Engine * engine, | ||
| WebsocketEndpointManager * websocketManager, | ||
| bool is_subscribe, | ||
| size_t caller_id, | ||
| boost::asio::strand<boost::asio::io_context::executor_type>& strand | ||
|
|
||
| ) : OutputAdapter( engine ), | ||
| m_websocketManager( websocketManager ), | ||
| m_strand( strand ), | ||
| m_isSubscribe( is_subscribe ), | ||
| m_callerId( caller_id ), | ||
| m_checkPerformed( is_subscribe ? false : true ) // we only need to check for pruned input adapters | ||
| {} | ||
|
|
||
| void ClientConnectionRequestAdapter::executeImpl() | ||
| { | ||
| // One-time check for pruned status | ||
| if (unlikely(!m_checkPerformed)) { | ||
| m_isPruned = m_websocketManager->adapterPruned(m_callerId); | ||
| m_checkPerformed = true; | ||
| } | ||
|
|
||
| // Early return if pruned | ||
| if (unlikely(m_isPruned)) | ||
| return; | ||
|
|
||
| std::vector<Dictionary> properties_list; | ||
| for (auto& request : input()->lastValueTyped<std::vector<InternalConnectionRequest::Ptr>>()) { | ||
| if (!request->allFieldsSet()) | ||
| CSP_THROW(TypeError, "All fields must be set in InternalConnectionRequest"); | ||
|
|
||
| Dictionary dict; | ||
| dict.update("host", request->host()); | ||
| dict.update("port", request->port()); | ||
| dict.update("route", request->route()); | ||
| dict.update("uri", request->uri()); | ||
| dict.update("use_ssl", request->use_ssl()); | ||
| dict.update("reconnect_interval", request->reconnect_interval()); | ||
| dict.update("persistent", request->persistent()); | ||
|
|
||
| dict.update("headers", request -> headers() ); | ||
| dict.update("on_connect_payload", request->on_connect_payload()); | ||
| dict.update("action", request->action()); | ||
| dict.update("dynamic", request->dynamic()); | ||
| dict.update("binary", request->binary()); | ||
|
|
||
| properties_list.push_back(std::move(dict)); | ||
| } | ||
|
|
||
| // We intentionally post here, we want the thread running | ||
| // the strand to handle the connection request. We want to keep | ||
| // all updates to internal data structures at graph run-time | ||
| // to that thread. | ||
| boost::asio::post(m_strand, [this, properties_list=std::move(properties_list)]() { | ||
| for(const auto& conn_req: properties_list) { | ||
| m_websocketManager->handleConnectionRequest(conn_req, m_callerId, m_isSubscribe); | ||
| } | ||
| }); | ||
| }; | ||
|
|
||
| } |
45 changes: 45 additions & 0 deletions
45
cpp/csp/adapters/websocket/ClientConnectionRequestAdapter.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| #ifndef _IN_CSP_ADAPTERS_WEBSOCKETS_CLIENT_CONNECTIONREQUESTADAPTER_H | ||
| #define _IN_CSP_ADAPTERS_WEBSOCKETS_CLIENT_CONNECTIONREQUESTADAPTER_H | ||
|
|
||
| #include <csp/adapters/websocket/ClientAdapterManager.h> | ||
| #include <csp/engine/Dictionary.h> | ||
| #include <csp/engine/OutputAdapter.h> | ||
| #include <csp/adapters/utils/MessageWriter.h> | ||
| #include <csp/adapters/websocket/csp_autogen/websocket_types.h> | ||
|
|
||
| namespace csp::adapters::websocket | ||
| { | ||
| using namespace csp::autogen; | ||
|
|
||
| class ClientAdapterManager; | ||
| class WebsocketEndpointManager; | ||
|
|
||
| class ClientConnectionRequestAdapter final: public OutputAdapter | ||
| { | ||
| public: | ||
| ClientConnectionRequestAdapter( | ||
| Engine * engine, | ||
| WebsocketEndpointManager * websocketManager, | ||
| bool isSubscribe, | ||
| size_t callerId, | ||
| boost::asio::strand<boost::asio::io_context::executor_type>& strand | ||
| ); | ||
|
|
||
| void executeImpl() override; | ||
|
|
||
| const char * name() const override { return "WebsocketClientConnectionRequestAdapter"; } | ||
|
|
||
| private: | ||
| WebsocketEndpointManager* m_websocketManager; | ||
| boost::asio::strand<boost::asio::io_context::executor_type>& m_strand; | ||
| bool m_isSubscribe; | ||
| size_t m_callerId; | ||
| bool m_checkPerformed; | ||
| bool m_isPruned{false}; | ||
|
|
||
| }; | ||
|
|
||
| } | ||
|
|
||
|
|
||
| #endif |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.