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 |
|
|
void* dest, |
39 |
|
|
std::size_t size) -> |
40 |
|
|
result<amount> |
41 |
|
|
{ |
42 |
|
✗ |
amount rv; |
43 |
|
✗ |
if(n_ > 0) |
44 |
|
|
{ |
45 |
|
|
std::size_t n; |
46 |
|
✗ |
if( n_ >= size) |
47 |
|
✗ |
n = size; |
48 |
|
|
else |
49 |
|
✗ |
n = n_; |
50 |
|
✗ |
error_code ec; |
51 |
|
✗ |
n = f_.read( |
52 |
|
|
dest, n, ec); |
53 |
|
✗ |
if(ec.failed()) |
54 |
|
✗ |
return ec; |
55 |
|
✗ |
n_ -= n; |
56 |
|
|
|
57 |
|
✗ |
rv.bytes = n; |
58 |
|
✗ |
rv.more = n_ > 0; |
59 |
|
✗ |
return rv; |
60 |
|
|
} |
61 |
|
|
|
62 |
|
✗ |
rv.bytes = 0; |
63 |
|
✗ |
rv.more = false; |
64 |
|
✗ |
return rv; |
65 |
|
|
} |
66 |
|
|
|
67 |
|
|
} // http_proto |
68 |
|
|
} // boost |
69 |
|
|
|
70 |
|
|
#endif |
71 |
|
|
|