-
Notifications
You must be signed in to change notification settings - Fork 66
fix: Add sending queue to ng web server #2273
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
Open
kuznetsss
wants to merge
11
commits into
XRPLF:develop
Choose a base branch
from
kuznetsss:Rewrite_ng_ws_connection
base: develop
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.
+402
−86
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
197a356
Add sending queue for http connection
kuznetsss 9a1d1d7
Add sending queue to WsConnection
kuznetsss 1bc6a1d
Merge branch 'develop' into Rewrite_ng_ws_connection
kuznetsss c46cccb
Fix review comments
kuznetsss daefb6d
Merge branch 'develop' into Rewrite_ng_ws_connection
kuznetsss df844e3
Remove commented code. Add assertion in destructor
kuznetsss e88c5a5
Merge branch 'develop' into Rewrite_ng_ws_connection
kuznetsss 23c87cf
Fix tests
kuznetsss ab51b65
Fix review issues
kuznetsss 24e17bc
Merge branch 'develop' into Rewrite_ng_ws_connection
kuznetsss 264e01a
Use correct nolint comment
kuznetsss 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
//------------------------------------------------------------------------------ | ||
/* | ||
This file is part of clio: https://github.com/XRPLF/clio | ||
Copyright (c) 2025, the clio developers. | ||
|
||
Permission to use, copy, modify, and distribute this software for any | ||
purpose with or without fee is hereby granted, provided that the above | ||
copyright notice and this permission notice appear in all copies. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*/ | ||
//============================================================================== | ||
|
||
#pragma once | ||
|
||
#include "web/ng/Error.hpp" | ||
|
||
#include <boost/asio/any_io_executor.hpp> | ||
#include <boost/asio/spawn.hpp> | ||
#include <boost/system/detail/error_code.hpp> | ||
|
||
#include <functional> | ||
#include <optional> | ||
#include <queue> | ||
|
||
namespace web::ng::impl { | ||
|
||
template <typename T> | ||
class SendingQueue { | ||
public: | ||
using Sender = std::function<void(T const&, boost::asio::basic_yield_context<boost::asio::any_io_executor>)>; | ||
|
||
private: | ||
std::queue<T> queue_; | ||
Sender sender_; | ||
Error error_; | ||
bool isSending_{false}; | ||
|
||
public: | ||
SendingQueue(Sender sender) : sender_{std::move(sender)} | ||
{ | ||
} | ||
|
||
std::optional<Error> | ||
kuznetsss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
send(T message, boost::asio::yield_context yield) | ||
{ | ||
if (error_) | ||
return error_; | ||
|
||
queue_.push(std::move(message)); | ||
if (isSending_) | ||
return std::nullopt; | ||
|
||
isSending_ = true; | ||
while (not queue_.empty() and not error_) { | ||
auto const responseToSend = std::move(queue_.front()); | ||
queue_.pop(); | ||
sender_(responseToSend, yield[error_]); | ||
} | ||
isSending_ = false; | ||
if (error_) | ||
return error_; | ||
return std::nullopt; | ||
} | ||
}; | ||
|
||
} // namespace web::ng::impl |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's UB if the exception is thrown, but I think we should be fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We throw exceptions from
ASSERT()
only in tests. I don't think there is a better way to check this, but I will think how to get rid of exceptions in tests forASSERT()
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added
WithMockAssertNoThrow
fixture for this case in tests.