10 #ifndef BOOST_BEAST_HTTP_BASIC_FILE_BODY_HPP 11 #define BOOST_BEAST_HTTP_BASIC_FILE_BODY_HPP 18 #include <boost/assert.hpp> 19 #include <boost/optional.hpp> 49 "File requirements not met");
97 std::uint64_t file_size_ = 0;
119 return file_.is_open();
159 file_.close(ignored);
169 file_.open(path, mode, ec);
174 file_size_ = file_.size(ec);
192 file_.close(ignored);
199 file_size_ = file_.size(ec);
225 std::uint64_t remain_;
232 boost::asio::const_buffers_1;
258 template<
bool isRequest,
class Fields>
277 boost::optional<std::pair<const_buffers_type, bool>>
290 template<
bool isRequest,
class Fields>
297 BOOST_ASSERT(body_.file_.is_open());
300 remain_ = body_.file_size_;
315 ec.assign(0, ec.category());
328 boost::optional<std::pair<const_buffers_type, bool>>
332 auto const amount = remain_ >
sizeof(buf_) ?
333 sizeof(buf_) :
static_cast<std::size_t
>(remain_);
345 ec.assign(0, ec.category());
350 auto const nread = body_.file_.read(buf_, amount, ec);
355 BOOST_ASSERT(nread != 0);
356 BOOST_ASSERT(nread <= remain_);
369 ec.assign(0, ec.category());
398 template<
bool isRequest,
class Fields>
417 template<
class ConstBufferSequence>
441 template<
bool isRequest,
class Fields>
458 BOOST_ASSERT(body_.file_.is_open());
463 boost::ignore_unused(content_length);
470 ec.assign(0, ec.category());
476 template<
class ConstBufferSequence>
484 std::size_t nwritten = 0;
488 for(boost::asio::const_buffer buffer : buffers)
491 nwritten += body_.file_.write(
492 boost::asio::buffer_cast<void const*>(buffer),
493 boost::asio::buffer_size(buffer),
501 ec.assign(0, ec.category());
515 ec.assign(0, ec.category());
520 #if ! BOOST_BEAST_DOXYGEN 522 template<
bool isRequest,
class File,
class Fields>
BufferSequence< boost::asio::const_buffer > ConstBufferSequence
Definition: type_traits.hpp:280
std::ostream & operator<<(std::ostream &os, message< isRequest, basic_file_body< File >, Fields > const &msg)=delete
file_mode
Definition: file_base.hpp:26
void init(sha1_context &ctx) noexcept
Definition: sha1.hpp:235
void finish(error_code &ec)
Definition: basic_file_body.hpp:511
Definition: async_result.hpp:20
Definition: file_stdio.hpp:27
detail::ostream_helper< DynamicBuffer, char, std::char_traits< char >, detail::basic_streambuf_movable::value > ostream(DynamicBuffer &buffer)
Definition: ostream.hpp:91
std::uint64_t size() const
Returns the size of the file if open.
Definition: basic_file_body.hpp:124
Definition: type_traits.hpp:25
void reset(File &&file, error_code &ec)
Definition: basic_file_body.hpp:186
detail::buffers_helper< ConstBufferSequence > buffers(ConstBufferSequence const &b)
Definition: ostream.hpp:50
Definition: basic_file_body.hpp:386
std::size_t put(ConstBufferSequence const &buffers, error_code &ec)
Definition: basic_file_body.hpp:480
writer(message< isRequest, basic_file_body, Fields > &m)
Definition: basic_file_body.hpp:444
Definition: beast_common.hpp:6
void init(boost::optional< std::uint64_t > const &, error_code &ec)
Definition: basic_file_body.hpp:453
Definition: basic_file_body.hpp:84
boost::system::error_code error_code
The type of error code used by the library.
Definition: error.hpp:21
bool is_open() const
Returns true if the file is open.
Definition: basic_file_body.hpp:117
Definition: type_traits.hpp:603
void open(char const *path, file_mode mode, error_code &ec)
Definition: basic_file_body.hpp:166
reader(message< isRequest, basic_file_body, Fields > &m)
Definition: basic_file_body.hpp:293
Definition: basic_file_body.hpp:222
Definition: basic_file_body.hpp:45
void close()
Close the file if open.
Definition: basic_file_body.hpp:156
static std::uint64_t size(value_type const &body)
Definition: basic_file_body.hpp:206
File file_type
The type of File this body uses.
Definition: basic_file_body.hpp:52
boost::optional< std::pair< const_buffers_type, bool > > get(error_code &ec)
Definition: basic_file_body.hpp:327
void init(error_code &ec)
Definition: basic_file_body.hpp:308
boost::asio::const_buffers_1 const_buffers_type
Definition: basic_file_body.hpp:232