Boost logo

Boost :

Subject: Re: [boost] Networking TS + Beast, NEW Tutorials, Read this to learn std::net !!!
From: Ivan Matek (libbooze_at_[hidden])
Date: 2019-03-17 23:13:29


Thank you for the reply, suggestions inline.

On Fri, Mar 15, 2019 at 1:19 AM Vinnie Falco <vinnie.falco_at_[hidden]> wrote:

> And this is why we can't have
> nice things.
>
> Somebody(tm) (ASIO or Beast) maybe should make buffer that has has member
fn content() that returns a range with begin and end.
example: if buffer is 8 bytes and you write 3 bytes buff.content().begin()
would return .data() and content().end() would return .data()+3

>
> > std::size_t read_line
> > I am tired, but is this function O(n^2)?
>
> It starts over from the beginning of the range so there can be some
> overlap of the searching, yes.
>
I beg you to fix this by remembering the index of last find(I assume
iterators are invalidated). I know in theory it is just an example, but
people blindly c/p code, and to make matters worse this thing is hard to
notice in tests since only very large total reads show O(n^2) behavior.
regards,
Ivan

On Fri, Mar 15, 2019 at 1:19 AM Vinnie Falco <vinnie.falco_at_[hidden]> wrote:

> On Thu, Mar 14, 2019 at 5:09 PM Ivan Matek <libbooze_at_[hidden]> wrote:
> > Quite a weird pattern, where buffer does not have member begin, end.
> > Maybe a sentence or two describing the rationale and complexity would be
> nice.
> > I know it is O(1), but it is weird that begin/end are called on pointer.
>
> Yeah, well... that's a sore subject. First of all I did not invent
> these buffer concepts, they are part of Asio and Networking TS. And
> they *used* to have begin() and end(), but then the C++ Standards
> Committee decided that they didn't like `const_buffers_1` and
> `mutable_buffers_1`, so they got rid of them in the TS draft. Then
> they realized that having `const_buffer::begin()` would be confusing.
> Does it refer to the beginning of the buffer sequence, or does it
> refer to the first byte of that buffer? They decided to get rid of
> begin/end entirely for the buffer types and add buffer_sequence_begin
> and buffer_sequence_end in its place. And this is why we can't have
> nice things.
>
> >
> > std::size_t read_line
> > I am tired, but is this function O(n^2)?
>
> It starts over from the beginning of the range so there can be some
> overlap of the searching, yes.
>
> > cb += bytes_transferred; // adjust the pointer and size
> > I would maybe switch to write instead of write_some to keep the code
> shorter, and mention write_some as another option in text.
>
> Well the purpose of this example is to show the looping.
>
> > [](error_code ec, std::size_t bytes_transferred)
> > For learning purposes I would capture something in lambda by value and
> note that reference capture would be buggy.
>
> That is something I might consider!! Remember though I"m stuck in
> C++11 so no lambda capture assignment expressions.
>
> Appreciate the feedback!
>
> Regards
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk