From 4ff4c79d5b3df7a56e692f6112de48bdc33a549f Mon Sep 17 00:00:00 2001 From: Klemens Date: Sat, 17 Dec 2022 16:12:31 +0800 Subject: [PATCH] file_body buffer size can be configured. --- doc/qbk/03_core/8_conf_macros.qbk | 7 +++++++ include/boost/beast/core/detail/config.hpp | 4 ++++ include/boost/beast/http/basic_file_body.hpp | 6 +++--- include/boost/beast/http/impl/file_body_win32.hpp | 6 +++--- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/doc/qbk/03_core/8_conf_macros.qbk b/doc/qbk/03_core/8_conf_macros.qbk index daea30de..1de67ee1 100644 --- a/doc/qbk/03_core/8_conf_macros.qbk +++ b/doc/qbk/03_core/8_conf_macros.qbk @@ -35,6 +35,13 @@ failure to do so may result in violations of ODR (One Definition Rule). Enables the use of deprecated APIs within Beast. ] ] +[ + [ + BOOST_BEAST_FILE_BUFFER_SIZE + ][ + Sets the small buffer size for the file_body. Defaults to 4096. + ] +] ] [endsect] diff --git a/include/boost/beast/core/detail/config.hpp b/include/boost/beast/core/detail/config.hpp index 8ec1c761..0146d86f 100644 --- a/include/boost/beast/core/detail/config.hpp +++ b/include/boost/beast/core/detail/config.hpp @@ -113,4 +113,8 @@ namespace net = boost::asio; #endif +#ifndef BOOST_BEAST_FILE_BUFFER_SIZE +#define BOOST_BEAST_FILE_BUFFER_SIZE 4096 +#endif + #endif diff --git a/include/boost/beast/http/basic_file_body.hpp b/include/boost/beast/http/basic_file_body.hpp index e57ae01b..7d04772a 100644 --- a/include/boost/beast/http/basic_file_body.hpp +++ b/include/boost/beast/http/basic_file_body.hpp @@ -234,9 +234,9 @@ size(value_type const& body) template class basic_file_body::writer { - value_type& body_; // The body we are reading from - std::uint64_t remain_; // The number of unread bytes - char buf_[4096]; // Small buffer for reading + value_type& body_; // The body we are reading from + std::uint64_t remain_; // The number of unread bytes + char buf_[BOOST_BEAST_FILE_BUFFER_SIZE]; // Small buffer for reading public: // The type of buffer sequence returned by `get`. diff --git a/include/boost/beast/http/impl/file_body_win32.hpp b/include/boost/beast/http/impl/file_body_win32.hpp index 9066f5f1..8af213d2 100644 --- a/include/boost/beast/http/impl/file_body_win32.hpp +++ b/include/boost/beast/http/impl/file_body_win32.hpp @@ -124,9 +124,9 @@ struct basic_file_body basic_file_body, Fields>& sr, error_code& ec); - value_type& body_; // The body we are reading from - std::uint64_t pos_; // The current position in the file - char buf_[4096]; // Small buffer for reading + value_type& body_; // The body we are reading from + std::uint64_t pos_; // The current position in the file + char buf_[BOOST_BEAST_FILE_BUFFER_SIZE]; // Small buffer for reading public: using const_buffers_type =