forked from boostorg/beast
Add multi_port to server-framework
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
|
||||
#include <beast/core/multi_buffer.hpp>
|
||||
#include <beast/websocket/stream.hpp>
|
||||
#include <functional>
|
||||
#include <boost/function.hpp>
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
|
||||
@@ -212,22 +212,28 @@ private:
|
||||
//
|
||||
class async_ws_con
|
||||
|
||||
// Note that we give this object the `enable_shared_from_this`, and have
|
||||
// the base class call `impl().shared_from_this()` when needed.
|
||||
// Give this object the enable_shared_from_this, and have
|
||||
// the base class call impl().shared_from_this(). The reason
|
||||
// is so that the shared_ptr has the correct type. This lets
|
||||
// the derived class (this class) use its members in calls to
|
||||
// `std::bind`, without an ugly call to `dynamic_downcast` or
|
||||
// other nonsense.
|
||||
//
|
||||
: public std::enable_shared_from_this<async_ws_con>
|
||||
|
||||
// We want the socket to be created before the base class so we use
|
||||
// the "base from member" idiom which Boost provides as a class.
|
||||
// The stream should be created before the base class so
|
||||
// use the "base from member" idiom.
|
||||
//
|
||||
, public base_from_member<beast::websocket::stream<socket_type>>
|
||||
|
||||
// Declare this base last now that everything else got set up first.
|
||||
// Constructs last, destroys first
|
||||
//
|
||||
, public async_ws_con_base<async_ws_con>
|
||||
{
|
||||
public:
|
||||
// Construct the plain connection.
|
||||
// Constructor
|
||||
//
|
||||
// Additional arguments are forwarded to the base class
|
||||
//
|
||||
template<class... Args>
|
||||
explicit
|
||||
@@ -241,7 +247,10 @@ public:
|
||||
|
||||
// Returns the stream.
|
||||
//
|
||||
// The base class calls this to obtain the websocket stream object.
|
||||
// The base class calls this to obtain the object to use for
|
||||
// reading and writing HTTP messages. This allows the same base
|
||||
// class to work with different return types for `stream()` such
|
||||
// as a `boost::asio::ip::tcp::socket&` or a `boost::asio::ssl::stream&`
|
||||
//
|
||||
beast::websocket::stream<socket_type>&
|
||||
stream()
|
||||
@@ -270,9 +279,10 @@ private:
|
||||
*/
|
||||
class ws_async_port
|
||||
{
|
||||
// The type of the on_stream callback
|
||||
using on_new_stream_cb = std::function<
|
||||
void(beast::websocket::stream<socket_type>&)>;
|
||||
// The type of the on_new_stream callback
|
||||
//
|
||||
using on_new_stream_cb =
|
||||
boost::function<void(beast::websocket::stream<socket_type>&)>;
|
||||
|
||||
server& instance_;
|
||||
std::ostream& log_;
|
||||
@@ -328,8 +338,7 @@ public:
|
||||
log_,
|
||||
instance_.next_id(),
|
||||
ep,
|
||||
cb_
|
||||
)->run();
|
||||
cb_)->run();
|
||||
}
|
||||
|
||||
/** Accept a WebSocket upgrade request.
|
||||
@@ -345,7 +354,7 @@ public:
|
||||
*/
|
||||
template<class Body, class Fields>
|
||||
void
|
||||
accept(
|
||||
on_upgrade(
|
||||
socket_type&& sock,
|
||||
endpoint_type ep,
|
||||
beast::http::request<Body, Fields>&& req)
|
||||
@@ -356,8 +365,7 @@ public:
|
||||
log_,
|
||||
instance_.next_id(),
|
||||
ep,
|
||||
cb_
|
||||
)->run(std::move(req));
|
||||
cb_)->run(std::move(req));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user