ASIO async_read_until with condition + strand
Can someone help with the boost async_read_until with condition ? I need to implement a request/response protocol. * A request cannot be send until the response has been completely read from the server. * Response's length from the server is unknown. The data must be parsed thanks to a parser to understand the content of the buffer. The parser is capable to return a code specifying whether the data is complete, which could require more reading on the socket. I'd like to implement my client asynchronously using ASIO. Here is the solution I implemented: the async send handler calls async_read whose handler calls async_read handler again until the message is complete. Due to the here above constraints, I am forced to queue the requests and async send the next request by the end of the handler of the current response (when it is complete, otherwize it async_reads again). I have tried to use async_read_until with a condition, but the parser was invoked very (too) often (every 2 bytes) and penalizes the performance. Would it be possible to reduce the number of calls to the condition (by reading at once the maximum of bytes present on the socket for example)? I'd like to async send the requests as soon as I can, in order to avoid the queue. Is it possible to implement a solution by using the ASIO strands? If yes, I have the feeling that the way I implemented the response handling will not work with the strand because the handler of async_read calls async_read again, which will probably come at the end of the strand's queue (which may contain many async_send requests). Could async_read_until with a condition solves this issue by avoiding to async_read again? Any help will be very appreciated. Christophe
participants (1)
-
Christophe Bourez