Line data Source code
1 : //
2 : // Copyright (c) 2023 Vinnie Falco (vinnie.falco@gmail.com)
3 : //
4 : // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 : // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 : //
7 : // Official repository: https://github.com/cppalliance/buffers
8 : //
9 :
10 : #ifndef BOOST_BUFFERS_IMPL_SOURCE_HPP
11 : #define BOOST_BUFFERS_IMPL_SOURCE_HPP
12 :
13 : #include <boost/http_proto/detail/except.hpp>
14 : #include <boost/assert.hpp>
15 :
16 : namespace boost {
17 : namespace http_proto {
18 :
19 : inline
20 : auto
21 2963 : source::
22 : results::
23 : operator+=(
24 : results const& rv) noexcept ->
25 : results&
26 : {
27 2963 : BOOST_ASSERT(! ec.failed());
28 2963 : BOOST_ASSERT(! finished);
29 2963 : ec = rv.ec;
30 2963 : bytes += rv.bytes;
31 2963 : finished = rv.finished;
32 2963 : return *this;
33 : }
34 :
35 : //------------------------------------------------
36 :
37 : template<class T>
38 : auto
39 996 : source::
40 : read_impl(
41 : T const& bs) ->
42 : results
43 : {
44 996 : results rv;
45 996 : constexpr int SmallArraySize = 16;
46 996 : buffers::mutable_buffer tmp[SmallArraySize];
47 996 : auto const tmp_end =
48 : tmp + SmallArraySize;
49 996 : auto it = buffers::begin(bs);
50 996 : auto const end_ = buffers::end(bs);
51 1964 : while(it != end_)
52 : {
53 995 : auto p = tmp;
54 : do
55 : {
56 1994 : *p++ = *it++;
57 : }
58 : while(
59 1994 : p != tmp_end &&
60 : it != end_);
61 995 : rv += on_read(
62 : true,
63 : boost::span<
64 : buffers::mutable_buffer const>(
65 995 : tmp, p - tmp));
66 995 : if(rv.ec.failed())
67 4 : return rv;
68 991 : if(rv.finished)
69 23 : break;
70 : }
71 992 : return rv;
72 : }
73 :
74 : } // http_proto
75 : } // boost
76 :
77 : #endif
|