Category : boost-asio

Here’s a simplified version of my problem. I’m using boost::asio, and I have a function that processes some data passed into it, but I want to delay that processing by 5 seconds. This is how I’ve implemented it. void process_later(boost::asio::io_service& io, const std::string& data) { auto timer = std::make_shared<boost::asio::steady_timer>(io); timer->expires_from_now(std::chrono::seconds(5)); timer->async_wait( [timer,data](const boost::system::error_code&) { std::cout ..

Read more

Is that possible to construct a boost::beast::http::message (specifically I have to construct a boost::beast::http::response<bb_http::string_body>) from std::string, std::string_view or other raw buffer? Maybe there is some kind of parser? From what I see in boost beast samples, we can either: receive a response from boost::beast::read* functions. In that case the first argument should be a SyncReadStream, ..

Read more

In the main thread, I’m creating 8 std::threads in a loop. All these threads will ultimately call _ios.run() // _ios is per thread. In the Class definition: boost::asio::io_service _ios; boost::optional<boost::asio::io_service::work> _work; std::thread _thread; Class c’tor: { _work = boost::in_place(boost::ref(_ios)); _thread = std::thread{[this] () { setup_a_few_stuffs(); _ios.run(); } }; } In the main thread, I would ..

Read more

Consider the following code (Boost 1.76 / Asio 1.18.2): #include <chrono> #include <iostream> #include <thread> #include <boost/asio.hpp> namespace asio = boost::asio; int main() { boost::system::error_code ec; asio::io_service ios; asio::ip::tcp::endpoint ep; asio::ip::tcp::acceptor acc(ios); acc.open(ep.protocol(), ec); acc.bind(ep, ec); acc.listen(); asio::ip::tcp::socket sock(ios); acc.accept(sock); std::this_thread::sleep_for(std::chrono::seconds(2)); auto str = std::string{"hello"}; sock.write_some(asio::buffer(str), ec); std::cout << ec.message() << std::endl; // further write_some ..

Read more

I’ve set up a little asio client test project to try find out why my asio read routine only functions correctly first time: int main(int argc, char* argv[]) { Network network; network.connect("google.com"); network.request("/search?q=test+search"); network.connect("example.com"); network.request("/index.html HTTP/1.1"); while (1) {} return 0; } It’s suppose to allow connecting to a site and then performing requests and ..

Read more

I am having a boost::asio::ip::udp::endpoint on boost::asio::ip::address_v6::any() (INADDR_ANY) and some port (let’s say 20000). Two UDP sockets now get bound to that endpoint with each subsequently joining a distingct IPv6 multicast group (let’s say ff02::a and ff02::b) on all external network interfaces by setting the option boost::asio::ip::multicast::join_group multiple times for the respective multicast IPv6 and ..

Read more