boost-asio

Boost ASIO: recovering from handler exceptions

亡梦爱人 提交于 2019-12-11 06:43:41
问题 If an ASIO callback throws an error is it safe to resume the async processing? In short, does the following code have any merit? void runAsioLoop() { boost::asio::io_service::work work(this->m_ioService); boost::system::error_code unused; while (m_running) { try { this->m_ioService.run(unused); this->m_ioService.reset(); } catch (...) { std::cerr << "*** An error happened\n"; } } } 回答1: It should work, but the better idiom is: for (;;) { try { svc.run(); break; // exited normally } catch (std

boost::asio::ssl linking errors in Xcode 4

烂漫一生 提交于 2019-12-11 05:31:36
问题 I have a simple project in Xcode—it doesn't actually do anything yet, just includes boost::asio::ssl : // main.cpp #include <iostream> #include <string> #include <boost/asio.hpp> #include <boost/asio/ssl.hpp> using namespace std ; int main (int argc, const char * argv [] ) { return 0 ; } I have it linked with libssl.dylib and libboost_system.dylib , and get this when building: Undefined symbols for architecture x86_64: "_CONF_modules_unload", referenced from: boost::asio::ssl::detail::openssl

BOOST ASIO multi-io_service RPC framework design RFC

安稳与你 提交于 2019-12-11 05:29:49
问题 I am working on a RPC framework, I want to use a multi io_service design to decouple the io_objects that perform the IO (front-end) from the the threads that perform the RPC work (the back-end). The front-end should be single threaded and the back-end should have a thread pool. I was considering a design to get the front-end and back-end to synchronise using a condition variables. However, it seems boost::thread and boost::asio do not comingle --i.e., it seems condition variable async_wait

Can Asio be used without boost or C++11?

旧街凉风 提交于 2019-12-11 04:48:14
问题 I'm looking at libraries to help build a scalable tcp/ip server, and Boost::ASIO looks pretty nice to make async socket i/o work homogeneously across platforms (We need to support at least OSX, Linux x86, and Windows, probably Solaris, maybe HP-UX & AIX). Management is dead-set against using Boost in our product, mostly due to it being 'bloated', and due to issues we've had in the past with conflicts, as our code gets statically linked with customer code (which may also be using boost,

boost::asio::strand && boost::lockfree::spsc_queue

依然范特西╮ 提交于 2019-12-11 04:32:40
问题 If I am running a single an boost::asio::io_service with a thread pool and wrapping a particular socket receive using a boost::asio::strand to simulate single threaded operation, does anyone know if the strand meets the requirements to safely produce to a boost::lockfree::spsc_queue even though I will be producing from different threads but guaranteed to only produce one at a time. 回答1: Yes. Serialization through a strand guarantees what you are after. To extend this a little bit, if you have

How to use boost::asio::io_service::run_one()

一世执手 提交于 2019-12-11 04:32:02
问题 I was reading up on boost::asio::io_service::run_one() and am confused by what it means by the function block. What has been blocked and where is the handler defined? 回答1: I was reading up on boost::asio::io_service::run_one() and am confused by what it means by the function block. What has been blocked Blocked means run_one() blocks until it completes one handler. and where is the handler defined? It isn't. Logically it's described in the documentation. A handler is whatever action is

Broken pipe after writing to socket

為{幸葍}努か 提交于 2019-12-11 04:18:09
问题 In my network library I can do asynchronous writes to the network if I run() and restart() the io_context manually. I'm now trying to make things scale by adding a thread pool: .hpp struct pool : public std::enable_shared_from_this<pool> { pool(const pool &) = delete; auto operator=(const pool &) -> pool & = delete; explicit pool(pool_parameters config, db_parameters params) noexcept; asio::io_context m_io_context; asio::thread_pool m_workers; asio::executor_work_guard<asio::io_context:

Why value captured by reference in lambda is broken? [duplicate]

我怕爱的太早我们不能终老 提交于 2019-12-11 04:02:14
问题 This question already has answers here : Can a local variable's memory be accessed outside its scope? (20 answers) Closed 4 years ago . Repeatable example: #include <iostream> #include <boost/asio/io_service.hpp> boost::asio::io_service io_service; void test1(int t_a) { std::cout << "in test1: t_a = " << t_a << std::endl; } void test2(int t_a) { std::cout << "in test2: t_a = " << t_a << std::endl; io_service.post([&t_a]() { std::cout << "in test2 post lambda: t_a = " << t_a << std::endl;

Could not find the following Boost libraries: boost_asio

流过昼夜 提交于 2019-12-11 03:59:57
问题 When I try to compile my cmake project, which uses boost and asio, with make I get these errors: CMakeFiles/client-network-handler-test.dir/main.cpp.o: In function `__cxx_global_var_init1': /usr/include/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()' CMakeFiles/client-network-handler-test.dir/main.cpp.o: In function `__cxx_global_var_init1': /usr/include/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()'

boost::asio async_write complex structure

家住魔仙堡 提交于 2019-12-11 03:39:14
问题 Whats the best way to send a complex structure using boost's asio async_write ... Any suggestions? Thanks! 回答1: You'll need to serialize the structure, some options include Boost.Serialization Google Protocol Buffers I've answered several similar questions when using Boost.Serialization with Boost.Asio, here is one that may be useful to you. 来源: https://stackoverflow.com/questions/5599302/boostasio-async-write-complex-structure