Return std::size_t from Body::writer::put (API Change)

`put` returns the number of bytes actually transferred
from the input buffers.

Actions Required:

* Return the number of bytes actually transferred from the
  input buffers in user defined `Body::writer::put` functions.
This commit is contained in:
Vinnie Falco
2017-07-20 08:15:29 -07:00
parent f3afc834b1
commit c149321013
19 changed files with 179 additions and 55 deletions
+10 -4
View File
@@ -255,7 +255,7 @@ public:
// buffer sequences corresponding to the incoming body.
//
template<class ConstBufferSequence>
void
std::size_t
put(ConstBufferSequence const& buffers, beast::error_code& ec);
// This function is called when writing is complete.
@@ -307,16 +307,20 @@ writer(beast::http::message<isRequest, file_body, Fields>& m,
// This will get called one or more times with body buffers
//
template<class ConstBufferSequence>
void
std::size_t
file_body::writer::
put(ConstBufferSequence const& buffers, beast::error_code& ec)
{
// This function must return the total number of
// bytes transferred from the input buffers.
std::size_t bytes_transferred = 0;
// Loop over all the buffers in the sequence,
// and write each one to the file.
for(boost::asio::const_buffer buffer : buffers)
{
// Write this buffer to the file
fwrite(
bytes_transferred += fwrite(
boost::asio::buffer_cast<void const*>(buffer), 1,
boost::asio::buffer_size(buffer),
file_);
@@ -327,12 +331,14 @@ put(ConstBufferSequence const& buffers, beast::error_code& ec)
// Convert the old-school `errno` into
// an error code using the generic category.
ec = beast::error_code{errno, beast::generic_category()};
return;
return bytes_transferred;
}
}
// Indicate success
ec = {};
return bytes_transferred;
}
// Called after writing is done when there's no error.
+3 -3
View File
@@ -120,7 +120,7 @@ struct mutable_body
}
template<class ConstBufferSequence>
void
std::size_t
put(ConstBufferSequence const& buffers,
beast::error_code& ec)
{
@@ -135,10 +135,10 @@ struct mutable_body
catch(std::length_error const&)
{
ec = beast::http::error::buffer_overflow;
return;
return 0;
}
ec.assign(0, ec.category());
buffer_copy(boost::asio::buffer(
return buffer_copy(boost::asio::buffer(
&body_[0] + len, n), buffers);
}