ping_callback is a member of stream (API Change):

fix #446

* The ping_callback option struct is removed.

Actions Required:

* Change call sites which use ping_callback with set_option to
  call stream::ping_callback instead.
This commit is contained in:
Vinnie Falco
2017-07-20 08:12:19 -07:00
parent 333067243f
commit 3d6574da81
7 changed files with 56 additions and 79 deletions
@@ -46,6 +46,9 @@ struct stream_base
protected:
friend class frame_test;
using ping_callback_type =
std::function<void(bool, ping_data const&)>;
struct op {};
detail::maskgen maskgen_; // source of mask keys
@@ -55,7 +58,7 @@ protected:
std::size_t wr_buf_size_ = 4096; // write buffer size
std::size_t rd_buf_size_ = 4096; // read buffer size
opcode wr_opcode_ = opcode::text; // outgoing message type
ping_cb ping_cb_; // ping callback
ping_callback_type ping_cb_; // ping callback
role_type role_; // server or client
bool failed_; // the connection failed
-62
View File
@@ -22,12 +22,6 @@
namespace beast {
namespace websocket {
namespace detail {
using ping_cb = std::function<void(bool, ping_data const&)>;
} // detail
/** permessage-deflate extension options.
These settings control the permessage-deflate extension,
@@ -69,62 +63,6 @@ struct permessage_deflate
int memLevel = 4;
};
/** Ping callback option.
Sets the callback to be invoked whenever a ping or pong is
received during a call to one of the following functions:
@li @ref beast::websocket::stream::read
@li @ref beast::websocket::stream::read_frame
@li @ref beast::websocket::stream::async_read
@li @ref beast::websocket::stream::async_read_frame
Unlike completion handlers, the callback will be invoked
for each received ping and pong during a call to any
synchronous or asynchronous read function. The operation is
passive, with no associated error code, and triggered by reads.
The signature of the callback must be:
@code
void
callback(
bool is_pong, // `true` if this is a pong
ping_data const& payload // Payload of the pong frame
);
@endcode
The value of `is_pong` will be `true` if a pong control frame
is received, and `false` if a ping control frame is received.
If the read operation receiving a ping or pong frame is an
asynchronous operation, the callback will be invoked using
the same method as that used to invoke the final handler.
@note Objects of this type are used with
@ref beast::websocket::stream::set_option.
To remove the ping callback, construct the option with
no parameters: `set_option(ping_callback{})`
*/
#if BEAST_DOXYGEN
using ping_callback = implementation_defined;
#else
struct ping_callback
{
detail::ping_cb value;
ping_callback() = default;
ping_callback(ping_callback&&) = default;
ping_callback(ping_callback const&) = default;
explicit
ping_callback(detail::ping_cb f)
: value(std::move(f))
{
}
};
#endif
} // websocket
} // beast
+40 -7
View File
@@ -256,13 +256,6 @@ public:
o = pmd_opts_;
}
/// Set the ping callback
void
set_option(ping_callback o)
{
ping_cb_ = std::move(o.value);
}
/** Set the automatic fragmentation option.
Determines if outgoing message payloads are broken up into
@@ -327,6 +320,46 @@ public:
return wr_opcode_ == opcode::binary;
}
/** Set the ping callback.
Sets the callback to be invoked whenever a ping or pong is
received during a call to one of the following functions:
@li @ref beast::websocket::stream::read
@li @ref beast::websocket::stream::read_frame
@li @ref beast::websocket::stream::async_read
@li @ref beast::websocket::stream::async_read_frame
Unlike completion handlers, the callback will be invoked
for each received ping and pong during a call to any
synchronous or asynchronous read function. The operation is
passive, with no associated error code, and triggered by reads.
The signature of the callback must be:
@code
void
callback(
bool is_pong, // `true` if this is a pong
ping_data const& payload // Payload of the pong frame
);
@endcode
The value of `is_pong` will be `true` if a pong control frame
is received, and `false` if a ping control frame is received.
If the read operation receiving a ping or pong frame is an
asynchronous operation, the callback will be invoked using
the same method as that used to invoke the final handler.
@param cb The callback to set.
*/
void
ping_callback(
std::function<void(bool, ping_data const&)> cb)
{
ping_cb_ = std::move(cb);
}
/** Set the read buffer size option.
Sets the size of the read buffer used by the implementation to