GCC Code Coverage Report


Directory: libs/http_proto/
File: src/file_body.cpp
Date: 2025-05-26 06:53:21
Exec Total Coverage
Lines: 0 28 0.0%
Functions: 0 5 0.0%
Branches: 0 8 0.0%

Line Branch Exec Source
1 //
2 // Copyright (c) 2022 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/http_proto
8 //
9
10 #include <boost/http_proto/file_body.hpp>
11 #include <boost/assert.hpp>
12
13 namespace boost {
14 namespace http_proto {
15
16 file_body::
17 ~file_body() = default;
18
19 file_body::
20 file_body(
21 file_body&&) noexcept = default;
22
23 file_body::
24 file_body(
25 file&& f,
26 std::uint64_t size) noexcept
27 : f_(std::move(f))
28 , n_(size)
29 {
30 }
31
32 auto
33 file_body::
34 on_read(
35 buffers::mutable_buffer b) ->
36 source::results
37 {
38 source::results rv;
39 if(n_ > 0)
40 {
41 std::size_t n;
42 if( n_ >= b.size())
43 n = b.size();
44 else
45 n = static_cast<std::size_t>(n_);
46 n = f_.read(
47 b.data(), n, rv.ec);
48 rv.bytes = n;
49 n_ -= n;
50 }
51 rv.finished = n_ == 0;
52 return rv;
53 }
54
55 auto
56 file_body::
57 on_write(
58 buffers::const_buffer b, bool) ->
59 sink::results
60 {
61 sink::results rv;
62 if(n_ > 0)
63 {
64 std::size_t n;
65 if( n_ >= b.size())
66 n = b.size();
67 else
68 n = static_cast<std::size_t>(n_);
69 n = f_.write(
70 b.data(), n, rv.ec);
71 rv.bytes = n;
72 n_ -= n;
73 }
74 return rv;
75 }
76
77 } // http_proto
78 } // boost
79