I want to remove all handlers from an IO_service right before I reuse it. Is this possible?
I\'m writing unit tests that involve an asio::io_service
.
Well, I racked my brain on this for a few days and came up with a workable solution. It's the mother of all hacks.
void clear( boost::asio::io_service& service )
{
service.stop();
service.~io_service();
new( &service ) boost::asio::io_service;
}
I'm not sure how safe this would be for productions code. But so far it seems to work (no segfaults, no weird behavior).