I am using the excellent asio for an asynchronous network client. When handling read (async_read) I am concerned that the method/function handling the data might hang or take too long (the function is supplied by the user of the class).
What is the best way of calling the supplied function and ensuring it won’t take too long ?
Thank you for your time.
You could write a wrapper function which launches the given handler in a separate thread and does a timed_join on it. If the timeout reaches, you could throw an exception or do whatever else you want.