Category : boost

Imagine, you want to use Boost’s boost::log::sources::severity_logger with an endpoint that accepts std::string messages plus an unsigned int severity level. Something like a pimped version of OutputDebugString() in the Win32 API. boost::log is quite handy because of it’s built in filtering, the stream insertion operator it supports and the possibility to subscribe more than one ..

Read more

Complete noob here learning c++ through an IoT project using Websocket. So far, somewhat successfully modified this example beast async_client_ssl to handshake with a server. My problem is ioc.run() runs out of work and exits after the initial callback. I was having the same issue as this post two years ago. Boost.best websocket ios.run() exits ..

Read more

I have a fairly simple use case. I would like to read from a boost socket using boost::asio::read, but with a timeout for the read call. I.e. If nothing nothing is read from the socket in 5 seconds, the call should terminate/throw-an-error/whatever. The code without a timeout is shown below: Json::Value Client::MakeRequest(const std::string &ip_addr, unsigned ..

Read more

Why boost::shared_mutex cannot block more than 128 threads? Is this a well-known issue? boost1.67+mscv2015 boost::shared_mutex mutex; for (int i = 0; i < 256; i++) { std::thread([&]() { printf("beginn"); { //crash after 128 times boost::unique_lock<boost::shared_mutex> lock(mutex); Sleep(5000); } printf("endn"); }).detach(); } Sleep(5000); Source: Windows Que..

Read more

I’m trying to get boost::multiprecision to parse a negative (two’s complement) hex number: #include <iostream> #include <boost/multiprecision/cpp_int.hpp> int main(int argc, char* argv[]) { std::string hex_str = "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffb2e"; boost::multiprecision::int256_t signed_int(hex_str); std::cout << signed_int << std::endl; } I expect this to output -1234. Unfortunately, it outputs 115792089237316195423570985008687907853269984665640564039457584007913129638702 Parsing an unsigned hex number works fine. How can I ..

Read more

I tried to compile a project but it failed with the following error: Build Error Below is the code in my project: boost::system::error_code ec; auto endpoints = resolver->resolver().resolve(ip_address, std::to_string(port)), ec); if (ec) return; // Connect to server boost::asio::ip::tcp::endpoint m_endpoint; m_endpoint = *(boost::asio::connect(_socket, endpoints.begin(), endpoints.end(), ec)); The problem occurs in the call to boost::asio::connect function. By ..

Read more