boost-asio

Why would we need many acceptors in the Boost.ASIO?

大城市里の小女人 提交于 2019-12-09 23:57:39
问题 As known, we can use multiple acceptors in boost::asio. boost::asio::io_service io_service_acceptors; std::vector<boost::thread> thr_grp_acceptors; unsigned int thread_num_acceptors = 2; for(size_t i = 0; i < thread_num_acceptors; ++i) { thr_grp_acceptors.emplace_back( boost::bind(&boost::asio::io_service::run, &io_service_acceptors)); But is there any sense in doing io_service_acceptors more than 1? Boost.ASIO uses optimal non-blocking demultiplexing mechanism (epoll, IOCP, ...). Also even

C++ Multithreaded server help

拥有回忆 提交于 2019-12-09 19:17:51
问题 I'm working on a multithreaded server in c++ using boost-asio. Currently a design problem I'm running into deals with erasing a connection. I have a single server instance which holds a vector of connection objects. These connections receive commands which I parse. One command in particular deals with sending data to ALL connections in my vector. Now when a connection disconnects I'm currently erasing this connection from the vector and calling the destructor. It seems like I'm going to run

Mocking an entire library

青春壹個敷衍的年華 提交于 2019-12-09 18:27:24
问题 I'm developing code that uses boost::asio . To test it, I need to mock a set of classes from this library. I'm using Google Mock, which allows for mocking virtual methods. The usual (and tedious) process would be to write an interface for each of the classes I need to use. On the other hand, the Google Mock Cookbook describes an alternative when it comes to mocking non-virtual methods: using templates. The problem in my case is that I might need to mock several classes at the same time (so

boost::asio async condition

无人久伴 提交于 2019-12-09 18:10:37
问题 The idea is to be able to replace multithreaded code with boost::asio and a thread pool, on a consumer/producer problem. Currently, each consumer thread waits on a boost::condition_variable - when a producer adds something to the queue, it calls notify_one / notify_all to notify all the consumers. Now what happens when you (potentially) have 1k+ consumers? Threads won't scale! I decided to use boost::asio , but then I ran into the fact that it doesn't have condition variables. And then async

How do it clear all posted tasks which already queued in a strand?

自作多情 提交于 2019-12-09 13:35:10
问题 How do it clear all posted tasks which already queued in a io_service::strand ? I see no similar method from boost document. 回答1: I have yet to find a need for it, as it can be resolved correctly with properly designing the asynchronous call chains. Generally, the Boost.Asio API is carefully designed in such a way that it prevents complex applications from becoming complicated in the asynchronous flow. If you have examined the call chains, and are absolutely certain that the effort to

How do I create a Boost.Asio Server that can handle multiple clients at once?

 ̄綄美尐妖づ 提交于 2019-12-09 07:58:56
问题 I can create a simple TCP server that can respond to one client, but I don't know how to create a server that can handle multiple clients at once. I have referred to examples like TCP daytime async server, but it just sends the data to client. What I need to create is keep alive the connection as long as client exists. Both Client and Server will communicate in Json. Consider one case where client will give {"hello":"Client"} and server should respond {"Hello":"Server"} , and say another {

What's the difference between WaitForMultipleObjects and boost::asio on multiple windows::basic_handle's?

谁都会走 提交于 2019-12-09 06:28:39
问题 I have a list of HANDLE's, controlled by a lot of different IO devices. What would be the (performance) difference between: A call to WaitForMultipleObjects on all these handles async_read on boost::windows::basic_handle's around all these handles Is WaitForMultipleObjects O(n) time complex with n the amount of handles? You can somehow call async_read on a windows::basic_handle right? Or is that assumption wrong? If I call run on the same IO device in multiple threads, will the handling-calls

boost::asio, threads and synchronization

三世轮回 提交于 2019-12-09 04:55:33
问题 This is somewhat related to this question, but I think I need to know a little bit more. I've been trying to get my head around how to do this for a few days (whilst working on other parts), but the time has come for me to bite the bullet and get multi-threaded. Also, I'm after a bit more information than the question linked. Firstly, about multi-threading. As I have been testing my code, I've not bothered with any multi-threading. It's just a console application that starts a connection to a

LNK2019 when including asio headers, solution generated with cmake

戏子无情 提交于 2019-12-09 04:55:06
问题 I am trying to port a big project from gcc (Linux) to msvc (windows), using cmake and boost libraries. The project compile and runs fine for gcc but on msvc it returns the following error: Dyna.obj : error LNK2019: unresolved external symbol "void __cdecl boost::throw_exception(class std::exception const &)" (?throw_exception@boost@@YAXABVexception@std@@@Z) referenced in function "void __cdecl boost::asio::detail::do_throw_error(class boost::system::error_code const &,char const *)" (?do

Asynchronous Mysql connector

人盡茶涼 提交于 2019-12-09 04:08:35
问题 Do any asynchronous connectors exist for Mysql that can be used within a C or C++ application? I'm looking for something that can be plugged into a reactor pattern written in Boost.Asio. [Edit:] Running a synchronous connector in threads is not an option. 回答1: http://forums.mysql.com/read.php?45,183339,183339 enjoy Updated link to the original article showing how to do async mysql queries: http://jan.kneschke.de/projects/mysql/async-mysql-queries-with-c-api/ 回答2: I had a similar problem with