From b9dbb76c4faf07d2ebe9443b6f651f86b84e5595 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Thu, 8 Jun 2017 18:22:25 -0700 Subject: [PATCH] read_message_max is a member of stream (API Change): fix #446 * The read_message_max option struct is removed. Actions Required: * Change call sites which use read_message_max with set_option to call stream::read_message_max instead. --- CHANGELOG.md | 4 ++++ doc/quickref.xml | 1 - examples/websocket_echo.cpp | 2 +- include/beast/websocket/option.hpp | 35 ---------------------------- include/beast/websocket/stream.hpp | 37 ++++++++++++++++++++++++------ test/websocket/stream.cpp | 6 ++--- 6 files changed, 38 insertions(+), 47 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a9bab60..efe35025 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ API Changes: * auto_fragment is a member of stream * binary, text are members of stream * read_buffer_size is a member of stream +* read_message_max is a member of stream Actions Required: @@ -17,6 +18,9 @@ Actions Required: * Change call sites which use read_buffer_size with set_option to call stream::read_buffer_size instead. +* Change call sites which use read_message_max with set_option to + call stream::read_message_max instead. + -------------------------------------------------------------------------------- Version 51 diff --git a/doc/quickref.xml b/doc/quickref.xml index 77908a45..34e1ac0a 100644 --- a/doc/quickref.xml +++ b/doc/quickref.xml @@ -125,7 +125,6 @@ permessage_deflate ping_callback - read_message_max write_buffer_size Constants diff --git a/examples/websocket_echo.cpp b/examples/websocket_echo.cpp index 524d83d3..7ed6808d 100644 --- a/examples/websocket_echo.cpp +++ b/examples/websocket_echo.cpp @@ -44,7 +44,7 @@ public: { ws.auto_fragment(false); ws.set_option(pmd_); - ws.set_option(beast::websocket::read_message_max{64 * 1024 * 1024}); + ws.read_message_max(64 * 1024 * 1024); } }; diff --git a/include/beast/websocket/option.hpp b/include/beast/websocket/option.hpp index 75ade538..f68d3631 100644 --- a/include/beast/websocket/option.hpp +++ b/include/beast/websocket/option.hpp @@ -124,41 +124,6 @@ struct ping_callback }; #endif -/** Maximum incoming message size option. - - Sets the largest permissible incoming message size. Message - frame fields indicating a size that would bring the total - message size over this limit will cause a protocol failure. - - The default setting is 16 megabytes. A value of zero indicates - a limit of the maximum value of a `std::uint64_t`. - - @note Objects of this type are used with - @ref beast::websocket::stream::set_option. - - @par Example - Setting the maximum read message size. - @code - ... - websocket::stream ws(ios); - ws.set_option(read_message_max{65536}); - @endcode -*/ -#if BEAST_DOXYGEN -using read_message_max = implementation_defined; -#else -struct read_message_max -{ - std::size_t value; - - explicit - read_message_max(std::size_t n) - : value(n) - { - } -}; -#endif - /** Write buffer size option. Sets the size of the write buffer used by the implementation to diff --git a/include/beast/websocket/stream.hpp b/include/beast/websocket/stream.hpp index 7a90f12f..ae3928e1 100644 --- a/include/beast/websocket/stream.hpp +++ b/include/beast/websocket/stream.hpp @@ -263,13 +263,6 @@ public: ping_cb_ = std::move(o.value); } - /// Set the maximum incoming message size allowed - void - set_option(read_message_max const& o) - { - rd_msg_max_ = o.value; - } - /// Set the size of the write buffer void set_option(write_buffer_size const& o) @@ -377,6 +370,36 @@ public: return rd_buf_size_; } + /** Set the maximum incoming message size option. + + Sets the largest permissible incoming message size. Message + frame fields indicating a size that would bring the total + message size over this limit will cause a protocol failure. + + The default setting is 16 megabytes. A value of zero indicates + a limit of the maximum value of a `std::uint64_t`. + + @par Example + Setting the maximum read message size. + @code + ws.read_message_max(65536); + @endcode + + @param n The limit on the size of incoming messages. + */ + void + read_message_max(std::size_t n) + { + rd_msg_max_ = n; + } + + /// Returns the maximum incoming message size setting. + std::size_t + read_message_max() const + { + return rd_msg_max_; + } + /** Returns the close reason received from the peer. This is only valid after a read completes with error::closed. diff --git a/test/websocket/stream.cpp b/test/websocket/stream.cpp index 88737c90..30f86599 100644 --- a/test/websocket/stream.cpp +++ b/test/websocket/stream.cpp @@ -557,7 +557,7 @@ public: ws.set_option(write_buffer_size{2048}); ws.binary(false); ws.read_buffer_size(8192); - ws.set_option(read_message_max{1 * 1024 * 1024}); + ws.read_message_max(1 * 1024 * 1024); try { ws.set_option(write_buffer_size{7}); @@ -1815,10 +1815,10 @@ public: restart(error::closed); // message size exceeds max - ws.set_option(read_message_max{1}); + ws.read_message_max(1); c.write(ws, cbuf(0x00, 0x00)); restart(error::failed); - ws.set_option(read_message_max{16*1024*1024}); + ws.read_message_max(16*1024*1024); } } catch(system_error const&)