开发者

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 sc开发者_运维百科hemes). 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜