| 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/algorithm.hpp> | ||
| 15 | |||
| 16 | namespace boost { | ||
| 17 | namespace http_proto { | ||
| 18 | namespace detail { | ||
| 19 | |||
| 20 | template< | ||
| 21 | class MutableBufferSequence, | ||
| 22 | class ConstBufferSequence> | ||
| 23 | auto | ||
| 24 | 60170 | filter:: | |
| 25 | process_impl( | ||
| 26 | MutableBufferSequence const& out, | ||
| 27 | ConstBufferSequence const& in, | ||
| 28 | bool more) -> | ||
| 29 | results | ||
| 30 | { | ||
| 31 | 60170 | results rv; | |
| 32 | 60170 | auto it_o = buffers::begin(out); | |
| 33 | 60170 | auto it_i = buffers::begin(in); | |
| 34 | |||
| 35 | 120340 | if( it_o == buffers::end(out) || | |
| 36 | 60170 | it_i == buffers::end(in) ) | |
| 37 | ✗ | return rv; | |
| 38 | |||
| 39 | 60170 | auto ob = *it_o++; | |
| 40 | 60170 | auto ib = *it_i++; | |
| 41 | 59443 | for(;;) | |
| 42 | { | ||
| 43 | // empty buffers may be passed, and this is | ||
| 44 | // intentional and valid. | ||
| 45 | 119613 | results rs = process_impl(ob, ib, more); | |
| 46 | |||
| 47 | 119613 | rv.out_bytes += rs.out_bytes; | |
| 48 | 119613 | rv.in_bytes += rs.in_bytes; | |
| 49 | 119613 | rv.ec = rs.ec; | |
| 50 | 119613 | rv.finished = rs.finished; | |
| 51 | |||
| 52 | 119613 | if( rv.finished || rv.ec ) | |
| 53 | 60170 | return rv; | |
| 54 | |||
| 55 | 119492 | ob = buffers::sans_prefix(ob, rs.out_bytes); | |
| 56 | 119492 | ib = buffers::sans_prefix(ib, rs.in_bytes); | |
| 57 | |||
| 58 | 119492 | if( ob.size() == 0 ) | |
| 59 | { | ||
| 60 | 6017 | if( it_o == buffers::end(out) ) | |
| 61 | 3463 | return rv; | |
| 62 | 2554 | ob = *it_o++; | |
| 63 | } | ||
| 64 | |||
| 65 | 116029 | if( ib.size() == 0 ) | |
| 66 | { | ||
| 67 | 113485 | if( it_i == buffers::end(in) ) | |
| 68 | { | ||
| 69 | // if `more == false` we return only | ||
| 70 | // when `out` buffers are full. | ||
| 71 | 56586 | if( more ) | |
| 72 | 56586 | return rv; | |
| 73 | } | ||
| 74 | else | ||
| 75 | { | ||
| 76 | 56899 | ib = *it_i++; | |
| 77 | } | ||
| 78 | } | ||
| 79 | } | ||
| 80 | } | ||
| 81 | |||
| 82 | } // detail | ||
| 83 | } // http_proto | ||
| 84 | } // boost | ||
| 85 | |||
| 86 | #endif | ||
| 87 |