Reputation: 4405
I am using boost::asio::ip::udp::socket
to communicate. I use socket.receive_from(...)
to receive messages from clients. This is working fine for now, but I want to be able to shut down my server. Right now I am calling receive_from
in a while-loop, which depends on a bool condition which I can set. However, this is pretty useless if I cannot force the thread to exit receive_from
at regular intervals or at a certain call.
Is this even possible? I have tried googling, but found no clear answer. I have tried using socket.cancel()
but this seems to have no effect.
Am I using the socket in the correct way?
Upvotes: 1
Views: 2196
Reputation: 24184
There's no good way to do what you want using the synchronous receive_from
method. You should use the asynchronous async_receive_from
method if you desire timeouts and cancelability. There's a ticket on the Boost.Asio trac website describing this.
I answered a similar question recently that you might find useful as well.
Upvotes: 3