boost-asio

Why does Boost.Asio not support an event-based interface?

此生再无相见时 提交于 2019-11-27 07:31:12
I am attempting to understand Boost.Asio, with the intention of potentially implementing a signaling system using condition variables in conjunction with Boost.Asio. I have seen the other StackOverflow questions boost asio asynchronously waiting on a condition variable , boost::asio async condition , and boost condition variable issue , but none of these questions/answers have satisfactorily touched on an essential question that I have: Is it true that, and/or is there a fundamental reason why, Boost.Asio is not applicable to, or a natural fit with, condition variables? My thinking is that

Gracefully terminate a Boost Asio based Windows console application

雨燕双飞 提交于 2019-11-27 07:23:24
问题 I am working on a boost.asio based HTTP server. It is supposed to be stopped externally. We use asio signal handling, and it works well for ctrl-c, but does not handle WM_CLOSE, so there is no straightforward way to gracefully close the application externally, e.g. via taskkill. Terminating the process forcibly is not an option. Is there a known approach to this? 回答1: Update Just use any IPC method you would "normally" use Write a simple process control utility that uses e.g. named_condition

Is calling asio io_service poll() or poll_one() in a nested or recursive fashion (ie. within a handler) valid?

℡╲_俬逩灬. 提交于 2019-11-27 07:03:42
问题 Is calling asio::io_service::poll() or poll_one() in a nested or recursive fashion (ie. from within a handler) valid? A really basic test seems to imply that this works (I've only done the test on one platform) but I want to be sure that calling poll() again from within a handler is considered valid behavior. I couldn't find any relevant information in the asio docs, so I'm hoping that someone with a bit more experience with asio's inner workings could verify this with an explanation or

boost::asio and Active Object

大憨熊 提交于 2019-11-27 07:01:24
I have implemented some module based Active Object design pattern. It is very simple implementation. I have Scheduler, ActivationList, Requests and Futures to get response. My requirements were like that: Access to active object shall be serialized by executing its methods within its own thread (main req and assumption of Active Object design pattern) Caller shall be able to specify the priority of requests execution. It means that if there is more than zero requests waiting for execution, they shall be ordered by the priority assigned to each request. Requests with higher priority shall be

How to set error_code to asio::yield_context

倾然丶 夕夏残阳落幕 提交于 2019-11-27 06:35:10
问题 I'd like to create an asynchronous function which takes as it's last argument boost::asio::yield_context. E.g.: int async_meaning_of_life(asio::yield_context yield); I'd also like to be consistent with how Asio returns error codes. That is, if the user does: int result = async_meaning_of_life(yield); and the function fails, then it throws the system_error exception. But if the user does: boost::error_code ec; int result = async_meaning_of_life(yield[ec]); Then - instead of throwing - the

sending/receiving a struct in boost::asio

可紊 提交于 2019-11-27 06:32:29
问题 I was going to send a struct from a client to a server using boost::asio::async_write_some , in this case boost::serialization and boost::property_tree come to help, //boost::serialization struct blank { int m_id; std::string m_message; template<typename archive> void serialize(archive& ar, const short version) { ar & m_id; ar & m_message; } }; blank info; info.m_id = 1; info.m_name = "Rasul"; std::stringstream ss; boost::archive::binary_oarchive out_archive(ss); out_archive << info; So, now

How to launch an “event” when my Boost::asio tcp server just start running ( AKA io_service.run() )?

冷暖自知 提交于 2019-11-27 06:31:41
问题 Based on an boost::asio client/server relationship, I have to launch the client program from the server program only when the server thread is in a " waiting to be connected " state. My question is how to have the knowledge of that state ? As a sample use the asio example/serialization link, and replace the main function of server.cpp with that code: #include <conio.h> #include <concrt.h> // wait function #include <future> #include <thread> void server_thread( std::promise<bool>& run ) {

Using boost::asio::async_read with stdin?

二次信任 提交于 2019-11-27 05:54:08
问题 short question: I have a realtime-simulation which is running as a backround process and is connected with pipes to the calling pogramm. I want to send commands to that process using stdin to get certain information from it via stdout. Now because it is a real-time process, it has to be a non blocking input. Is boost::asio::async_read in conjunction with iostream::cin a good idea for this task? how would I use that function if it is feasible? Any more suggestions? 回答1: Look at boost::asio:

What's the difference between boost::io_service poll_one and run_one?

我只是一个虾纸丫 提交于 2019-11-27 05:52:34
问题 io_service::poll_one Run the io_service object's event processing loop to execute one ready handler. vs io_service::run_one Run the io_service object's event processing loop to execute at most one handler. From that explanation it would seem poll_one could execute more than one handler? Does run_one or poll_one use any thread that's called run() or only the thread that calls poll_one/run_one? The documentation for ASIO is very sparse. 回答1: poll_one will return immediately (non-blocking) in

C++ Boost ASIO: how to read/write with a timeout?

二次信任 提交于 2019-11-27 05:36:37
问题 From reading other Stack Overflow entries and the boost::asio documentation, I've confirmed that there is no synchronous ASIO read/write calls that also provide an easy-to-use timeout as a parameter to the call. I'm in the middle of converting an old-school Linux socket application with select(2) calls that employs timeouts, and I need to do more-or-less the same. So what is the best way to do this in boost::asio ? Looking at the asio documentation, there are many confusing examples of