I use boost.asio async read data, if handle_read takes a lot of time (such as sleep), does it affect other connections?
I use boost.asio async read data, if handle_read takes a lot of time (such
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you execute
io_service::runin one thread, the completion handlers of all the i/o objects associated with thatio_serviceare invoked sequentially. So, if one of them takes too much time, all the queue gets stuck.To prevent this situation, you can either re-design this completion handler, or associate the i/o object having problematic handlers with its own dedicated
io_servicerunning in a separate thread.(Note that running a single
io_serivcein multiple threads wouldn’t solve this problem, as you can’t know how the handlers are distributed among the threads.)