-
Notifications
You must be signed in to change notification settings - Fork 26
feat: Update asio to 1.34 #31
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
Merged
FlorianReimold
merged 7 commits into
eclipse-ecal:master
from
DownerCase:fix_asio_compat
Apr 9, 2025
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8f8dd57
Update asio to 1.34
DownerCase befba60
Replace .wrap with bind_executor
DownerCase a2c1250
Rename io_service to io_context
DownerCase 658ea30
Don't push ASIO_NO_DEPRECATED to consumers
DownerCase 89c2adb
Use asio::post
DownerCase f905719
Fix CI mistake
DownerCase 7c03080
Try updating vs toolset?
DownerCase 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
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
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 |
|---|---|---|
|
|
@@ -32,20 +32,20 @@ namespace tcp_pubsub | |
| /// Constructor & Destructor | ||
| ////////////////////////////////////////////// | ||
|
|
||
| SubscriberSession_Impl::SubscriberSession_Impl(const std::shared_ptr<asio::io_service>& io_service | ||
| SubscriberSession_Impl::SubscriberSession_Impl(const std::shared_ptr<asio::io_context>& io_context | ||
| , const std::vector<std::pair<std::string, uint16_t>>& publisher_list | ||
| , int max_reconnection_attempts | ||
| , const std::function<std::shared_ptr<std::vector<char>>()>& get_buffer_handler | ||
| , const std::function<void(const std::shared_ptr<SubscriberSession_Impl>&)>& session_closed_handler | ||
| , const tcp_pubsub::logger::logger_t& log_function) | ||
| : publisher_list_ (publisher_list) | ||
| , resolver_ (*io_service) | ||
| , resolver_ (*io_context) | ||
| , max_reconnection_attempts_(max_reconnection_attempts) | ||
| , retries_left_ (max_reconnection_attempts) | ||
| , retry_timer_ (*io_service, std::chrono::seconds(1)) | ||
| , retry_timer_ (*io_context, std::chrono::seconds(1)) | ||
| , canceled_ (false) | ||
| , data_socket_ (*io_service) | ||
| , data_strand_ (*io_service) | ||
| , data_socket_ (*io_context) | ||
| , data_strand_ (*io_context) | ||
| , get_buffer_handler_ (get_buffer_handler) | ||
| , session_closed_handler_ (session_closed_handler) | ||
| , log_ (log_function) | ||
|
|
@@ -88,16 +88,15 @@ namespace tcp_pubsub | |
|
|
||
| void SubscriberSession_Impl::resolveEndpoint(size_t publisher_list_index) | ||
| { | ||
| const asio::ip::tcp::resolver::query query(publisher_list_[publisher_list_index].first, std::to_string(publisher_list_[publisher_list_index].second)); | ||
|
|
||
| if (canceled_) | ||
| { | ||
| connectionFailedHandler(); | ||
| return; | ||
| } | ||
|
|
||
| resolver_.async_resolve(query | ||
| , [me = shared_from_this(), publisher_list_index](asio::error_code ec, const asio::ip::tcp::resolver::iterator& resolved_endpoints) | ||
| resolver_.async_resolve(publisher_list_[publisher_list_index].first | ||
| , std::to_string(publisher_list_[publisher_list_index].second) | ||
| , [me = shared_from_this(), publisher_list_index](asio::error_code ec, const asio::ip::tcp::resolver::results_type& resolved_endpoints) | ||
| { | ||
| if (ec) | ||
| { | ||
|
|
@@ -136,7 +135,7 @@ namespace tcp_pubsub | |
| }); | ||
| } | ||
|
|
||
| void SubscriberSession_Impl::connectToEndpoint(const asio::ip::tcp::resolver::iterator& resolved_endpoints, size_t publisher_list_index) | ||
| void SubscriberSession_Impl::connectToEndpoint(const asio::ip::tcp::resolver::results_type& resolved_endpoints, size_t publisher_list_index) | ||
| { | ||
| if (canceled_) | ||
| { | ||
|
|
@@ -147,9 +146,9 @@ namespace tcp_pubsub | |
| // Convert the resolved_endpoints iterator to an endpoint sequence | ||
| // (i.e. a vector of endpoints) | ||
| auto endpoint_sequence = std::make_shared<std::vector<asio::ip::tcp::endpoint>>(); | ||
| for (auto it = resolved_endpoints; it != asio::ip::tcp::resolver::iterator(); ++it) | ||
| for (const auto& endpoint : resolved_endpoints) | ||
| { | ||
| endpoint_sequence->push_back(*it); | ||
| endpoint_sequence->push_back(endpoint); | ||
| } | ||
|
|
||
| asio::async_connect(data_socket_ | ||
|
|
@@ -220,7 +219,7 @@ namespace tcp_pubsub | |
|
|
||
| asio::async_write(data_socket_ | ||
| , asio::buffer(*buffer) | ||
| , data_strand_.wrap( | ||
| , asio::bind_executor(data_strand_, | ||
| [me = shared_from_this(), buffer](asio::error_code ec, std::size_t /*bytes_to_transfer*/) | ||
| { | ||
| if (ec) | ||
|
|
@@ -301,7 +300,7 @@ namespace tcp_pubsub | |
| asio::async_read(data_socket_ | ||
| , asio::buffer(&(header->header_size), sizeof(header->header_size)) | ||
| , asio::transfer_at_least(sizeof(header->header_size)) | ||
| , data_strand_.wrap([me = shared_from_this(), header](asio::error_code ec, std::size_t /*length*/) | ||
| , asio::bind_executor(data_strand_, [me = shared_from_this(), header](asio::error_code ec, std::size_t /*length*/) | ||
| { | ||
| if (ec) | ||
| { | ||
|
|
@@ -337,7 +336,7 @@ namespace tcp_pubsub | |
| asio::async_read(data_socket_ | ||
| , asio::buffer(&reinterpret_cast<char*>(header.get())[sizeof(header->header_size)], bytes_to_read_from_socket) | ||
| , asio::transfer_at_least(bytes_to_read_from_socket) | ||
| , data_strand_.wrap([me = shared_from_this(), header, bytes_to_discard_from_socket](asio::error_code ec, std::size_t /*length*/) | ||
| , asio::bind_executor(data_strand_, [me = shared_from_this(), header, bytes_to_discard_from_socket](asio::error_code ec, std::size_t /*length*/) | ||
| { | ||
| if (ec) | ||
| { | ||
|
|
@@ -380,7 +379,7 @@ namespace tcp_pubsub | |
| asio::async_read(data_socket_ | ||
| , asio::buffer(data_to_discard.data(), bytes_to_discard) | ||
| , asio::transfer_at_least(bytes_to_discard) | ||
| , data_strand_.wrap([me = shared_from_this(), header](asio::error_code ec, std::size_t /*length*/) | ||
| , asio::bind_executor(data_strand_, [me = shared_from_this(), header](asio::error_code ec, std::size_t /*length*/) | ||
| { | ||
| if (ec) | ||
| { | ||
|
|
@@ -424,7 +423,7 @@ namespace tcp_pubsub | |
| asio::async_read(data_socket_ | ||
| , asio::buffer(data_buffer->data(), le64toh(header->data_size)) | ||
| , asio::transfer_at_least(le64toh(header->data_size)) | ||
| , data_strand_.wrap([me = shared_from_this(), header, data_buffer](asio::error_code ec, std::size_t /*length*/) | ||
| , asio::bind_executor(data_strand_, [me = shared_from_this(), header, data_buffer](asio::error_code ec, std::size_t /*length*/) | ||
| { | ||
| if (ec) | ||
| { | ||
|
|
@@ -465,7 +464,8 @@ namespace tcp_pubsub | |
| return; | ||
| } | ||
| me->synchronous_callback_(data_buffer, header); | ||
| }); | ||
| }, | ||
| asio::get_associated_allocator(me->data_strand_)); | ||
|
|
||
| } | ||
| else | ||
|
|
@@ -479,7 +479,8 @@ namespace tcp_pubsub | |
| me->data_strand_.post([me]() | ||
| { | ||
| me->readHeaderLength(); | ||
| }); | ||
| }, | ||
| asio::get_associated_allocator(me->data_strand_)); | ||
|
||
| })); | ||
| } | ||
|
|
||
|
|
@@ -498,7 +499,8 @@ namespace tcp_pubsub | |
| data_strand_.post([me = shared_from_this(), callback]() | ||
| { | ||
| me->synchronous_callback_ = callback; | ||
| }); | ||
| }, | ||
| asio::get_associated_allocator(data_strand_)); | ||
|
||
| } | ||
|
|
||
| std::vector<std::pair<std::string, uint16_t>> SubscriberSession_Impl::getPublisherList() const | ||
|
|
@@ -545,14 +547,16 @@ namespace tcp_pubsub | |
| } | ||
|
|
||
| { | ||
| asio::error_code ec; | ||
| retry_timer_.cancel(ec); | ||
| try { | ||
| static_cast<void>(retry_timer_.cancel()); | ||
| #if (TCP_PUBSUB_LOG_DEBUG_VERBOSE_ENABLED) | ||
| if (ec) | ||
| log_(logger::LogLevel::DebugVerbose, "SubscriberSession " + endpointToString() + ": Failed canceling retry timer: " + ec.message()); | ||
| else | ||
| log_(logger::LogLevel::DebugVerbose, "SubscriberSession " + endpointToString() + ": Successfully canceled retry timer."); | ||
| log_(logger::LogLevel::DebugVerbose, "SubscriberSession " + endpointToString() + ": Successfully canceled retry timer."); | ||
| #endif | ||
| } catch (asio::system_error& err){ | ||
| #if (TCP_PUBSUB_LOG_DEBUG_VERBOSE_ENABLED) | ||
| log_(logger::LogLevel::DebugVerbose, "SubscriberSession " + endpointToString() + ": Failed canceling retry timer: " + err.what()); | ||
| #endif | ||
| } | ||
| } | ||
|
|
||
| resolver_.cancel(); | ||
|
|
||
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.
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.
Why is this line of code necessary?
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.
Because the remaining signatures of
io_context_strand::postrequires an allocator even though the function doesn't use it...https://github.com/chriskohlhoff/asio/blob/a892f73dc96bfaf92db98a3fe219f920fad007ea/asio/include/asio/io_context_strand.hpp#L174-L193
Looking at the commit that removed the originally used function, it actually says to use
asio::postwhich does not require an allocator.chriskohlhoff/asio@2f9c4ef#diff-a9951ef828e91a6ea4683ee5f1da1046abaefaa093db694a8a9825a098f50431
Thank you. I will make that change.