Questions tagged [boost-asio]
Boost.Asio is a cross-platform C++ library for network and low-level I/O programming that provides developers with a consistent asynchronous model using a modern C++ approach.
4,301
questions
1
vote
1
answer
19
views
asio::ip::tcp::socket auto reconnect by io_service
Under Ubuntu 2404LTS with boost version 1.65.1.
I use io_service to initiate asio::ip::tcp::socket async_connect and get socket1, then I read several messages from it.
After receving some specific ...
2
votes
1
answer
29
views
is it safe to use boost::asio::streambuf as both an istream and an array as string_view?
For example, could there be problems with the memory work inside this buffer if I use code like this? Can I use the input stream and use sv (string_view) with the same streambuf?
boost::asio::...
0
votes
0
answers
18
views
asio::thread created in object with global scope causes strange behavior, but not if it is created in main
I have been battling a problem for a day or so and "solved" it but I wonder if anyone knows why it must be so, or whether I have just hacked my way around a deeper problem in my code. Using ...
1
vote
1
answer
62
views
boost::asio: register fd for EPOLLIN / EPOLLOUT once and leave it registered
I have a tcp client which is serviced by a boost::asio::io_context running on a single thread. It is configured non-blocking.
Reads/writes to this client are only ever done within the context of this ...
0
votes
1
answer
27
views
why do i getting boost.URL linking error?
This is my project :
https://github.com/Naseefabu/HFTBOT/blob/master/src/main.cpp
When i try to build it,
Error :
https://gist.github.com/Naseefabu/5a114956f39b6c853916bcaf66f939e4
Is it because that ...
-1
votes
2
answers
42
views
boost::asio::io_context::stop segfalt in gtest setup and teardown
Using C++17. I am trying to setup a gtest fixture that will create a fresh io_context to run timers on for each test case. My test segfault about 90% of the time. If I debug and step very slowly, I ...
1
vote
1
answer
32
views
Understand function parameters(pass by value instead of by const reference) in boost::beast client example websocket_client_async_ssl.cpp
Reference:
boost_1_78_0/doc/html/boost_asio/reference/ip__basic_resolver/async_resolve/overload1.html
template<
typename ResolveHandler = DEFAULT>
DEDUCED async_resolve(
const query &...
1
vote
1
answer
28
views
Boost Asio J1939 / Can-bus Multithreading
I am implementing a J1939 socket handler on top of Boost::ASIO and canary. My previous application had a socket to listen for devices and the each device discovered would also have a socket. Each ...
1
vote
1
answer
77
views
Asio How to write a custom AsyncStream?
I have actually managed to write a working AsyncStream. However, I am not really sure if I did it the way it is supposed to be done.
My main question is: Which executor is the get_executor() function ...
1
vote
1
answer
62
views
how to send request parameters with beast
body in the docs i am trying to send to the server : https://binance-docs.github.io/apidocs/spot/en/#order-book
// Start the asynchronous operation
void
run(
char const* host,
...
1
vote
1
answer
49
views
Boost Asio and Udp Poll() No incoming data
I have to handle information from 100 ports in parallel for 100ms per second.
I am using Ubuntu OS.
I did some research and i saw that poll() function is a good candidate, to avoid to open 100 threads ...
1
vote
1
answer
49
views
Is there a problem with the socket I wrote for boost::socket, for the simplifying work with network?
I wrote a socket class to wrap all the work with asynchronous methods boost::asio, did it for the sake of code reduction, just inherit from this class and use its methods! Is there any flaws, because ...
6
votes
1
answer
117
views
asio How to change the executor inside an awaitable?
I have read this question and tried to replicate the answer with the following code:
#include <iostream>
#include <syncstream>
#include <thread>
#include <coroutine>
#include &...
1
vote
1
answer
70
views
How to use boost::outcome::result as the return type of completion token for boost::asio::co_spawn
boost::asio::co_spawn requires the completion token with the signature void(std::exception_ptr, R) for calling an awaitable function boost::asio::awaitable<R>.
When the return type of awaitable ...
1
vote
1
answer
59
views
boost.beast : HTTP/1.1 400 Bad Request
#include <boost/beast/http.hpp>
#include <boost/beast/ssl.hpp>
#include <boost/beast/version.hpp>
#include <boost/asio/executor.hpp>
#include <boost/asio/strand.hpp>
#...
1
vote
1
answer
39
views
Boost async_pipe not showing all child process output
I ran into a roadblock. The code below has issues, but this is just a demo; I want to get the high level logic correct first.
The two startup application output a lot of startup info, before arriving ...
0
votes
1
answer
55
views
beast : http bad request
#include <boost/beast/http.hpp>
#include <boost/beast/ssl.hpp>
#include <boost/beast/version.hpp>
#include <boost/asio/executor.hpp>
#include <boost/asio/strand.hpp>
#...
0
votes
1
answer
40
views
ASIO async_write with empty buffer
What happens when an ASIO async_write is invoked with zero bytes in the outgoing buffer?
Example:
// Assume data is a member with appropriate lifetime for duration of handler, but data.size() == 0
...
0
votes
1
answer
46
views
Listening for all incoming packets to a certain network interface using Boost/ASIO
I was looking all over the internet to find a way to capture incoming packets from a certain network interface, then I came across PCAP, TCPDUMP, I believe the most commonly used networking library ...
0
votes
0
answers
31
views
Can i use `asio::io_context` just as an Event queue?
I am experimenting asio for game developpment.
Outside networking, since I need an Event Queue and asio::io_context is basically an event queue that do tasks in order with io_context::poll(), is it ...
1
vote
1
answer
30
views
How to create a response from a file that has CJK filename
I'm trying to load a file to be a HTTP response with Boost.Beast, but it doesn't work on Windows. My code is similar to this:
typedef boost::beast::http::response<boost::beast::http::file_body> ...
1
vote
1
answer
65
views
i cannot build one of the examples provided in the beast websocket example
My code :
#include <boost/beast/core.hpp>
#include <boost/beast/websocket.hpp>
#include <boost/asio/strand.hpp>
#include <boost/thread/thread.hpp>
#include <boost/...
0
votes
1
answer
40
views
I am trying to upgrade from boost 1.68.0 to boost 1.77.0. But I am facing issue related to endpoint type
I need to upgrade from boost 1.68.0 to boost 1.77.0.
So I downloaded boost 1.77.0 and built it.
But when I compile my code with boost I get the following error,
In file included from
..//../bin/boost/...
0
votes
0
answers
46
views
boost::asio::ip::udp::socket can I force an immediate send or write?
I'm working on up programme using boost::asio::ip::udp:: socket where I need at certain moment send a buffer to a specific end point with high priority (I need a guarantee that my data was delivered ...
0
votes
1
answer
77
views
Can Boost::asio::post can interrupt the running thread?
I am new to Boost::asio and I am currently looking at io_context.
I have a question regarding the function io_context::post
Posting on thread can preempt what's running on that thread currently ?
...
3
votes
1
answer
127
views
Server crashing while being interrupted sending large chunk of data
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 ...
1
vote
1
answer
61
views
Sending a large text via Boost ASIO
I am trying to send a very large string to one of my clients. I am mostly following code in HTTP server example: https://www.boost.org/doc/libs/1_78_0/doc/html/boost_asio/examples/cpp11_examples.html
...
1
vote
1
answer
61
views
How to communicate with child process asynchronously?
I have a parent GUI app built with GTKmm, and I need to spawn a child process (another GUI app) and communicate with it. I use boost::process to do that. I know that I should do it asynchronously, so ...
0
votes
0
answers
45
views
Boost asio set_option(boost::asio::ip::udp::socket::reuse_address(true)) error
I have two processes,in ubuntu 18.04,both use the same port. So, I set them reuse address.
one use socket, the code is
int flag = 1;
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR | SO_REUSEPORT, &flag, ...
1
vote
1
answer
67
views
Asio async_read_until EOF Error in Asynchronous TCP Server
when I build it, and running server and then run client, that appear a error
error code = 2, error message = End of file
when I code synchronous tcp server it's work ok;
thanks
full client code
#...
1
vote
1
answer
90
views
Boost Asio Serial port How to find out the size of the buffer in the queue for reading C++
In Arduino data can be read as follows:
void setup() {
Serial.begin(9600);
}
String Comand = "";
void loop() {
if (Serial.available() > 0) //If there is data read
{
...
2
votes
1
answer
76
views
Asio difference between work(), require() and make_work_guard()
Sorry to interrupt, I am a newbie in C++ and Asio...
I just come from here Asio difference between prefer, require and make_work_guard.
I am trying to make a "dummy work" for my io_context.
...
1
vote
1
answer
59
views
Understand the usage of strand without locking
Reference:
websocket_client_async_ssl.cpp
strands
Question 1> Here is my understanding:
Given a few async operations bound with the same strand, the strand
will guarantee that all associated async ...
1
vote
1
answer
40
views
Why do we need to run `io.run` in both main thread and a new thread `t` within asico tutorial Timer.5 example?
Reference: tuttimer5
coliru demo
Based on the tutorial, the main function looks like the following:
int main()
{
boost::asio::io_context io;
printer p(io);
boost::thread t(boost::bind(&boost:...
2
votes
1
answer
70
views
Does mulithreaded http processing with boost asio require strands?
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 ...
1
vote
1
answer
117
views
boost::asio - the acceptor doesn't call the callback after the server is stopped and started again
I've created a simple wrapper for boost::asio library. My wrapper consists of 4 main classes: NetServer (server), NetClient (client), NetSession (client/server session) and Network (composition class ...
1
vote
1
answer
58
views
How to write content to file asynchronously with boost::beast or boost::asio?
Based on websocket_client_async_ssl.cpp, I modify the function of on_read so that I can save the content into a local file.
class session : public std::enable_shared_from_this<session>
{
std:...
1
vote
1
answer
75
views
How to make a timeout at receiving in boost::asio udp::socket?
I create an one-thread application which exchanges with another one via UDP. When the second is disconnecting, my socket::receive_from blocks and I don't know how to solve this problem not changing ...
1
vote
1
answer
159
views
Is it possible to use keep-alive with boost::beast sync https client?
Is it possible to use http 1.1 keep-alive with the boost beast library when using a sync ssl client? I have a process that works something like this:
Connection to web server using https. Send an ...
1
vote
1
answer
74
views
segfault when using boost::asio::async_read
I'm new in doing serial port communication with boost::asio.
In my program, the code can write data to the serial port correctly.
But when receiving data, segmentation fault came up.
I tried std::cout ...
0
votes
0
answers
67
views
Can a C++20 co-routine implement a synchronous interface without blocking?
I am writing a GRPC service and am trying to use the asynchronous methods with the help from Asio. The service calls into a C++ library that have synchronous methods. The code in that library uses ...
2
votes
1
answer
219
views
ASIO C++ coroutine cancellation
I am spawning a coroutine as shown below.
asio::co_spawn(executor, my_coro(), asio::detached);
How am I supposed to cancel it?
As far as I know, per handler cancellation can be achieved simply by ...
1
vote
1
answer
109
views
Combine multiple boost::asio::const_buffer into a single buffer
My program receives data in the form of std::vector<boost::asio::const_buffer> buf_vect. I need to combine the const_buffer in the vector into a single buffer which will then be converted to a ...
1
vote
0
answers
36
views
Websocketpp server that yield on boost fibers
I try to implement a version of websocketpp server inside a mono-thread project that uses multiple coroutines based on boost fibers.
The server is working fine but I'm having issue with the fact that ...
1
vote
1
answer
54
views
asio socket, split incoming data at a delimitator?
I am reading data from a asio socket in c++.
I need to parse the incoming data as json. To do this, i need to get a single json string entry. I am adding a character ';' at the end of the json string, ...
0
votes
1
answer
78
views
Why does sanitizer give warnings when processing asynchronous boost::asio operations in parallel in my code?
I am decided to test my project written using boost::asio (I run io_service::run in different threads) with all kinds of sanitizers and on thread-sanitizer got data race, namely it reported that ...
0
votes
0
answers
54
views
Boost async: which completion condition to use with async_read on a socket?
I'm using Boost's async_read method to read from a socket (see code below).
Wireshark shows that packets of various size are received on the socket port, some with size between 256B and 512B (we only ...
1
vote
1
answer
114
views
HTTP requests via proxy with boost beast
Is it possible to set a proxy when making HTTP requests using Boost Beast?
Using CURL is straighforward. Anyone has done this?
Thank you,
0
votes
0
answers
24
views
C++ Boost http post request [duplicate]
I have the read the Boost documentation and manage to run a get request:
https://www.boost.org/doc/libs/1_77_0/libs/beast/doc/html/beast/quick_start/http_client.html
However I unable to figure out how ...
4
votes
1
answer
171
views
Asio difference between prefer, require and make_work_guard
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 ...