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
17
votes
3 answers

Segfault with asio standalone when classes in separate files

The below is as minimal of an example as I can get. It does need to be in separate files as that seems to be what causes the segmentation fault error. I'm using Mingw x32 4.8.1 with Asio standalone 1.10.6 . I've also tested with TDM GCC 4.7.1 and…
NeomerArcana
  • 1,978
  • 3
  • 23
  • 50
17
votes
2 answers

Which boost libraries are heading for TR2?

If found this quote at boost.org: More Boost libraries are in the pipeline for TR2 It links to the TR2 call from proposals. But I can't seem to find any other information on which boost libraries are headed for TR2. I've seen a draft proposal for…
deft_code
  • 57,255
  • 29
  • 141
  • 224
17
votes
2 answers

Is there any way to asynchronously wait for a future in Boost Asio?

My problem is the following. I start several operations asynchronously, and I want to continue until all of them are finished. Using Boost Asio, the most straightforward way to do this is the following. Suppose tasks is some kind of container of…
petersohn
  • 11,292
  • 13
  • 61
  • 98
17
votes
1 answer

boost::asio::deadline_timer with std::chrono time values

I have an application that uses asio deadline timers. The rest of the application uses std::chrono constructs for its time values, and it feels awkward to use boost::posix_time for only the stuff that touches asio. I'd like to use std::chrono…
John S
  • 3,035
  • 2
  • 18
  • 29
17
votes
1 answer

Chaining asynchronous Lambdas with Boost.Asio?

I find myself writing code that basically looks like this: using boost::system::error_code; socket.async_connect(endpoint, [&](error_code Error) { if (Error) { print_error(Error); return; } // Read header …
ltjax
  • 15,837
  • 3
  • 39
  • 62
16
votes
1 answer

Boost ASIO: SSL handshake() never finishes

I have a C++ client app that uses Boost ASIO to make SSL connections to various servers. But against 2 specific servers, the SSL connection cannot be established. It hangs in the call to boost::asio::ssl::stream::handshake(). I've used Wireshark to…
Stéphane
  • 19,459
  • 24
  • 95
  • 136
16
votes
2 answers

Getting to know the basics of Asynchronous programming on *nix

For some time now I have been googling a lot to get to know about the various ways to acheive asynchronous programming/behavior on nix machines and ( as known earlier to me ) got confirmed on the fact that there is still no TRULY async pattern…
Arunmu
  • 6,837
  • 1
  • 24
  • 46
16
votes
3 answers

Boost Asio message_flags

I recently began working with Boost Asio. I noticed that the receive method of a TCP socket accepts a message_flags as a parameter. However, the documentation I found for message_flags only says that it is an integer without specifying the valid…
Brian
  • 1,201
  • 2
  • 14
  • 26
16
votes
4 answers

Boost asio socket: how to get IP, port address of connection?

I have a TCP server using boost asio. I have accepted a socket connection. How to get IP, Port of machine my server is communicating with? BTW: Is it possible to get info on what ip that connected server user sees my server4 machine?
Rella
  • 65,003
  • 109
  • 363
  • 636
16
votes
2 answers

Can boost::asio::thread_pool be used instead of combining boost::asio::io_context with a boost::thread::thread_group?

I'm trying to clear up some confusion I have. I stumbled over boost::asio::thread_pool and I thought that one could use to somehow automatically combine boost::asio::io_context and boost::thread::thread_group like is often suggested (here or here).…
screwnut
  • 1,367
  • 7
  • 26
16
votes
2 answers

standard way to perform a clean shutdown with Boost.Asio

I'm writing a cross-platform server program in C++ using Boost.Asio. Following the HTTP Server example on this page, I'd like to handle a user termination request without using implementation-specific APIs. I've initially attempted to use the…
Timothy003
  • 2,348
  • 5
  • 28
  • 33
16
votes
1 answer

Boost.Asio: Operation Cancelled on async_read

Another one in the continuing saga of myself vs. Boost.Asio... I have a simple asynchronous client and server that utilise async_write and async_read to communicate. The client can successfully write bytes to the socket, but the server never sees…
kfb
  • 6,252
  • 6
  • 40
  • 51
16
votes
5 answers

boost shared_from_this<>()

could someone summarize in a few succinct words how the boost shared_from_this<>() smart pointer should be used, particularly from the perspective of registering handlers in the io_service using the bind function. EDIT: Some of the responses have…
Gearoid Murphy
  • 11,834
  • 17
  • 68
  • 86
16
votes
2 answers

Why capture this as well as shared-pointer-to-this in lambdas?

In the Boost.asio C++11 examples there are snippets like the following: void do_read() { auto self(shared_from_this()); socket_.async_read_some(boost::asio::buffer(data_, max_length), [this, self](boost::system::error_code ec, std::size_t…
dshepherd
  • 4,989
  • 4
  • 39
  • 46
16
votes
2 answers

How to detect when a boost tcp socket disconnects

Suppose I have a socket: std::shared_ptr socket( new tcp::socket(acceptor.get_io_service()) ); acceptor.async_accept( *socket, std::bind( handleAccept, this, std::placeholders::_1, socket, std::ref(acceptor)) ); And I store a weak_ptr…
aCuria
  • 6,935
  • 14
  • 53
  • 89