Line |
Branch |
Exec |
Source |
1 |
|
|
// |
2 |
|
|
// Copyright (c) 2022 Vinnie Falco (vinnie dot falco at gmail dot 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 |
|
|
#ifndef BOOST_HTTP_PROTO_IMPL_FILE_BODY_IPP |
11 |
|
|
#define BOOST_HTTP_PROTO_IMPL_FILE_BODY_IPP |
12 |
|
|
|
13 |
|
|
#include <boost/http_proto/file_body.hpp> |
14 |
|
|
#include <boost/assert.hpp> |
15 |
|
|
|
16 |
|
|
namespace boost { |
17 |
|
|
namespace http_proto { |
18 |
|
|
|
19 |
|
|
file_body:: |
20 |
|
|
~file_body() = default; |
21 |
|
|
|
22 |
|
|
file_body:: |
23 |
|
|
file_body( |
24 |
|
|
file_body&&) noexcept = default; |
25 |
|
|
|
26 |
|
✗ |
file_body:: |
27 |
|
|
file_body( |
28 |
|
|
file&& f, |
29 |
|
✗ |
std::uint64_t size) noexcept |
30 |
|
✗ |
: f_(std::move(f)) |
31 |
|
✗ |
, n_(size) |
32 |
|
|
{ |
33 |
|
|
} |
34 |
|
|
|
35 |
|
|
auto |
36 |
|
✗ |
file_body:: |
37 |
|
|
read( |
38 |
|
|
mutable_buffers_pair dest) -> |
39 |
|
|
results |
40 |
|
|
{ |
41 |
|
✗ |
results rv; |
42 |
|
✗ |
for(auto const& mb : dest) |
43 |
|
|
{ |
44 |
|
✗ |
if(n_ == 0) |
45 |
|
✗ |
break; |
46 |
|
|
std::size_t n; |
47 |
|
✗ |
if( n_ >= mb.size()) |
48 |
|
✗ |
n = mb.size(); |
49 |
|
|
else |
50 |
|
✗ |
n = n_; |
51 |
|
✗ |
n = f_.read( |
52 |
|
|
mb.data(), n, rv.ec); |
53 |
|
✗ |
rv.bytes += n; |
54 |
|
✗ |
n_ -= n; |
55 |
|
✗ |
rv.more = n_ > 0; |
56 |
|
✗ |
if(rv.ec.failed()) |
57 |
|
✗ |
return rv; |
58 |
|
|
} |
59 |
|
✗ |
return rv; |
60 |
|
|
} |
61 |
|
|
|
62 |
|
|
} // http_proto |
63 |
|
|
} // boost |
64 |
|
|
|
65 |
|
|
#endif |
66 |
|
|
|