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.

Most programs interact with the outside world in some way, whether it be via a file, a network, a serial cable, or the console. Sometimes, as is the case with networking, individual I/O operations can take a long time to complete. This poses particular challenges to application development. The Boost.Asio library is intended for programmers using C++ for systems programming, where access to operating system functionality such as networking is often required.

More information on Boost.Asio can be found here:

Notable alternatives for Boost.Asio:

4582 questions
11
votes
1 answer

boost::asio read n bytes from socket to streambuf

I have a serialized structure, which is being sent via socket. I need to read it in chunks, since one of its fields contains the size of the data remaining: I need to read first few bytes, find out the length and read the rest. This is what I have…
11
votes
3 answers

Can boost::asio only receive full UDP datagrams?

I am working on a UDP server built with boost::asio and I started from the tutorial customizing to my needs. When I call socket.receive_from(boost::asio::buffer(buf), remote, 0, error); it fills my buffer with data from the packet, but, if my…
Kjir
  • 4,437
  • 4
  • 29
  • 34
11
votes
2 answers

Why does Boost.Asio not support an event-based interface?

I am attempting to understand Boost.Asio, with the intention of potentially implementing a signaling system using condition variables in conjunction with Boost.Asio. I have seen the other StackOverflow questions boost asio asynchronously waiting on…
Dan Nissenbaum
  • 13,558
  • 21
  • 105
  • 181
11
votes
3 answers

Using boost::asio thread pool for general purpose tasks

In this blog I found a pretty neat example on how to create a simple thread pool using boost::asio. I basically want to use it like this: #include #include #include int main ( int argc, char* argv[] ) { …
Haatschii
  • 9,021
  • 10
  • 58
  • 95
11
votes
3 answers

boost:asio thread pool implementation for occasionally synchronized tasks

I have a "main" function that performs many small, independent tasks each once per time step. However, after each time step, I must wait for all of the tasks to complete before stepping forward. I want to make the program multithreaded. I have tried…
John Doe
  • 301
  • 3
  • 11
11
votes
2 answers

How should one tear down a boost::asio::ip::udp::socket?

I have read the boost asio reference, gone through the tutorial and looked at some of the examples. Still, I am unable to see how a socket should be torn down: Should I call close() or is this done by the socket's destructor? When should I call…
Torleif
  • 2,334
  • 3
  • 27
  • 28
10
votes
3 answers

boost:asio IPv4 address and UDP comms

Problem Solved - See bottom for solution notes I'm trying to build a simple app to test an ethernet-capable microcontroller. All I want to do is send and receive small UDP packets. The code is using boost::asio for the networking, and is incredibly…
OcularProgrammer
  • 482
  • 2
  • 5
  • 19
10
votes
2 answers

How to decipher a boost asio ssl error code?

I've got an occasional communications failure in a boost asio ssl implementation, the super helpful error message returned by boost is 'asio.ssl:336458004' I suspect that the numerical figure is some sort of aggregate construct composed of SSL…
Gearoid Murphy
  • 11,834
  • 17
  • 68
  • 86
10
votes
3 answers

How to asynchronously read input from command line using boost asio in Windows?

I found this question which asks how to read input asynchronously, but will only work with POSIX stream descriptors, which won't work on Windows. So, I found this tutorial which shows that instead of using a POSIX stream descriptor I can use a…
nickb
  • 59,313
  • 13
  • 108
  • 143
10
votes
1 answer

Sending raw data with write() in boost::asio

I've recently decided to use boost::asio for my sockets, but now I'm running into a problem: documentation seems to be lacking. What I want to do is write a function that will send a message consisting of the following structure: 2 bytes of an…
Josh1billion
  • 14,837
  • 8
  • 38
  • 48
10
votes
3 answers

Who uses Boost ASIO?

I would like to know how popular is Boost ASIO. Is it being used in any popular network-intensive software ?
Suresh
10
votes
5 answers

Payload split over two TCP packets when using Boost ASIO, when it fits within the MTU

I have a problem with a boost::asio::ip::tcp::iostream. I am trying to send about 20 raw bytes. The problem is that this 20 byte payload is split into two TCP packets with 1 byte, then 19 bytes. Simple problem, why it is happening I have no idea. I…
xconspirisist
  • 1,451
  • 2
  • 13
  • 26
10
votes
2 answers

Is boost::io_service::post thread safe?

Is it thread safe to post new handlers from within a handler? I.e. Can threads that called the io_service::run() post new Handlers to the same io_service? Thanks
Johannes Gerer
  • 25,508
  • 5
  • 29
  • 35
10
votes
2 answers

Force boost::asio::buffer to copy by value

I use boost::asio::buffer to send a message using void Send(const std::string& messageData) { socket.async_write(boost::asio::buffer(messageData), ...); } And encounter "string iterator not dereferencable" runtime error somewhere within…
Slaus
  • 2,086
  • 4
  • 26
  • 41
10
votes
3 answers

using boost sockets, do I need only one io_service?

having several connections in several different threads.. I'm basically doing a base class that uses boost/asio.hpp and the tcp stuff there.. now i was reading this:…
grich
  • 463
  • 3
  • 6
  • 14