Boost asio thread_pool join does not wait for tasks to be finished

The best practice is not to reuse the pool (what would be the use of pooling, if you keep creating new pools?). If you want to be sure you “time” the batches together, I’d suggest using when_all on futures: Live On Coliru #define BOOST_THREAD_PROVIDES_FUTURE_WHEN_ALL_WHEN_ANY #include <iostream> #include <boost/bind.hpp> #include <boost/asio.hpp> #include <boost/thread.hpp> uint64_t foo(uint64_t begin) … Read more

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

Boost.Asio is a C++ library for network and low-level I/O programming. As such, OS-level synchronization objects, such as condition variables, are outside of the scope of the library, and a much better fit for Boost.Thread. The Boost.Asio author often presents the boost::asio::io_service as the bridge or link between the application and the OS. While this … Read more

Strange exception throw – assign: Operation not permitted

Boost.Asio’s POSIX stream-oriented descriptors explicitly do not support regular files. Hence, if test is a regular file, then ./client < test will result in posix::stream_descriptor::assign() failing when attempting to assign STDIN_FILENO to the stream_descriptor. The documentation states: Boost.Asio includes classes added to permit synchronous and asynchronous read and write operations to be performed on POSIX … Read more

asio How to change the executor inside an awaitable?

You want to associate your executor with the completion token, and then let post/dispatch/defer figure it out from there: co_await asio::post(bind_executor(pstrand, asio::use_awaitable)); See also e.g. When must you pass io_context to boost::asio::spawn? (C++) or boost::asio::bind_executor does not execute in strand for more details on how it works/why it works/when it works. It does in fact … Read more

boost::asio with boost::unique_future

Boost.Asio only provides first-class support for asynchronous operations to return a C++11 std::future or an actual value in stackful coroutines. Nevertheless, the requirements on asynchronous operations documents how to customize the return type for other types, such as Boost.Thread’s boost::unique_future. It requires: A specialization of the handler_type template. This template is used to determine the … Read more

Boost.Asio as header-only

AFAIK you can get the non-boost version of asio from http://think-async.com/Asio/AsioAndBoostAsio “— Boost.Asio uses the Boost.System library to provide support for error codes ( boost::system::error_code and boost::system::system_error). Asio includes these under its own namespace ( asio::error_code and asio::system_error). The Boost.System version of these classes currently supports better extensibility for user-defined error codes. — Asio is … Read more

Exception running boost asio ssl example

OK, for anyone finding this in the future, you need to create your certificates and sign them appropriately. Here are the commands for linux: //Generate a private key openssl genrsa -des3 -out server.key 1024 //Generate Certificate signing request openssl req -new -key server.key -out server.csr //Sign certificate with private key openssl x509 -req -days 3650 … Read more

BOOST ASIO – How to write console server

The problem is: How can I attach (or write) console, which can calls above functionalities. This console have to be a client? Should I run this console client as a sepearate thread? You don’t need a separate thread, use a posix::stream_descriptor and assign STDIN_FILENO to it. Use async_read and handle the requests in the read … Read more