From 0656c5b1f5f568d3acf2648c832faa4759aaf1bb Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Wed, 10 May 2017 10:03:51 -0700 Subject: [PATCH] Return http::error::end_of_stream on HTTP read eof (API Change) fix #350 --- CHANGELOG.md | 8 +++++ include/beast/http/impl/async_read.ipp | 7 ++-- include/beast/http/impl/read.ipp | 2 ++ include/beast/http/read.hpp | 45 ++++++++++++++++++++++++++ test/http/read.cpp | 4 +-- 5 files changed, 62 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d9aa0ad..294ac2bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +Version 41 + +API Changes + +* Return http::error::end_of_stream on HTTP read eof + +-------------------------------------------------------------------------------- + Version 40 * Add to_static_string diff --git a/include/beast/http/impl/async_read.ipp b/include/beast/http/impl/async_read.ipp index de090523..f4a015a9 100644 --- a/include/beast/http/impl/async_read.ipp +++ b/include/beast/http/impl/async_read.ipp @@ -185,8 +185,11 @@ operator()(error_code ec, BOOST_ASSERT(bytes_transferred == 0); d.bytes_used = 0; if(! d.p.got_some()) + { + ec = error::end_of_stream; goto upcall; - // caller sees EOF on next read. + } + // caller sees end_of_stream on next read. ec = {}; d.p.write_eof(ec); if(ec) @@ -194,7 +197,7 @@ operator()(error_code ec, BOOST_ASSERT(d.p.is_complete()); goto upcall; } - else if(ec) + if(ec) { d.bytes_used = 0; goto upcall; diff --git a/include/beast/http/impl/read.ipp b/include/beast/http/impl/read.ipp index 5fdc1f29..725a2e58 100644 --- a/include/beast/http/impl/read.ipp +++ b/include/beast/http/impl/read.ipp @@ -76,7 +76,9 @@ read_some_buffer( if(ec) return 0; BOOST_ASSERT(parser.is_complete()); + break; } + ec = error::end_of_stream; break; } else if(ec) diff --git a/include/beast/http/read.hpp b/include/beast/http/read.hpp index c7c4db32..187bbdb9 100644 --- a/include/beast/http/read.hpp +++ b/include/beast/http/read.hpp @@ -41,6 +41,11 @@ namespace http { being parsed. This additional data is stored in the dynamic buffer, which may be used in subsequent calls. + If the end of the stream is reached during the read, the + value @ref error::partial_message is indicated as the + error if bytes have been processed, else the error + @ref error::end_of_stream is indicated. + @param stream The stream from which the data is to be read. The type must support the @b SyncReadStream concept. @@ -92,6 +97,11 @@ read_some( being parsed. This additional data is stored in the dynamic buffer, which may be used in subsequent calls. + If the end of the stream is reached during the read, the + value @ref error::partial_message is indicated as the + error if bytes have been processed, else the error + @ref error::end_of_stream is indicated. + @param stream The stream from which the data is to be read. The type must support the @b SyncReadStream concept. @@ -151,6 +161,11 @@ read_some( processed from the dynamic buffer. The caller should remove these bytes by calling `consume` on the dynamic buffer. + If the end of the stream is reached during the read, the + value @ref error::partial_message is indicated as the + error if bytes have been processed, else the error + @ref error::end_of_stream is indicated. + @param stream The stream from which the data is to be read. The type must support the @b AsyncReadStream concept. @@ -205,6 +220,11 @@ async_read_some( being parsed. This additional data is stored in the dynamic buffer, which may be used in subsequent calls. + If the end of the stream is reached during the read, the + value @ref error::partial_message is indicated as the + error if bytes have been processed, else the error + @ref error::end_of_stream is indicated. + @param stream The stream from which the data is to be read. The type must support the @b SyncReadStream concept. @@ -244,6 +264,11 @@ read( being parsed. This additional data is stored in the dynamic buffer, which may be used in subsequent calls. + If the end of the stream is reached during the read, the + value @ref error::partial_message is indicated as the + error if bytes have been processed, else the error + @ref error::end_of_stream is indicated. + @param stream The stream from which the data is to be read. The type must support the @b SyncReadStream concept. @@ -287,6 +312,11 @@ read( end of the object being parsed. This additional data is stored in the stream buffer, which may be used in subsequent calls. + If the end of the stream is reached during the read, the + value @ref error::partial_message is indicated as the + error if bytes have been processed, else the error + @ref error::end_of_stream is indicated. + @param stream The stream from which the data is to be read. The type must support the @b AsyncReadStream concept. @@ -338,6 +368,11 @@ async_read( being parsed. This additional data is stored in the dynamic buffer, which may be used in subsequent calls. + If the end of the stream is reached during the read, the + value @ref error::partial_message is indicated as the + error if bytes have been processed, else the error + @ref error::end_of_stream is indicated. + @param stream The stream from which the data is to be read. The type must support the @b `SyncReadStream` concept. @@ -379,6 +414,11 @@ read( being parsed. This additional data is stored in the dynamic buffer, which may be used in subsequent calls. + If the end of the stream is reached during the read, the + value @ref error::partial_message is indicated as the + error if bytes have been processed, else the error + @ref error::end_of_stream is indicated. + @param stream The stream from which the data is to be read. The type must support the @b `SyncReadStream` concept. @@ -424,6 +464,11 @@ read( end of the message being parsed. This additional data is stored in the dynamic buffer, which may be used in subsequent calls. + If the end of the stream is reached during the read, the + value @ref error::partial_message is indicated as the + error if bytes have been processed, else the error + @ref error::end_of_stream is indicated. + @param stream The stream to read the message from. The type must support the @b `AsyncReadStream` concept. diff --git a/test/http/read.cpp b/test/http/read.cpp index bad11351..2d9ff567 100644 --- a/test/http/read.cpp +++ b/test/http/read.cpp @@ -253,7 +253,7 @@ public: message_parser p; error_code ec; read(ss, b, p, ec); - BEAST_EXPECT(ec == boost::asio::error::eof); + BEAST_EXPECT(ec == http::error::end_of_stream); } { multi_buffer b; @@ -261,7 +261,7 @@ public: message_parser p; error_code ec; async_read(ss, b, p, do_yield[ec]); - BEAST_EXPECT(ec == boost::asio::error::eof); + BEAST_EXPECT(ec == http::error::end_of_stream); } }