Line |
Branch |
Exec |
Source |
1 |
|
|
// |
2 |
|
|
// Copyright (c) 2023 Vinnie Falco (vinnie.falco@gmail.com) |
3 |
|
|
// Copyright (c) 2024 Mohammad Nejati |
4 |
|
|
// |
5 |
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying |
6 |
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
7 |
|
|
// |
8 |
|
|
// Official repository: https://github.com/cppalliance/http_proto |
9 |
|
|
// |
10 |
|
|
|
11 |
|
|
#ifndef BOOST_HTTP_PROTO_DETAIL_IMPL_FILTER_HPP |
12 |
|
|
#define BOOST_HTTP_PROTO_DETAIL_IMPL_FILTER_HPP |
13 |
|
|
|
14 |
|
|
#include <boost/buffers/range.hpp> |
15 |
|
|
#include <boost/buffers/sans_prefix.hpp> |
16 |
|
|
|
17 |
|
|
namespace boost { |
18 |
|
|
namespace http_proto { |
19 |
|
|
namespace detail { |
20 |
|
|
|
21 |
|
|
template< |
22 |
|
|
class MutableBufferSequence, |
23 |
|
|
class ConstBufferSequence> |
24 |
|
|
auto |
25 |
|
60084 |
filter:: |
26 |
|
|
process_impl( |
27 |
|
|
MutableBufferSequence const& out, |
28 |
|
|
ConstBufferSequence const& in, |
29 |
|
|
bool more) -> |
30 |
|
|
results |
31 |
|
|
{ |
32 |
|
60084 |
results rv; |
33 |
|
60084 |
auto it_o = buffers::begin(out); |
34 |
|
60084 |
auto it_i = buffers::begin(in); |
35 |
|
|
|
36 |
|
120168 |
if( it_o == buffers::end(out) || |
37 |
|
60084 |
it_i == buffers::end(in) ) |
38 |
|
✗ |
return rv; |
39 |
|
|
|
40 |
|
60084 |
auto ob = *it_o++; |
41 |
|
60084 |
auto ib = *it_i++; |
42 |
|
59334 |
for(;;) |
43 |
|
|
{ |
44 |
|
|
// empty buffers may be passed, and this is |
45 |
|
|
// intentional and valid. |
46 |
|
119418 |
results rs = process_impl(ob, ib, more); |
47 |
|
|
|
48 |
|
119418 |
rv.out_bytes += rs.out_bytes; |
49 |
|
119418 |
rv.in_bytes += rs.in_bytes; |
50 |
|
119418 |
rv.ec = rs.ec; |
51 |
|
119418 |
rv.finished = rs.finished; |
52 |
|
|
|
53 |
|
119418 |
if( rv.finished || rv.ec ) |
54 |
|
60084 |
return rv; |
55 |
|
|
|
56 |
|
119297 |
ob = buffers::sans_prefix(ob, rs.out_bytes); |
57 |
|
119297 |
ib = buffers::sans_prefix(ib, rs.in_bytes); |
58 |
|
|
|
59 |
|
119297 |
if( ob.size() == 0 ) |
60 |
|
|
{ |
61 |
|
6001 |
if( it_o == buffers::end(out) ) |
62 |
|
3467 |
return rv; |
63 |
|
2534 |
ob = *it_o++; |
64 |
|
|
} |
65 |
|
|
|
66 |
|
115830 |
if( ib.size() == 0 ) |
67 |
|
|
{ |
68 |
|
113301 |
if( it_i == buffers::end(in) ) |
69 |
|
|
{ |
70 |
|
|
// if `more == false` we return only |
71 |
|
|
// when `out` buffers are full. |
72 |
|
56496 |
if( more ) |
73 |
|
56496 |
return rv; |
74 |
|
|
} |
75 |
|
|
else |
76 |
|
|
{ |
77 |
|
56805 |
ib = *it_i++; |
78 |
|
|
} |
79 |
|
|
} |
80 |
|
|
} |
81 |
|
|
} |
82 |
|
|
|
83 |
|
|
} // detail |
84 |
|
|
} // http_proto |
85 |
|
|
} // boost |
86 |
|
|
|
87 |
|
|
#endif |
88 |
|
|
|