boost-asio

joining a thread: “resource deadlock avoided”

帅比萌擦擦* 提交于 2020-07-27 03:34:59
问题 I use a c++ class that encapsulates a boost::asio::io_service . class IoService { public: static IoService& getInstance() { static IoService instance; return instance; } void start() { _ioServiceThread = std::thread(&IoService::run, this); } void stop() { _ioService.stop(); _ioServiceThread.join(); } void run() { _ioService.run(); } private: IoService(); ~IoService(); IoService(const IoService& old) = delete; IoService(const IoService&& old) = delete; IoService& operator=(const IoService& old

joining a thread: “resource deadlock avoided”

a 夏天 提交于 2020-07-27 03:32:45
问题 I use a c++ class that encapsulates a boost::asio::io_service . class IoService { public: static IoService& getInstance() { static IoService instance; return instance; } void start() { _ioServiceThread = std::thread(&IoService::run, this); } void stop() { _ioService.stop(); _ioServiceThread.join(); } void run() { _ioService.run(); } private: IoService(); ~IoService(); IoService(const IoService& old) = delete; IoService(const IoService&& old) = delete; IoService& operator=(const IoService& old

Boost.asio and asynchronous chain, unique_ptr?

纵饮孤独 提交于 2020-07-06 12:24:28
问题 I am not deeply familiar with async programming and I have a question. My question is the following. Given the echo_server example here for C++11 in boost.asio: http://www.boost.org/doc/libs/1_60_0/doc/html/boost_asio/example/cpp11/spawn/echo_server.cpp I would like to know if the std::make_shared<session> can be replaced in C++14 with a std::unique_ptr<session> in C++14, avoiding the overhead of reference count. I am not sure since we have shared_from_this() but not something like unique

boost.asio: async_read/async_write completion handler ordering

↘锁芯ラ 提交于 2020-06-29 05:09:28
问题 Does boost.asio provide any guarantees on completion handler ordering? I have initiated a single async_read & a single async_write operation. I am using the epoll_reactor internally. If the socket becomes both readable & writable simultaneously, will my read (or write) operation and hence completion handler be executed in a particular order always Currently, reading the epoll_reactor.ipp:perform_io, that seems to be the case. But does the ASIO documentation guarantee that? 回答1: There is no

Reading a serialized struct at the receiver end boost asio

老子叫甜甜 提交于 2020-06-28 03:42:23
问题 I am new to boost and networking ;). I am making a client server application with boost::asio, I need to pass structs as messages so used boost::asio::serialization for it : test.h #pragma once #include <boost/archive/binary_oarchive.hpp> #include <boost/serialization/serialization.hpp> struct Test { public: int a; int b; template<typename archive> void serialize(archive& ar, const unsigned version) { ar & a; ar & b; } }; client side sending: void send_asynchronously(tcp::socket& socket) {

Running a process using boost process in async mode with timeout

余生颓废 提交于 2020-06-27 16:35:31
问题 In the following code, I am trying to implement a program that runs a shell command and get the stdio , stderr and return code. I am doing it using boost process in the async mode as advised here. namespace bp = boost::process; class Process { public: Process(std::string & cmd, const int timeout); void run(); private: void timeout_handler(); const std::string command; const int timeout; bool killed; bool stopped; std::string stdOut; std::string stdErr; int returnStatus; boost::asio::io

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

浪尽此生 提交于 2020-06-25 22:52:48
问题 Consider the functions #include <iostream> #include <boost/bind.hpp> #include <boost/asio.hpp> void foo(const uint64_t begin, uint64_t *result) { uint64_t prev[] = {begin, 0}; for (uint64_t i = 0; i < 1000000000; ++i) { const auto tmp = (prev[0] + prev[1]) % 1000; prev[1] = prev[0]; prev[0] = tmp; } *result = prev[0]; } void batch(boost::asio::thread_pool &pool, const uint64_t a[]) { uint64_t r[] = {0, 0}; boost::asio::post(pool, boost::bind(foo, a[0], &r[0])); boost::asio::post(pool, boost: