Re: [asio-users] New overload for async_read_until
Brought to you by:
chris_kohlhoff
From: Christopher K. <ch...@ko...> - 2007-08-22 11:38:42
|
Antti Tuppurainen wrote: > Hello! > I'm writing an irc bot (how cliché, eh?) for learning purposes, and > noticed that I could use a new overload for > boost::asio::async_read_until that takes a user-supplied predicate > functor, so I made one! I was originally using boost::regex("[\r\n]+") > for the delimiters to irc messages but since I'm not using regex > anywhere else in the program currently, it seemed a bit overkill to link > to the regex library just for that. > > I'd like to submit this to boost::asio, it should be trivial to add and > provides imho very useful functionality. I have tested this code in my > application, though additional testing might be necessary in case I > didn't get all the details right. > > Here's the code (added at the bottom of boost/asio/impl/read_until.ipp): > http://www.anttirt.net/files/read_until_pred.txt > <http://www.anttirt.net/files/read_until_pred.txt> Yep, this is almost what I'd like to add, however... the one problem with your current solution is that it relies on the position() function implemented by asio::detail::const_buffers_iterator. As a result the predicate is tied to this implementation detail and can't be used with other bidirectional iterators. I think perhaps I should create some buffers_iterator types that are part of the asio public interface. These should be random access iterators (rather than bidirectional) so that one can be subtracted from the other to obtain the position, a position can be added to a "begin" iterator, etc. I'll have a think about whether this can be implemented cleanly and efficiently. Cheers, Chris |