asio | Boostorg asio module | SDK library
kandi X-RAY | asio Summary
kandi X-RAY | asio Summary
Boost.org asio module
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of asio
asio Key Features
asio Examples and Code Snippets
Community Discussions
Trending Discussions on asio
QUESTION
My server crashes when I gracefully close a client that is connected to it, while the client is receiving a large chunk of data. I am thinking of a possible lifetime bug as with the most bugs in boost ASIO, however I was not able to point out my mistake myself.
Each client establishes 2 connection with the server, one of them is for syncing, the other connection is long-lived one to receive continuous updates. In the "syncing phase" client receives large data to sync with the server state ("state" is basically DB data in JSON format). After syncing, sync connection is closed. Client receives updates to the DB as it happens (these are of course very small data compared to "syncing data") via the other connection.
These are the relevant files:
connection.h
...ANSWER
Answered 2022-Apr-05 at 01:14Reviewing, adding some missing code bits:
QUESTION
ANSWER
Answered 2022-Mar-14 at 01:13Your lambda doesn't have the required signature.
Based the boost documentation, the callback takes a const boost::system::error_code&
argument. std::bind
lets you be a bit looser in the function signature (Why std::bind can be assigned to argument-mismatched std::function?), but lambdas need to be an exact match.
The following code seems to work for me
QUESTION
In the boost asio documentation for strands it says:
Strands may be either implicit or explicit, as illustrated by the following alternative approaches:
- ...
- Where there is a single chain of asynchronous operations associated with a connection (e.g. in a half duplex protocol implementation like HTTP) there is no possibility of concurrent execution of the handlers. This is an implicit strand.
- ...
However, in boost beast's example for a multithreaded asynchronous http server the boost::asio::ip::tcp::acceptor
as well as each boost::asio::ip::tcp::socket
get their own strand explicitly (see line 373 and 425). As far as I can see, this should not be necessary, since all of these objects are only ever going to be accessed in sequentially registered/running CompletionHandler
s.¹ Precisely, a new async operation for one of these objects is only ever registered at the end of a CompletionHandler
registered on the same object, making any object be used in a single chain of asynchronous operations.²
Thus, I'd assume that - despite of multiple threads running concurrently - strands could be omitted all together in this example and the io_context
may be used for scheduling any async operation directly. Is that correct? If not, what issues of synchronization am I missing? Am I misunderstanding the statement in the documentation above?
¹: Of course, two sockets or a socket and the acceptor may be worked with concurrently but due to the use of multiple stand
s this is not prevented in the example either.
²: Admittedly, the CompletionHandler
registered at the end of the current CompletionHandler
may be started on another thread before the current handler actually finished, i. e. returns. But I would assume that this is not a circumstance risking synchronization problems. Correct me, if I am wrong.
ANSWER
Answered 2022-Mar-13 at 18:48If the async chain of operations creates a logical strand, then often you don't need explicit strands.
Also, if the execution context is only ever run/polled from a single thread then all async operations will effective be on that implicit strand.
The examples serve more than one purpose.
On the one hand. they're obviously kept simple. Naturally there will be minimum number of threads or simplistic chains of operations.
However, that leads to over-simplified examples that have too little relation to real life.
Therefore, even if it's not absolutely required, the samples often show good practice or advanced patterns. Sometimes (often IME) this is even explicitly commented. E.g. in your very linked example L277:
QUESTION
I am spawning a coroutine as shown below.
...ANSWER
Answered 2022-Mar-01 at 19:59To cancel a coroutine in asio use the new awaitable_operator '||'. The awaitable operator '||' allows to co_await for more than one coroutine until one of the coroutines is finished. For example:
QUESTION
In the following example I start a worker thread for my application. Later I post some work to it. To prevent it from returning prematurely I have to ensure "work" is outstanding. I do this with a work_guard object. However I have found two other ways to "ensure" work. Which one should I use throughout my application? Is there any difference?
...ANSWER
Answered 2022-Feb-21 at 17:14My knowledge comes from e.g. WG22 P0443R12 "A Unified Executors Proposal for C++".
Some differences up front: a work-guard
- does not alter the executor, instead just calling
on_work_started()
andon_work_finished()
on it. [It is possible to have an executor on which both of these have no effect.] - can be
reset()
independent of its lifetime, or that of any executor instance. Decoupled lifetime is a feature.
On the other hand, using prefer/require to apply outstanding_work
sub-properties:
- modifies existing executors
- notably when copied, all copies will have the same properties. This could be dangerous for something as invasive as keeping an execution context/resources around.
However, not all properties are requirable in the first place. Doing some reconaissance using Ex
defined as:
QUESTION
Reference: https://www.boost.org/doc/libs/1_35_0/doc/html/boost_asio/reference/basic_socket_acceptor/async_accept/overload1.html
ANSWER
Answered 2022-Feb-18 at 02:33It all depends on the implementation of the types.
We can loosely describe the intent of a move as "the compiler is allowed to cannibalize". But really, for user-defined types we're going to have to tell it how to do that, exactly.
In language "doctrine" a moved-from object may only be assumed safe to destruct, but in practice many libraries make more lenient guarantees (e.g. keeping all the invariants, or making sure that a moved-from object is comparable to a newly constructed one).
Indeed, ASIO documents this:
RemarksFollowing the move, the moved-from object is in the same state as if constructed using the basic_stream_socket(const executor_type&) constructor.
QUESTION
I'm using asio (non-boost) to create a TCP server and while my code works it's not done properly because I'm calling asio::async_write
from multiple threads. I think I should use strands but the more I read about that the more lost I am.
ANSWER
Answered 2022-Feb-14 at 15:28You only have 1 thread running the IO service. Everything is on an implicit strand (Why do I need strand per connection when using boost::asio?), no need to worry UNTIL you start using a new thread.
The simplest fix, then, would seem to make sure sending the replies happens on the IO service as well:
QUESTION
I'm trying to send https web requests with Asio and OpenSSL. My code is working fine on most of the sites I tried it on, but on some others, I get an error during the handshake handshake: wrong version number (SSL routines, ssl3_get_record)
.
I've found some people having this issue because they were behind proxies or because they tried to connect to port 80 instead of port 443, but this is not the case here (as far as I know) because the exact same code (see below for minimal example) works for most of the sites I tried it on.
I've tried to check with wireshark to see if I could spot the difference between a case with and one without the error. Here what I found:
- when it works, TLSv1.2 or 1.3 is used, when it doesn't, it's TLSv1
- when it doesn't work, the DNS query shows a cloudfront cname redirection, but the endpoint used for the socket matches the redirection
Based on these observations, I know my code is capable of using TLSv1.3, and I thought that using TLSv1 was the issue. So I tried to force asio to use a version > 1 for TLS with asio::ssl::context::tlsv13_client
when creating the context, or by adding asio::ssl::context::no_tlsv1
to set_options, but wireshark still showed that a TLSv1 protocol was used.
For the second point, I'm not too familiar with web stuff, so I'm not sure what conclusion I can make about that, or even if it's relevant to the issue.
Minimal working example:
...ANSWER
Answered 2022-Feb-11 at 18:00You need to be more specific about the server you are trying to connect to:
QUESTION
If set up a program with boost asio. Broadcasts are working fine, if only one network interface is present. However, if there are more network interfaces each broadcast is being sent on one interface only. The interface changes randomly. As observed by wireshark.
I'd expect each broadcast to go out on every interface.
Who's wrong? Me, boost or my understanding of how to use boost. Well, I'm aware, that the latter is the most probable :).
And how can I get the expected behavior.
...ANSWER
Answered 2022-Feb-03 at 13:14As suggested by Alan Birtles in the comments to the question i found an explanation here: UDP-Broadcast on all interfaces
I solved the issue by iterating over he configured interfaces and sending the broadcast to each networks broadcast address as suggested by the linked answer.
QUESTION
When looking through boost asio co_spawn
documentation (https://www.boost.org/doc/libs/1_78_0/doc/html/boost_asio/reference/co_spawn/overload6.html), I see this statement, "Spawn a new coroutined-based thread of execution", however my understanding is that co_spawn
does not create an actual thread, but uses threads that are part of the boost::asio::io_context
pool. It's a "coroutine-based thread of execution" in a sense, that this coroutine would be a root of all coroutines that are spawned from inside this one
Is my understanding correct here or an actual thread is created whenever co_spawn
is used like this:
ANSWER
Answered 2022-Feb-01 at 13:01It does not. See The Proactor Design Pattern: Concurrency Without Threads and https://www.boost.org/doc/libs/1_78_0/doc/html/boost_asio/overview/core/threads.html
What does detached
mean/do? The documentation says:
The detached_t class is used to indicate that an asynchronous operation is detached. That is, there is no completion handler waiting for the operation's result.
It comes down to writing a no-op handler but (a) less work (b) more room for the library to optimize.
Another angle to look at this from is this: if the execution context for the executor (io_ctx
) is never run/polled, nothing will ever happen. As always in boost, you decide where you run the service (whether you use threads e.g.)
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install asio
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page