4,884 questions
1
vote
0
answers
88
views
Using boost::asio::async_wait with Native recvfrom() Calls: Is It Correct?
Suppose we are waiting for incoming data on a socket using the call socket::async_wait(socket::wait_read, callback). After the callback notifies us that data is available, is it possible to read the ...
2
votes
1
answer
143
views
Is it possible to apply rate limiting to UDP sockets in Boost?
As is well known, in Boost we can use a rate limit to restrict the read and write speed of a TCP stream, as indicated in the documentation: https://www.boost.org/doc/libs/latest/libs/beast/doc/html/...
1
vote
1
answer
134
views
Race condition with ordered send queue in ASIO
I have the following code using the C++ ASIO library that's intended to ensure messages are not interleaved on the socket being written to (as discussed here):
#include <boost/asio.hpp>
#include ...
0
votes
1
answer
169
views
Why does boost::asio accepts parameters by const references?
I have a class like this:
class Socket
{
public:
boost::asio::awaitable<void> asyncConnect(
boost::asio::ip::basic_resolver_results<boost::asio::ip::tcp>::value_type
...
2
votes
1
answer
48
views
‘asio::stream_file’ has not been declared error on Linux with GCC
I built BOOST 1.89 on Ubuntu 24.04 with GCC 13.3.0 using the following commands:
./bootstrap.sh --prefix="/home/dmitriano/dev/libs/boost"
./b2 -j8 cxxstd=20 install
See config and build log....
1
vote
0
answers
122
views
Number of threads for domain name resolution in boost asio
According to the boost::asio documentation, for each io_context one or more additional threads can be created that will be used for host resolution.
One or more additional threads per io_context to ...
1
vote
1
answer
49
views
Using asio::async_initiate with asio::co_spawn and asio::any_io_executor
Is it guaranteed that token will be called on executor ex in the code below?
template <class T, class CompletionToken>
auto async_from_awaitable(asio::any_io_executor ex,
asio::awaitable<...
1
vote
1
answer
115
views
Monitor boost io_context availability
I want to set up a watchdog that checks whether the io_context workers can pick up tasks within a reasonable time and are not stuck running long or blocking operations.
To achieve this, I've ...
2
votes
1
answer
102
views
Boost.Beast async_connect fails after upgrading Boost 1.78 to 1.89
I have a Websocket class that connects asynchronously using Boost.Asio and Boost.Beast. The following code was working fine with Boost 1.78, but after updating to the latest Boost version, I now get a ...
4
votes
1
answer
143
views
Boost Asio Timer interruption after signal is handled
I have the following program that just runs a timer for 5 seconds and has a signal handler.
#include <boost/asio.hpp>
#include <chrono>
#include <iostream>
#include <signal.h>
...
2
votes
1
answer
91
views
integration of windows message loop (PeekMessage -> DispatchMessage) with boost.asio
I have a Windows application that uses boost.asio for I/O.
but the asio's io_context::run() executes in a separate thread, because of WinMain() function has while() {} loop with PeekMessage() and ...
2
votes
1
answer
117
views
How to wait one task to finish and do not cancel others?
Assume I run multiple transfer tasks. How do I wait one task to finish and do not cancel others in bidirectional_transfer method? (Assume there are not two tasks, but three or more).
#include <...
1
vote
1
answer
83
views
asio::experimental::use_promise requires the result type to be default constructible
I wrote an experimental TCP proxy with boost::asio and tried to replace all asio::use_awaitable with asio::experimental::use_promise in my code (as another experiment), and the following code stopped ...
2
votes
2
answers
97
views
Hook asio io_context so that my own functor is called for every completion handler
I am working in a system which uses a global Clock singleton to store the current time.
class Clock
{
public:
static Clock& instance()
{
static Clock clock;
return clock;
...
3
votes
1
answer
87
views
How do I combine multiple boost::asio::experimental::promise?
How do I implement asyncConnectAndHandshake function that connects to a TCP server and than does SSL handshake and returns boost::asio::experimental::promise?
#pragma once
#include <boost/asio.hpp&...
2
votes
1
answer
116
views
What is the proper usage of boost::asio::experimental::promise?
While investigating boost::asio::experimental::promise I wrote the code below with two asyncRead functions:
#pragma once
#include <boost/asio.hpp>
#include <boost/asio/ssl.hpp>
#include &...
4
votes
1
answer
110
views
Using an analog of boost::asio::awaitable in boost::cobalt
SocketWrapper class has asyncRead that reads either from boost::asio::ssl::stream<boost::asio::ip::tcp::socket> or from boost::asio::ip::tcp::socket depending on isSSL() flag:
#pragma once
#...
8
votes
1
answer
164
views
Asio's signal handling under multithreaded scenarios
In Linux OS's multithread process, the signal isn't guaranteed to deliver to specific thread.
And I wonder, when I use asio::signal_set::async_wait. Is this asynchronous operation guaranteed to ...
2
votes
1
answer
125
views
When does socket::is_open return false?
Suppose I accept a socket by calling async_accept like this
acceptor.async_accept([](const boost::system::error_code& ec, boost::asio::ip::tcp::socket sock)
{
if (ec)
return;
auto sess = std:...
0
votes
0
answers
47
views
Failing to configure nghttp2-asio in MacOS
I checked out nghttp2/asio in my C++ project. I have built boost version 1.89.0 from source using b2.
I am met with error "Could not find version of library" and as per the configure shell ...
3
votes
1
answer
91
views
Why does Asio TCP server crash after the first async_read?
I wrote a simple program to learn how Asio works.
Here's the code:
#include <boost/asio.hpp>
#include <iostream>
namespace asio = boost::asio;
using asio::ip::tcp;
int main() {
using ...
2
votes
2
answers
119
views
How to share dependencies in composed Asio operations
This question nerd-sniped me by a problem mentioned in the comments:
@sehe use_promise seems very interesting. I looked up some
documentation about it and found some of your posts, like this. But
how ...
0
votes
0
answers
231
views
How to use boost::asio::co_spawn with boost::thread::future?
I'm trying to use asio::co_spawn with boost::future in Thread library, such that I could chain the co_routine task with then() function. But the problem is asio::use_future only generates std::future. ...
0
votes
0
answers
106
views
VS2022 17.6+Boost.ASIO 1.89+C++20: there are no parameter packs available to expand
I encountered a compiler bug when using C++20 + Boost.ASIO in Windows boost1.89 & msvc17.6:
asio\co_composed.hpp(162,33): error C3546: '...': there are no parameter packs available to expand
asio\...
2
votes
1
answer
197
views
How to parse multipart/form-data from http::request<http::string_body> object?
I am reading a http::request<http::string_body> request from the network using boost::beast, which is of type multipart/form-data. The request contains files and strings.
How can I get each part ...
1
vote
1
answer
51
views
How can I skip uninteresting functions/files with lldb (in boost asio)?
I would like to skip the whole boost library details when stepping through the code in the debugger.
Example uninteresting things I would like to skip:
(lldb) n
Process 577286 stopped
* thread #1, ...
5
votes
2
answers
132
views
Copy boost::asio::streambuf using std::ostream
I need to copy one boost::asio::streambuf to another. For this I decided to use std::ostream. At the moment I copy the buffer like this
boost::asio::streambuf src;
boost::asio::streambuf dst;
std::...
3
votes
1
answer
104
views
Why prepare_payload removes Transfer-Encoding: chunked from http::response?
I create http::response<string_body> and call prepare_payload() after the response is built like this
http::response<http::string_body> res;
res.version(11);
res.result(http::status::ok);
...
3
votes
1
answer
153
views
Call boost::asio::post for io_context which runs in another thread
I have two threads and I need to run a task from the first thread but in such a way that the task is executed in the second thread.
For this I decided to use boost::asio::post, but I'm not sure if it ...
2
votes
1
answer
192
views
boost.asio : how to cancel a synchronous task
The following code simulates short bursts of work by sleeping 1ms at a time in order to achieve a cancellable task that takes a total of 2s. That work is then launched in three different ways.
The ...
3
votes
1
answer
99
views
Is it correct to reset the connection in websocket::stream_base::decorator callback?
I have a websocket server where I call websocket::stream::async_accept to perform a handshake with the client.
I also set a decorator to modify the headers like this
conn->get_websocket_stream()....
2
votes
2
answers
159
views
Do asio initiating functions synchronize with the completion handlers?
I'm trying to understand the memory order related to asio initiating functions and completion handlers, but I can't find any documentation on this.
Asio examples tend to start the io_context::run ...
-1
votes
1
answer
145
views
How to determine whether the ClientHello message was received fully or not [closed]
I read TLS ClientHello data from the network using boost::asio like this
socket->async_wait(ip::tcp::socket::wait_read, [=](const boost::system::error_code& ec)
{
std::size_t avail = socket-...
4
votes
1
answer
65
views
Does http::response_parser inherits limits from source parser?
I create http::response_parser<http::buffer_body> and set header_limit and body_limit like this
auto parser = std::make_shared<http::response_parser<http::buffer_body>>();
parser->...
1
vote
1
answer
152
views
True Non threaded Asynchronous File IO in c++
How to verify if Boost.Asio actually uses Windows Overlapped I/O for file operations?
I'm implementing high-performance file I/O in C++ on Windows and need to confirm whether Boost.Asio truly ...
3
votes
1
answer
161
views
Will moving ssl::context cause UB?
I have some code that creates an ssl::stream. The ssl::stream object takes an ssl::context in its constructor by reference. Creating an ssl::stream looks like this
ssl::context ssl_context(boost::asio:...
1
vote
1
answer
130
views
ssl::stream::shutdown sometimes does not complete
I want to close the TLS connection gracefully. So before closing the socket I call ssl::stream::shutdown. I call ssl::stream::shutdown in the session destructor and at that moment I have no active ...
3
votes
1
answer
152
views
Is it guaranteed to cancel socket operations under Windows 10+?
Suppose we have ip::tcp::socket and asynchronous operations, and at some point we call ip::tcp::socket::cancel. Is it guaranteed that all asynchronous operations will be cancelled? The documentation ...
5
votes
1
answer
111
views
Boost.Asio coroutine hangs when using both `concurrent_channel` and `steady_timer`
I'm encountering a strange issue using Boost.Asio coroutines in combination with steady_timer and experimental::concurrent_channel. Some coroutines never return from timer->async_wait.
Here's a ...
1
vote
1
answer
71
views
WebSocket interface binding not working with Boost.Beast - socket still uses default interface
I'm trying to bind a WebSocket connection to a specific network interface using Boost.Beast, but the socket keeps using the default interface instead of the specified one.
I have a WebSocket client ...
2
votes
1
answer
110
views
call ssl::stream::async_shutdown after read operation cancelled
I have one active async operation, it is http::async_read. At the moment when I want to close the ssl connection, I cancel this async operation on the socket by calling ip::tcp::socket::cancel.
Then I ...
2
votes
1
answer
154
views
Boost.Asio: any_completion_handler and associated executor
I want to implement my own async initiating function and use the type erasure wrapper boost::asio::any_completion_handler. Assuming I want to store the completion handler for later, how do I ensure ...
3
votes
1
answer
152
views
Correct way to call ssl::stream::async_shutdown
Is it correct to call ssl::stream::async_shutdown while there are outstanding async_read_some/async_write operations? Should I wait for all async operations to complete before calling ssl::stream::...
5
votes
1
answer
132
views
How to receive a string with boost.asio's resumable C++20 coroutines?
I would like to define a test case using experimental Resumable C++20 Coroutines from boost.asio, such that the coroutine would be implemented as a generator receiving a string under co_yield and ...
2
votes
1
answer
116
views
how to compose as_tuple with use_awaitable completion adapters for boost.process v2 async_wait?
When I was trying to develop some example code for a question about completion tokens under co_await with boost asio's async_read_some for an asio::readable_pipe, I arrived at the following code, with ...
1
vote
1
answer
237
views
How do I spawn multiple coroutines with co_spawn that run concurrently while awaiting the results in another coroutine in the same order?
I'm trying to implement HTTP 1.1 pipelining using Boost Asio, Boost Beast and coroutines.
What I've come up with for now is using one coroutine for receiving requests, one for sending responses and ...
2
votes
1
answer
95
views
Controlling BOOST_ASIO_ENABLE_HANDLER_TRACKING Output at Runtime
I'm using the BOOST_ASIO_ENABLE_HANDLER_TRACKING flag in Boost.Asio to enable handler tracking logs, which provides useful debugging output to the standard error stream.
I have a couple of questions ...
0
votes
0
answers
99
views
boost::asio::io_context stops running new tasks
I'm encountering an issue with the Boost.Asio library. My program uses a single io_context instance and multiple worker threads that call io_context::run(). Tasks are posted using spawn or post on the ...
1
vote
1
answer
130
views
Why doesn't boost::asio::async_initiate or async_compose automatically call the handler via its bound executor
Code firstly, very simple example code:
template <typename CompletionToken>
decltype(auto) test_initiate(CompletionToken&& token) {
return boost::asio::async_initiate<...
3
votes
1
answer
62
views
Correct way to convert http::response_parser<http::buffer_body> to http::response_parser<http::string_body>
I have a response parser of type http::response_parser<http::buffer_body>, which I need to convert to a parser of type http::response_parser<http::string_body>. I do the conversion after ...