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
10
votes
1 answer

'Error while decoding payload' after trying to send second payload

I'm trying to implement a client which connects to a WebSocket (the Discord gateway to be precise) using the websocketpp library, but I'm getting an error when I try to send a JSON payload to the server The code I'm using is: //Standard…
Ben Hollier
  • 585
  • 2
  • 11
  • 32
10
votes
3 answers

Alternative to deprecated get_io_service()

Asio v 1.11. The doc says that basic_stream_socket::get_io_service() member function is deprecated and get_executor() must be used instead. But the latter returns executor not io_service. How to obtain reference to the io_service object used by…
Victor Dyachenko
  • 1,363
  • 8
  • 18
10
votes
2 answers

Boost.Asio wrong local endpoint

code example: #include "stdafx.h" #include #include #include #include int _tmain(int argc, _TCHAR* argv[]) { boost::asio::io_service service; auto sock_ = new…
kain64b
  • 2,258
  • 2
  • 15
  • 27
10
votes
1 answer

Exception handling in Boost.Asio

Boost.Asio documentation suggests the following exception handling pattern: boost::asio::io_service io_service; ... for (;;) { try { io_service.run(); break; // run() exited normally } catch (my_exception& e) { // Deal with…
Alex B
  • 82,554
  • 44
  • 203
  • 280
10
votes
1 answer

How to use boost::asio with Linux GPIOs

I have a single-threaded Linux application using boost::asio for asynchronous input/output. Now I need to extend this application to read in GPIO inputs on /sys/class/gpio/gpioXX/value. It is possible to do that with…
Florian
  • 1,036
  • 10
  • 15
10
votes
2 answers

When do I call boost::asio::streambuf::consume() and boost::asio::streambuf::commit()?

I'm trying to understand the boost::asio::streambuf::consume() and boost::asio::streambuf::commit() calls. In the docs, we have the examples, boost::asio::streambuf b; std::ostream os(&b); os << "Hello, World!\n"; // try sending some data in input…
Ted Middleton
  • 6,859
  • 10
  • 51
  • 71
10
votes
1 answer

Can I read from a socket synchronously using Boost.Asio with a timeout on a multithreaded I/O service?

I have an application that uses Boost.Asio for TCP and UDP socket communications. I understand that the 'A' in "Asio" stands for Asynchronous, so the library is bent toward encouraging you to use asynchronous I/O when possible. I have a few cases…
Jason R
  • 11,159
  • 6
  • 50
  • 81
10
votes
1 answer

dedicated thread for io_service::run()

I want to provide a global io_service that is driven by one global thread. Simple enough, I just have the thread body call io_service::run(). However, that doesn't work as run (run_one, poll, poll_one) return if there is no work to do. But, if…
deft_code
  • 57,255
  • 29
  • 141
  • 224
10
votes
2 answers

Difference between resolving a query and creating an endpoint with IP and port (in boost asio)

I've recently noticed a problem with my application and I think it's due to the fact that I don't use boost::asio properly and don't understand what a tcp resolver does. Basically, I use a boost::asio::ip::tcp::resolver to get endpoints to connect…
0x26res
  • 11,925
  • 11
  • 54
  • 108
10
votes
2 answers

Using futures with boost::asio

Does anyone have a good pointer to examples which use futures from the Boost thread library with Boost ASIO? I have an existing asynchronous library which uses callback function that I would like to provide a friendlier synchronous interface for.
MrEvil
  • 7,785
  • 7
  • 36
  • 36
10
votes
2 answers

When do I have to use boost::asio:strand

Reading the document of boost::asio, it is still not clear when I need to use asio::strand. Suppose that I have one thread using io_service is it then safe to write on a socket as follows ? void Connection::write(boost::shared_ptr msg) { …
user2004360
  • 209
  • 2
  • 3
  • 8
10
votes
1 answer

What's the use of asio::placeholder::error

The asio library passes an error parameter in a lot of its examples, ie; http://think-async.com/Asio/asio-1.5.3/src/examples/echo/async_tcp_echo_server.cpp What's the point of this parameter? Does asio actually populate this parameter with…
kvanbere
  • 3,289
  • 3
  • 27
  • 52
10
votes
3 answers

boost::asio::buffer: Getting the buffer size and preventing buffer overflow?

I have the two following functions for sending and receiving packets. void send(std::string protocol) { char *request=new char[protocol.size()+1]; request[protocol.size()] = 0; memcpy(request,protocol.c_str(),protocol.size()); …
pandoragami
  • 5,387
  • 15
  • 68
  • 116
10
votes
1 answer

how to use asio with device files

I'm using boost asio throughout my project. I now want to read a device file (/dev/input/eventX). In the boost asio documentation it states that normal file IO is not possible but device files or pipes are supported by using…
David Feurle
  • 2,687
  • 22
  • 38
10
votes
2 answers

Google Protocol Buffers - Missing required fields even though all the fields are apparently present

I'm trying to send a protocol buffer message over TCP, but on the receiving side I'm getting a "Missing required fields" error when trying to parse, even though apparently all the fields are there. I'm sending a 4 byte header before the message that…
indiosmo
  • 103
  • 1
  • 2
  • 6