[asio] Is io_service::run() reentrant?
Hi, I cannot figure out from the documentation if I can call io_service::run() from an asynchronous handler, called itsels by run() of the same io_service. If it is possible, should I call reset() or not? I tried and it seems to work under linux, but I need to call run() in a loop as it returns prematurely, even with an io_service::work(), and with/without a reset(). The reason I need to do this is because my asynchronous handlers are calling legacy code that needs to perform synchronous operations. Using synchronous socket operations while this lasts as it was suggested to handle this kind of situations would be possible, but a lot more complicated in my setup. A pseudocode example of what I am trying to do in case I'm not clear: io_service io; tcp::socket s(io); onRead2() { // We got our data, stop inner io::run invocation io.stop(); } onRead(socket& s) { s.write("request"); //we need the result of the request synchronously // I know this looks silly, but it makes more sense in my real-world // use case where the async_read is burried deep. s.async_read(&onRead2); // optional io.reset() here, has no effect. io.run(); // <-- ends prematurely } main() { <connect s > s.async_read(&onRead) io.run(); } Regards, Matthieu
participants (1)
-
bearclaw