[Boost::asio] Problem using the same io_service with many sockets
Hi all, I have defined an io_service that is used by two sockets, one of them uses tcp, and the other udp. When the callback of this async_read_some is called socket.async_read_some(boost::asio::buffer(readBuffer), boost::bind(&RequestHandler::onRead, shared_from_this(), boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); A udp socket is created with the same io_service and an async_receive_from is called. On the callback of this read operation I try to write to the tcp socket but it captures an exception with message: "unknown exception". When this happens, the client that is listening to the tcp socket, receives "End of file" error. I resolved this problem with an io_service per socket but I would like to use the same io_service. Someone has any idea why this happens? Thanks! Victoria
Hey Victoria,
On 30 September 2016 at 20:16, María Victoria Rocha
Hi all,
I have defined an io_service that is used by two sockets, one of them uses tcp, and the other udp.
When the callback of this async_read_some is called
socket.async_read_some(boost::asio::buffer(readBuffer), boost::bind(&RequestHandler::onRead, shared_from_this(), boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
A udp socket is created with the same io_service and an async_receive_from is called. On the callback of this read operation I try to write to the tcp socket but it captures an exception with message: "unknown exception".
When this happens, the client that is listening to the tcp socket, receives "End of file" error.
I resolved this problem with an io_service per socket but I would like to use the same io_service.
Someone has any idea why this happens?
Do you have a minimal working example that demonstrates the problem? In general it should be fine to use the same io_service with different sockets, so I suspect the problem lies somewhere else. A minimal example showing the problem will help a lot in tracking down the problem. One thing though: if you don't catch the exception (or call std::terminate() in the handler) you should see more details regarding the exception (at least the type of the exception, but more if it inherits from std::exception). That may be enough to point you to the problem already. Cheers, Maarten
participants (2)
-
Maarten de Vries
-
María Victoria Rocha