LCOV - code coverage report
Current view: top level - src/detail - filter.cpp (source / functions) Coverage Total Hit Missed
Test: coverage_remapped.info Lines: 70.0 % 40 28 12
Test Date: 2026-11-22 21:03:06 Functions: 100.0 % 2 2

           TLA  Line data    Source code
       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
       9                 : //
      10                 : 
      11                 : #include "src/detail/filter.hpp"
      12                 : 
      13                 : #include <boost/capy/buffers/buffers_front.hpp>
      14                 : #include <boost/http/io/buffer_param.hpp>
      15                 : 
      16                 : namespace boost {
      17                 : namespace http {
      18                 : namespace detail {
      19                 : 
      20                 : namespace {
      21                 : 
      22                 : // Returns true if the slice's current data view contains at most one
      23                 : // non-empty buffer (i.e., we are processing the last logical chunk).
      24                 : template<class Slice>
      25 HIT           2 : bool single_or_empty(Slice& s)
      26                 : {
      27               2 :     auto d = s.data();
      28               2 :     auto it = d.begin();
      29               2 :     auto const end_it = d.end();
      30               2 :     if(it == end_it)
      31               1 :         return true;
      32               1 :     ++it;
      33               1 :     return it == end_it;
      34                 : }
      35                 : 
      36                 : } // anonymous
      37                 : 
      38                 : auto
      39               2 : filter::
      40                 : process(
      41                 :     boost::span<const capy::mutable_buffer> out_seq,
      42                 :     std::array<capy::const_buffer, 2> in_seq,
      43                 :     bool more) -> results
      44                 : {
      45               2 :     buffer_param out(out_seq);
      46               2 :     buffer_param in(in_seq);
      47                 : 
      48                 :     // data() spans only the current window, so track totals separately
      49               2 :     std::size_t out_left = capy::buffer_size(out_seq);
      50               2 :     std::size_t in_left = capy::buffer_size(in_seq);
      51                 : 
      52               2 :     results rv;
      53               2 :     bool p_more = true;
      54                 :     for(;;)
      55                 :     {
      56               2 :         if(!more && p_more && single_or_empty(in))
      57                 :         {
      58               2 :             if(out_left < min_out_buffer())
      59                 :             {
      60 MIS           0 :                 rv.out_short = true;
      61 HIT           2 :                 return rv;
      62                 :             }
      63               2 :             p_more = false;
      64                 :         }
      65                 : 
      66               2 :         auto ob = capy::buffers_front(out.data());
      67               2 :         auto ib = capy::buffers_front(in.data());
      68               2 :         auto rs = do_process(ob, ib, p_more);
      69                 : 
      70               2 :         rv.in_bytes  += rs.in_bytes;
      71               2 :         rv.out_bytes += rs.out_bytes;
      72                 : 
      73               2 :         if(rs.ec)
      74                 :         {
      75 MIS           0 :             rv.ec = rs.ec;
      76               0 :             return rv;
      77                 :         }
      78                 : 
      79 HIT           2 :         if(rs.finished)
      80                 :         {
      81               2 :             rv.finished = true;
      82               2 :             return rv;
      83                 :         }
      84                 : 
      85 MIS           0 :         out.consume(rs.out_bytes);
      86               0 :         in.consume(rs.in_bytes);
      87               0 :         out_left -= rs.out_bytes;
      88               0 :         in_left -= rs.in_bytes;
      89                 : 
      90               0 :         if(out_left == 0)
      91               0 :             return rv;
      92                 : 
      93               0 :         if(in_left == 0 && rs.out_bytes < ob.size())
      94               0 :             return rv;
      95               0 :     }
      96                 : }
      97                 : 
      98                 : } // detail
      99                 : } // http
     100                 : } // boost
        

Generated by: LCOV version 2.3