RatePolicy documentation

This commit is contained in:
Vinnie Falco
2019-02-20 15:30:03 -08:00
parent eaa3d5f975
commit fd4b080a4a
11 changed files with 269 additions and 14 deletions
+40 -1
View File
@@ -239,7 +239,12 @@ private:
template<class... Args>
explicit
impl_type(Args&&...);
impl_type(std::false_type, Args&&...);
template<class RatePolicy_, class... Args>
explicit
impl_type(std::true_type,
RatePolicy_&& policy, Args&&...);
impl_type& operator=(impl_type&&) = delete;
@@ -317,9 +322,43 @@ public:
@param args A list of parameters forwarded to the constructor of
the underlying socket.
*/
#if BOOST_BEAST_DOXYGEN
template<class... Args>
explicit
basic_stream(Args&&... args);
#else
template<class Arg0, class... Args,
class = typename std::enable_if<
! std::is_constructible<RatePolicy, Arg0>::value>::type>
explicit
basic_stream(Arg0&& argo, Args&&... args);
#endif
/** Constructor
This constructor creates the stream with the specified rate
policy, and forwards all remaining arguments to the underlying
socket. The socket then needs to be open and connected or
accepted before data can be sent or received on it.
@param policy The rate policy object to use. The stream will
take ownership of this object by decay-copy.
@param args A list of parameters forwarded to the constructor of
the underlying socket.
*/
#if BOOST_BEAST_DOXYGEN
template<class RatePolicy_, class... Args>
explicit
basic_stream(RatePolicy_&& policy, Args&&... args);
#else
template<class RatePolicy_, class Arg0, class... Args,
class = typename std::enable_if<
std::is_constructible<
RatePolicy, RatePolicy_>::value>::type>
basic_stream(
RatePolicy_&& policy, Arg0&& arg, Args&&... args);
#endif
/** Move constructor
+35 -3
View File
@@ -33,7 +33,7 @@ template<class Protocol, class Executor, class RatePolicy>
template<class... Args>
basic_stream<Protocol, Executor, RatePolicy>::
impl_type::
impl_type(Args&&... args)
impl_type(std::false_type, Args&&... args)
: socket(std::forward<Args>(args)...)
, read(ex())
, write(ex())
@@ -42,6 +42,23 @@ impl_type(Args&&... args)
reset();
}
template<class Protocol, class Executor, class RatePolicy>
template<class RatePolicy_, class... Args>
basic_stream<Protocol, Executor, RatePolicy>::
impl_type::
impl_type(std::true_type,
RatePolicy_&& policy, Args&&... args)
: boost::empty_value<RatePolicy>(
boost::empty_init_t{},
std::forward<RatePolicy_>(policy))
, socket(std::forward<Args>(args)...)
, read(ex())
, write(ex())
, timer(ex())
{
reset();
}
template<class Protocol, class Executor, class RatePolicy>
template<class Executor2>
void
@@ -650,10 +667,25 @@ basic_stream<Protocol, Executor, RatePolicy>::
}
template<class Protocol, class Executor, class RatePolicy>
template<class... Args>
template<class Arg0, class... Args, class>
basic_stream<Protocol, Executor, RatePolicy>::
basic_stream(Args&&... args)
basic_stream(Arg0&& arg0, Args&&... args)
: impl_(boost::make_shared<impl_type>(
std::false_type{},
std::forward<Arg0>(arg0),
std::forward<Args>(args)...))
{
}
template<class Protocol, class Executor, class RatePolicy>
template<class RatePolicy_, class Arg0, class... Args, class>
basic_stream<Protocol, Executor, RatePolicy>::
basic_stream(
RatePolicy_&& policy, Arg0&& arg0, Args&&... args)
: impl_(boost::make_shared<impl_type>(
std::true_type{},
std::forward<RatePolicy_>(policy),
std::forward<Arg0>(arg0),
std::forward<Args>(args)...))
{
}
+9 -10
View File
@@ -102,36 +102,35 @@ private:
*/
class unlimited_rate_policy
{
friend class rate_policy_access;
static std::size_t constexpr all =
(std::numeric_limits<std::size_t>::max)();
private:
friend class rate_policy_access;
std::size_t
available_read_bytes()
available_read_bytes() const noexcept
{
return all;
}
std::size_t
available_write_bytes()
available_write_bytes() const noexcept
{
return all;
}
void
transfer_read_bytes(std::size_t)
transfer_read_bytes(std::size_t) const noexcept
{
}
void
transfer_write_bytes(std::size_t)
transfer_write_bytes(std::size_t) const noexcept
{
}
void
on_timer()
on_timer() const noexcept
{
}
};
@@ -162,13 +161,13 @@ class simple_rate_policy
std::size_t wr_limit_ = all;
std::size_t
available_read_bytes()
available_read_bytes() const noexcept
{
return rd_remain_;
}
std::size_t
available_write_bytes()
available_write_bytes() const noexcept
{
return wr_remain_;
}