Questions tagged [asio]

ASIO stands for Audio Stream Input/Output, a digital audio protocol. For questions about the Boost.Asio C++ library for asynchronous I/O, use the [boost-asio] tag to avoid ambiguity.

Audio Stream Input/Output is a low-latency protocol for sending and receiving audio data from sound interfaces. It was developed by Steinberg, which offers a licensed ASIO SDK among other audio software technology such as VST plugins.


Please note that in order to avoid ambiguity, questions about Boost.Asio should be tagged with as discussed on meta.

479 questions
1
vote
1 answer

Can't set keep_alive to socket in asio

I'm trying to create a ServerSocket as a singleton. Here's the code: ServerSocket.h #pragma once #include #include #include using asio::ip::tcp; class ServerSocket { public: ServerSocket(ServerSocket&…
Vasile Mihai
  • 103
  • 6
1
vote
1 answer

where is the const-ness in this lambda capture argument introduced?

This code compiles correctly. #include #include #include struct Message { int msg; }; // never mind global variables, just for the sake of making this a minimal example extern asio::ip::tcp::socket mysocket; void…
Fabio
  • 2,105
  • 16
  • 26
1
vote
0 answers

Icmp ping with Asio on macOS: Operation not permitted

I successfully ported the Asio Pinger example https://think-async.com/Asio/asio-1.20.0/src/examples/cpp03/icmp/ping.cpp to work without Boost at all. The example works perfectly, but running the app as root on macOS. As suggested here and here, I…
JohnnyParafango
  • 316
  • 2
  • 11
1
vote
1 answer

boost::asio::connect compile failed ['this' pointer is null]

I tried to compile a project but it failed with the following error: Build Error Below is the code in my project: boost::system::error_code ec; auto endpoints = resolver->resolver().resolve(ip_address, std::to_string(port)), ec); if (ec) …
Hung Law
  • 11
  • 1
1
vote
1 answer

Sending http request from multiple threads using boost::asio. How to handle responses serially

For a client side application, I wish to serialize http post requests using strand, in order to avoid overlapping writes/ responses to/from the server. Serialization is made using boost::asio, by calling the method as a callback from strand.post as…
Zohar81
  • 4,554
  • 5
  • 29
  • 82
1
vote
1 answer

Difference between boost::asio::strand and boost::asio::io_context::strand

I'd like to serialize http post requests using strand, to avoid overlapping writes to network. My approach was to call the post method from the strand object with the callback that send the data as can be shown in the following code : void Send( …
Zohar81
  • 4,554
  • 5
  • 29
  • 82
1
vote
1 answer

boost::deadline_timer error: static assertion failed: WaitHandler type requirements not met

I have a cnx class which represents a socket and it must also has a timer in which if the clients stays more than cnx::timeout_mili milliseconds without responding then I'll close the connection. Each timer will start when the connection is made,…
Fnr
  • 2,096
  • 7
  • 41
  • 76
1
vote
1 answer

`io_context.stop()` vs `socket.close()`

To close a Tcp client, which one should be used, io_context.stop() or socket.close()? What aspects should be considered when making such a choice? As far as I know, io_context is thread-safe whereas socket is not. So, I can invoke io_context.stop()…
John
  • 2,963
  • 11
  • 33
1
vote
1 answer

Why is there not a "cursor" for caller to async_send_some with ConstBufferSequence buffers?

In boost asio is there async_write_some for programmer to implement their own fine-grained logic similar to async_write in any fashion, etc: class koebenhavn : public std::enable_shared_from_this { private: …
Y.Z
  • 626
  • 2
  • 9
  • 21
1
vote
1 answer

In a thread which never calls asio::io_conterxt.run(), must I invoke post() to dispatch tasks to the thread which has called io_context.run()?

In a thread which has not ever called and would never call asio::io_context.run(), must I invoke post() or dispatch() to dispatch tasks to the thread which has called asio::io_context.run()? Is it safe to directly call asio::async_write() or…
John
  • 2,963
  • 11
  • 33
1
vote
1 answer

Avoiding global variables making boost asio socket wrapper

i have this socket-tcp.h with an wrapper of socket implementation using boost asio: #include #include #include static const std::string PORT = "65432"; static const std::string HOST = "127.0.0.1"; …
Guinther Kovalski
  • 1,629
  • 1
  • 7
  • 15
1
vote
0 answers

serial_port::async_read_some not working without sleep

#define DELAY 1 func() { auto readHandler = [&](const boost::system::error_code& ec, std::size_t bytesRead)->void { if(ec) { // Something went wrong std::cerr << ec.message()…
1
vote
1 answer

Sending Packet objects with boost asio

Take the following: struct Header{ std::size_t body_size; }; struct Body{ std::string data; }; struct Packet{ Header header; Body body; }; Suppose now, that I want to send a Packet object over a tcp socket. To do this, I want to…
snakelovah18119
  • 121
  • 1
  • 7
1
vote
0 answers

boost asio thread_group only run one thread

I am studing boost library. I want to use fiber with blocking api so I try to use a thread pool to run blocking api. When the blocking api is finished, the fiber get the result. I have created a thread pool of 4 threads, but I found that only one…
KingHowe
  • 11
  • 2
1
vote
1 answer

How to close async client connection in ASIO?

I'm trying to create a client for the C++ 20 server example, the one that uses coroutines. I'm not quite sure how I'm supposed to close the client connection. As far as I'm aware, there are two ways: #1 This one seems to be closing it once it's…
nop
  • 4,711
  • 6
  • 32
  • 93