Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I force boost::asio to prioritize finishing async_write calls over running other handlers?

I am implementing a set of simple protocols using boost::asio (oblivious transfer schemes). These are CPU bound when they run. To improve efficiency, I want to try to keep both hosts working as much as possible. If host A has the choice between preforming two tasks, one of which would let host B start computation, and one which wouldn't, I want host A to pick the former.

Currently, io_service is running computationally intensive handlers before async_writes. Unless the tcp window is full (or some similar condition is blocking writing data to the socker), it's almost certainly better to finish the async_write rather than running some other handler.

I have seen asio's example of a priority queue for handlers. Is reimplementing async_write to use such a priority queue the only solution to my problem?

like image 736
Amy Avatar asked Jan 31 '11 17:01

Amy


1 Answers

There's an example in the documentation describing how to attach a priority to completion handlers. You won't need to reimplement async_write, just implement your own version of the handler_priority_queue class from the example.

like image 123
Sam Miller Avatar answered Oct 30 '22 18:10

Sam Miller