515 questions
1
vote
0
answers
67
views
asio: asio::awaitable<void> yield execution to other ready tasks
Consider the code
#include <asio.hpp>
asio::awaitable<void> doit(char ch)
{
for (int i = 0; i < 5; ++i) {
fprintf(stderr, "%c %d\n", ch, i);
asio::...
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 ...
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 ...
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
1
answer
111
views
How to make recordings using C#.NET, NAudio, ASIO4ALL, WinUI 3 (part of Windows App SDK), and Visual Studio 2022
The goal is to use NAudio, ASIO4ALL, WinUI 3 (a part of the Windows App SDK), and C#.NET in Visual Studio 2022 to make recordings. Unfortunately, such goal hasn't been reached as of yet.
I based my ...
3
votes
1
answer
153
views
How to gracefully shutdown asio::ssl::stream<asio::ip::tcp::socket> in C++ Asio? (shutdown always throws "stream truncated" exception)
I'm building a client-server project using standalone Asio (C++20) and OpenSSL. My client uses asio::ssl::stream<asio::ip::tcp::socket> for TLS connections.
After my client is done communicating ...
-1
votes
1
answer
152
views
How to deal with OpenSSL poluting the global namespace in C++?
I am trying to build C++ code with ASIO and OpenSSL (on windows, without boost). I have been using ASIO no problem for a while now. However, I now tried to include "asio/ssl.hpp" and I get a ...
3
votes
1
answer
74
views
AsyncOperation Reading and Writing
There is a test code for main, It's pretty simple.
void AddData(std::shared_ptr<std::queue<std::string>> stores)
{
stores->push("A\n");
stores->push("B\n")...
2
votes
1
answer
219
views
Boost asio serial port premature completion on async_read
I have a class that wraps a boost::asio::serial_port on a Windows system. I use it to start asynchronous reads on a supplied buffer.
It works well in most cases when there is data in the queue before ...
3
votes
0
answers
182
views
Is there a way to drain websocket in boost asio?
I am using asio/beast for tcp ssl connections. Calling async_read in a loop inside corouties.
In situations when I have N packets on websocket I need to do N async_reads to drain the websocket. This ...
0
votes
0
answers
53
views
is executor of asio always smart-ptr like?
When using asynchronous programming, the life cycle is always particularly complex. In order to control the life cycle effectively, I always try to use smart pointers to encapsulate all the objects ...
2
votes
1
answer
318
views
why boost asio tcp resolver creates threads for async resolve
When I use the following code, it spawns a new thread.
resolver_.async_resolve(
host_, port_,
beast::bind_front_handler(&session::on_resolve, shared_from_this()));
But when I change ...
3
votes
1
answer
58
views
boost asio single threaded post() doesn't post when poll() is used?
Everything is handle in a single thread
void GameClient::test()
{
std::cout <<"called test" << std::endl;
m_io_context.post([](){
std::cout << "test&...
2
votes
1
answer
156
views
Boost asio using concrete executor type with c++20 coroutines causes compilation errors
I am implementing a very simple UDP client using the Boost ASIO library with C++20 coroutines.
To try to gain a little performance cheaply, I am trying to use a concrete executor type asio::io_service:...
3
votes
1
answer
203
views
Separate Boost async read and async write in two threads
I was looking at the documentation provided by Boost regarding how to realize TCP async client/server (echo server, chat, and so on), but I didn't find anything related to managing the async read and ...
2
votes
1
answer
141
views
Deinterleave 24 bit audio buffer for ASIO output
I'm using an ASIO component (in Delphi 7) which supports only 16-bit and 32-bit output when it deinterleaves the left/right channels into 2 separate ASIO buffers. Some ASIO drivers only support 24-bit ...
1
vote
1
answer
101
views
Iterating over buffers in an asio::streambuf
While transferring data over named pipes I need to serialize some data structure and then transmit a sequence consisting of the size in bytes of the serialized structure as a uint32_t followed by the ...
0
votes
0
answers
51
views
Does boost asio guarantee a handler callback when async operation is pending?
To handle timeouts, let's assume I set up a steady_timer to go off right before async_resolve, async_connect, async_write, async_read_some...
When the timer fires, I shutdown & close the socket. ...
1
vote
1
answer
131
views
ASIO 'operation not supported' runtime error on windows when compiled with clang
I am trying to move away from using Visual Studio and use command-line compilation more, however I am having an issue with a project that uses ASIO in its header-only, standalone (non-boost) form ...
0
votes
1
answer
364
views
How to load an ASIO driver in C++?
I want to access the list of driver's names with the C++ ASIO SDK of Steinberg to select the driver then load it. So I try to use the hostsample.cpp exemple to write my code, it compile but dont want ...
0
votes
1
answer
794
views
How to compile Steinberg ASIO SDK on Window?
I want to compile a simple program using ASIO SDK, however there is a strange error that I cannot fix.
#include "asio.h"
int main(void)
{
ASIODriverInfo info {};
ASIOInit(&info)...
3
votes
1
answer
367
views
No audio input via ASIO with feedback example using cpal
I'm trying to build an audio application with cpal on Windows. With the Wasapi driver I got everything to work fine, but with ASIO only the outputs work, I can't get any input signals. I modified the ...
1
vote
1
answer
67
views
Asio no response afer sending a basic http request
I'm new to asio and was follwing a tutorial. After sending a pretty basic http get request to example.com there is no response.
#include<json/json.h>
#include<asio/ts/buffer.hpp>
#include&...
4
votes
1
answer
234
views
Can asio co_composed lambda function capture this pointer?
I've read this Q&A.
Lambda lifetime explanation for C++20 coroutines
If I understand correctly, lambda expression with capture something is not safe if the lambda expression is used as coroutine ...
2
votes
1
answer
120
views
async_write only sends after the server is closed
I'm trying to send messages via async_write, but they are only sent after I shutdown the server ( ctrl-c)
For example:
as client I send "test" and "test2", and only after closing ...
-1
votes
1
answer
122
views
asio TCP Client breaks when async
I am currently trying to communicate from Unreal Engine 5 with an existing piece of software we have running at our company. This software accepts TCP connections.
Since it seems to be the de-facto ...
1
vote
1
answer
100
views
C++ simple http server, the program closes on the second request and does not send the contents of the string
this is what my fileCollector looks like, it just stores a "cache" of files (so that you don't read the file during each request)
class FileCollector
{
public:
FileCollector()...
0
votes
1
answer
130
views
"corrupted size vs. prev_size" when using LZ4
I'm using JSON to pass messages between a server and a client, both written in C++. To get a performance boost, I'm evaluating compression, as well as binary formats (like MessagePack). I started with ...
1
vote
2
answers
279
views
the compiler throws an error on a function from boost.asio with cmake
I'm just learning boost.asio and decided to try to learn how to work with cmake as well, but my IDE swears at the async_wait function
my code looks like this
#include <boost/asio.hpp>
#include &...
1
vote
2
answers
2k
views
Understanding Boost.Asio Strand Behavior with Multiple Threads
Win12, boost::asio 1.82.0, MSVC 2022 (I used different compilers, c++ 14 and c++ 20)
I try to understand iocontext step by step.
Now I want to use many threads (but I don't want to use thread pool yet,...
1
vote
1
answer
162
views
Unexpected Behavior of Boost.Asio's io_context without Running ioc.run() - Why Does it Work?
I try to understand how iocontext works and created a simple program to understand its better step by step. As you can see, I even not to run ioc.run(). And I believed this code would do nothing.
But ...
2
votes
1
answer
184
views
ASIO continuously send requests to and get responses from the server over TCP using asio::async_write, asio::async_read, and asio::async_read_until
I am working on a C++ client/server application with standalone asio without boost. I want the client application to continuously get responses from the server and send requests to the server when a ...
1
vote
0
answers
223
views
Writing a custom async function using ASIO
I'm working on a async udp server for a multiplayer game. It is a personal project and for education. I'm using ASIO standalone and C++20, mainly relying on coroutines. For the past couple of days I'...
1
vote
1
answer
702
views
Correct usage of concurrent_channel in Asio?
I am currently learning how to use the concurrent_channel provided in boost asio. Unfortunately, there are no usage examples for concurrent_channel in boost asio, so I'm trying to write some demos ...
3
votes
1
answer
95
views
how to run 2 asynchronous timers implemented in a class
I want the second timer to start working half a second after the second one, but the moment the second timer starts working, the terminal displays something completely different from what I want. If ...
1
vote
1
answer
90
views
Segmentation fault using Boost Asio reference
The link I'm using for the asio code is https://www.boost.org/doc/libs/1_55_0/doc/html/boost_asio/tutorial/tutdaytime1.html
#include <iostream>
#include <boost/asio.hpp>
#include <boost/...
3
votes
1
answer
538
views
Is there any elegant way to combine asio::co_composed and std::variant?
Question
I want to treat connection classes that has same signature member functions. For example, both tcp and tls are kind of connection class. They have send() member function template that ...
0
votes
1
answer
303
views
getting the CppServer's asio example compiled in a meson project using the cmake module
I'm trying to add CppServer from https://github.com/chronoxor/CppServer as a dependency to my cpp meson project and I'm trying to run the asio server/client example from https://github.com/chronoxor/...
1
vote
1
answer
112
views
What is happend if a completion handler is neither invoked nor stored with C++20 coroutine?
Overview
When I use BoostAsio's CompletionToken facility, I design that completion_handler generated from CompletionToken finally invoked.
But I am interested in the behavior if completion_handler is ...
1
vote
1
answer
319
views
Problem sending 2 files to the client using Boost.Asio, Error: read: End of file [asio.misc:2]
I want to send two files to the client, the first file is img.jpg and the second file is message.txt
The first file img.jpg is received correctly, but the file message.txt is received with size zero
...
0
votes
0
answers
19
views
Asio 1.24.0 and OpenSSL 3.0.11 linking problem on Debian 6.1.52 [duplicate]
Operating system:
6.1.0-12-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.52-1 (2023-09-07) x86_64 GNU/Linux
What I'm trying to do:
I'm trying to build one of this asio samples: https://github.com/...
0
votes
1
answer
72
views
boost bind error for async reading with asio
I am trying to bind a callback function with asio async_read_some function.
Here is the code I tried to bind callback function for async reading.
#include <chrono>
#include <iostream>
#...
1
vote
1
answer
1k
views
How to wait multiple CompletionToken using C++20 coroutine with Boost.Asio?
Background
I'm using Boost.Asio. I call multiple asynchronous functions, then I want to wait multiple CompetionToken. For example, async_read() and steady_timer::async_wait().
I implemented it using ...
-2
votes
1
answer
67
views
Where is the documentation about removing arguments from a WriteToken signature, as shown in an official ASIO example?
In this example :
https://www.boost.org/doc/libs/1_83_0/doc/html/boost_asio/tutorial/tutdaytime3.html#boost_asio.tutorial.tutdaytime3.removing_unused_handler_parameters
It is written :
You may have ...
1
vote
1
answer
113
views
The connection cannot be completed in Linux boost::asio::spawn
If the server starts after the connection cannot be reached.why?
boost_1_73_0、Linux operating system
#include "boost/asio.hpp"
#include "boost/asio/spawn.hpp"
int main() {
...
2
votes
2
answers
651
views
How to wait for an `std::future` with boost::asio?
I have an asynchronous operation by an external library that I can't change, but I can give a callback to. I want to wait for it to finish but without blocking the io_context.
Something like:
// ...
0
votes
1
answer
73
views
Check if data is available to read in ASIO
I am migrating old c++ code to more modern c++ with ASIO and i have a problem which i'm not sure how to solve with ASIO.
The general ideia is:
Act as Client and
...
1
vote
1
answer
116
views
How to retrieve the data type stored in buffer and pass it to the template?
I have a problem that when I call async_read I don't know the exact data type which a user sent so I need to retrieve it from the asio::streambuf and pass it to the asio::buffer_cast template. Also we ...
1
vote
1
answer
103
views
Problem downloading files with boost asio, junk in output file
I'm trying to download any files from server - images, text/html, zip etc. But somehow I have some trash in the beginning and at the end of my output file.
#include "dependencies.h"
asio::...
0
votes
1
answer
153
views
Getting multiple audio samples from naudio GetAsInterleavedSamples using asioOut
After checking out this link:
Writing multiple wav files from NAudio asioOut, I wanted to be able to get separate wave samples into different files, but it's not working. I'm only getting zero-byte ...