mirror of
https://github.com/boostorg/beast.git
synced 2025-07-30 12:57:31 +02:00
@ -1,6 +1,7 @@
|
|||||||
Version 108:
|
Version 108:
|
||||||
|
|
||||||
* Fix argument parsing in HTTP examples
|
* Fix argument parsing in HTTP examples
|
||||||
|
* Don't use async_write_msg in examples
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -235,14 +235,6 @@ listed here along with a description of their use:
|
|||||||
which supports construction from a moved-froms ocket and is also
|
which supports construction from a moved-froms ocket and is also
|
||||||
itself move constructible.
|
itself move constructible.
|
||||||
]
|
]
|
||||||
][
|
|
||||||
[[repo_file example/common/write_msg.hpp]]
|
|
||||||
[
|
|
||||||
The function `async_write_msg` takes ownership of an HTTP message
|
|
||||||
using the move constructor, and sends it asynchronously. It is
|
|
||||||
used as a convenience for managing the lifetime of temporary
|
|
||||||
objects, as well as for implementing HTTP pipelining.
|
|
||||||
]
|
|
||||||
]]
|
]]
|
||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
#include "example/common/detect_ssl.hpp"
|
#include "example/common/detect_ssl.hpp"
|
||||||
#include "example/common/server_certificate.hpp"
|
#include "example/common/server_certificate.hpp"
|
||||||
#include "example/common/ssl_stream.hpp"
|
#include "example/common/ssl_stream.hpp"
|
||||||
#include "example/common/write_msg.hpp"
|
|
||||||
|
|
||||||
#include <boost/beast/core.hpp>
|
#include <boost/beast/core.hpp>
|
||||||
#include <boost/beast/http.hpp>
|
#include <boost/beast/http.hpp>
|
||||||
|
@ -14,7 +14,6 @@ GroupSources(example/http/server/async-ssl "/")
|
|||||||
add_executable (http-server-async-ssl
|
add_executable (http-server-async-ssl
|
||||||
${BOOST_BEAST_INCLUDES}
|
${BOOST_BEAST_INCLUDES}
|
||||||
${PROJECT_SOURCE_DIR}/example/common/server_certificate.hpp
|
${PROJECT_SOURCE_DIR}/example/common/server_certificate.hpp
|
||||||
${PROJECT_SOURCE_DIR}/example/common/write_msg.hpp
|
|
||||||
Jamfile
|
Jamfile
|
||||||
http_server_async_ssl.cpp
|
http_server_async_ssl.cpp
|
||||||
)
|
)
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
#include "example/common/server_certificate.hpp"
|
#include "example/common/server_certificate.hpp"
|
||||||
#include "example/common/write_msg.hpp"
|
|
||||||
|
|
||||||
#include <boost/beast/core.hpp>
|
#include <boost/beast/core.hpp>
|
||||||
#include <boost/beast/http.hpp>
|
#include <boost/beast/http.hpp>
|
||||||
@ -231,12 +230,20 @@ class session : public std::enable_shared_from_this<session>
|
|||||||
void
|
void
|
||||||
operator()(http::message<isRequest, Body, Fields>&& msg) const
|
operator()(http::message<isRequest, Body, Fields>&& msg) const
|
||||||
{
|
{
|
||||||
// This function takes ownership of the message by moving
|
// The lifetime of the message has to extend
|
||||||
// it into a temporary buffer, otherwise we would have
|
// for the duration of the async operation so
|
||||||
// to manage the lifetime of the message and serializer.
|
// we use a shared_ptr to manage it.
|
||||||
async_write_msg(
|
auto sp = std::make_shared<
|
||||||
|
http::message<isRequest, Body, Fields>>(std::move(msg));
|
||||||
|
|
||||||
|
// Store a type-erased version of the shared
|
||||||
|
// pointer in the class to keep it alive.
|
||||||
|
self_.res_ = sp;
|
||||||
|
|
||||||
|
// Write the response
|
||||||
|
http::async_write(
|
||||||
self_.stream_,
|
self_.stream_,
|
||||||
std::move(msg),
|
*sp,
|
||||||
self_.strand_.wrap(std::bind(
|
self_.strand_.wrap(std::bind(
|
||||||
&session::on_write,
|
&session::on_write,
|
||||||
self_.shared_from_this(),
|
self_.shared_from_this(),
|
||||||
@ -250,6 +257,7 @@ class session : public std::enable_shared_from_this<session>
|
|||||||
boost::beast::flat_buffer buffer_;
|
boost::beast::flat_buffer buffer_;
|
||||||
std::string const& doc_root_;
|
std::string const& doc_root_;
|
||||||
http::request<http::string_body> req_;
|
http::request<http::string_body> req_;
|
||||||
|
std::shared_ptr<void> res_;
|
||||||
send_lambda lambda_;
|
send_lambda lambda_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -327,6 +335,9 @@ public:
|
|||||||
if(ec)
|
if(ec)
|
||||||
return fail(ec, "write");
|
return fail(ec, "write");
|
||||||
|
|
||||||
|
// We're done with the response so delete it
|
||||||
|
res_ = nullptr;
|
||||||
|
|
||||||
// Read another request
|
// Read another request
|
||||||
do_read();
|
do_read();
|
||||||
}
|
}
|
||||||
|
@ -8,12 +8,10 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
GroupSources(include/boost/beast beast)
|
GroupSources(include/boost/beast beast)
|
||||||
GroupSources(example/common common)
|
|
||||||
GroupSources(example/http/server/async "/")
|
GroupSources(example/http/server/async "/")
|
||||||
|
|
||||||
add_executable (http-server-async
|
add_executable (http-server-async
|
||||||
${BOOST_BEAST_INCLUDES}
|
${BOOST_BEAST_INCLUDES}
|
||||||
${PROJECT_SOURCE_DIR}/example/common/write_msg.hpp
|
|
||||||
Jamfile
|
Jamfile
|
||||||
http_server_async.cpp
|
http_server_async.cpp
|
||||||
)
|
)
|
||||||
|
@ -13,8 +13,6 @@
|
|||||||
//
|
//
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
#include "example/common/write_msg.hpp"
|
|
||||||
|
|
||||||
#include <boost/beast/core.hpp>
|
#include <boost/beast/core.hpp>
|
||||||
#include <boost/beast/http.hpp>
|
#include <boost/beast/http.hpp>
|
||||||
#include <boost/beast/version.hpp>
|
#include <boost/beast/version.hpp>
|
||||||
@ -228,12 +226,20 @@ class session : public std::enable_shared_from_this<session>
|
|||||||
void
|
void
|
||||||
operator()(http::message<isRequest, Body, Fields>&& msg) const
|
operator()(http::message<isRequest, Body, Fields>&& msg) const
|
||||||
{
|
{
|
||||||
// This function takes ownership of the message by moving
|
// The lifetime of the message has to extend
|
||||||
// it into a temporary buffer, otherwise we would have
|
// for the duration of the async operation so
|
||||||
// to manage the lifetime of the message and serializer.
|
// we use a shared_ptr to manage it.
|
||||||
async_write_msg(
|
auto sp = std::make_shared<
|
||||||
|
http::message<isRequest, Body, Fields>>(std::move(msg));
|
||||||
|
|
||||||
|
// Store a type-erased version of the shared
|
||||||
|
// pointer in the class to keep it alive.
|
||||||
|
self_.res_ = sp;
|
||||||
|
|
||||||
|
// Write the response
|
||||||
|
http::async_write(
|
||||||
self_.socket_,
|
self_.socket_,
|
||||||
std::move(msg),
|
*sp,
|
||||||
self_.strand_.wrap(std::bind(
|
self_.strand_.wrap(std::bind(
|
||||||
&session::on_write,
|
&session::on_write,
|
||||||
self_.shared_from_this(),
|
self_.shared_from_this(),
|
||||||
@ -246,6 +252,7 @@ class session : public std::enable_shared_from_this<session>
|
|||||||
boost::beast::flat_buffer buffer_;
|
boost::beast::flat_buffer buffer_;
|
||||||
std::string const& doc_root_;
|
std::string const& doc_root_;
|
||||||
http::request<http::string_body> req_;
|
http::request<http::string_body> req_;
|
||||||
|
std::shared_ptr<void> res_;
|
||||||
send_lambda lambda_;
|
send_lambda lambda_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -306,6 +313,9 @@ public:
|
|||||||
if(ec)
|
if(ec)
|
||||||
return fail(ec, "write");
|
return fail(ec, "write");
|
||||||
|
|
||||||
|
// We're done with the response so delete it
|
||||||
|
res_ = nullptr;
|
||||||
|
|
||||||
// Read another request
|
// Read another request
|
||||||
do_read();
|
do_read();
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@ add_executable (http-server-flex
|
|||||||
${BOOST_BEAST_INCLUDES}
|
${BOOST_BEAST_INCLUDES}
|
||||||
${PROJECT_SOURCE_DIR}/example/common/detect_ssl.hpp
|
${PROJECT_SOURCE_DIR}/example/common/detect_ssl.hpp
|
||||||
${PROJECT_SOURCE_DIR}/example/common/server_certificate.hpp
|
${PROJECT_SOURCE_DIR}/example/common/server_certificate.hpp
|
||||||
${PROJECT_SOURCE_DIR}/example/common/write_msg.hpp
|
|
||||||
Jamfile
|
Jamfile
|
||||||
http_server_flex.cpp
|
http_server_flex.cpp
|
||||||
)
|
)
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
|
|
||||||
#include "example/common/detect_ssl.hpp"
|
#include "example/common/detect_ssl.hpp"
|
||||||
#include "example/common/server_certificate.hpp"
|
#include "example/common/server_certificate.hpp"
|
||||||
#include "example/common/write_msg.hpp"
|
|
||||||
|
|
||||||
#include <boost/beast/core.hpp>
|
#include <boost/beast/core.hpp>
|
||||||
#include <boost/beast/http.hpp>
|
#include <boost/beast/http.hpp>
|
||||||
@ -242,12 +241,20 @@ class session
|
|||||||
void
|
void
|
||||||
operator()(http::message<isRequest, Body, Fields>&& msg) const
|
operator()(http::message<isRequest, Body, Fields>&& msg) const
|
||||||
{
|
{
|
||||||
// This function takes ownership of the message by moving
|
// The lifetime of the message has to extend
|
||||||
// it into a temporary buffer, otherwise we would have
|
// for the duration of the async operation so
|
||||||
// to manage the lifetime of the message and serializer.
|
// we use a shared_ptr to manage it.
|
||||||
async_write_msg(
|
auto sp = std::make_shared<
|
||||||
|
http::message<isRequest, Body, Fields>>(std::move(msg));
|
||||||
|
|
||||||
|
// Store a type-erased version of the shared
|
||||||
|
// pointer in the class to keep it alive.
|
||||||
|
self_.res_ = sp;
|
||||||
|
|
||||||
|
// Write the response
|
||||||
|
http::async_write(
|
||||||
self_.derived().stream(),
|
self_.derived().stream(),
|
||||||
std::move(msg),
|
*sp,
|
||||||
self_.strand_.wrap(std::bind(
|
self_.strand_.wrap(std::bind(
|
||||||
&session::on_write,
|
&session::on_write,
|
||||||
self_.derived().shared_from_this(),
|
self_.derived().shared_from_this(),
|
||||||
@ -257,6 +264,7 @@ class session
|
|||||||
|
|
||||||
std::string const& doc_root_;
|
std::string const& doc_root_;
|
||||||
http::request<http::string_body> req_;
|
http::request<http::string_body> req_;
|
||||||
|
std::shared_ptr<void> res_;
|
||||||
send_lambda lambda_;
|
send_lambda lambda_;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -318,6 +326,9 @@ public:
|
|||||||
if(ec)
|
if(ec)
|
||||||
return fail(ec, "write");
|
return fail(ec, "write");
|
||||||
|
|
||||||
|
// We're done with the response so delete it
|
||||||
|
res_ = nullptr;
|
||||||
|
|
||||||
// Read another request
|
// Read another request
|
||||||
do_read();
|
do_read();
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ GroupSources(example/http/server/stackless-ssl "/")
|
|||||||
add_executable (http-server-stackless-ssl
|
add_executable (http-server-stackless-ssl
|
||||||
${BOOST_BEAST_INCLUDES}
|
${BOOST_BEAST_INCLUDES}
|
||||||
${PROJECT_SOURCE_DIR}/example/common/server_certificate.hpp
|
${PROJECT_SOURCE_DIR}/example/common/server_certificate.hpp
|
||||||
${PROJECT_SOURCE_DIR}/example/common/write_msg.hpp
|
|
||||||
Jamfile
|
Jamfile
|
||||||
http_server_stackless_ssl.cpp
|
http_server_stackless_ssl.cpp
|
||||||
)
|
)
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
#include "example/common/server_certificate.hpp"
|
#include "example/common/server_certificate.hpp"
|
||||||
#include "example/common/write_msg.hpp"
|
|
||||||
|
|
||||||
#include <boost/beast/core.hpp>
|
#include <boost/beast/core.hpp>
|
||||||
#include <boost/beast/http.hpp>
|
#include <boost/beast/http.hpp>
|
||||||
@ -234,12 +233,20 @@ class session
|
|||||||
void
|
void
|
||||||
operator()(http::message<isRequest, Body, Fields>&& msg) const
|
operator()(http::message<isRequest, Body, Fields>&& msg) const
|
||||||
{
|
{
|
||||||
// This function takes ownership of the message by moving
|
// The lifetime of the message has to extend
|
||||||
// it into a temporary buffer, otherwise we would have
|
// for the duration of the async operation so
|
||||||
// to manage the lifetime of the message and serializer.
|
// we use a shared_ptr to manage it.
|
||||||
async_write_msg(
|
auto sp = std::make_shared<
|
||||||
self_.stream_,
|
http::message<isRequest, Body, Fields>>(std::move(msg));
|
||||||
std::move(msg),
|
|
||||||
|
// Store a type-erased version of the shared
|
||||||
|
// pointer in the class to keep it alive.
|
||||||
|
self_.res_ = sp;
|
||||||
|
|
||||||
|
// Write the response
|
||||||
|
http::async_write(
|
||||||
|
self_.socket_,
|
||||||
|
*sp,
|
||||||
self_.strand_.wrap(std::bind(
|
self_.strand_.wrap(std::bind(
|
||||||
&session::loop,
|
&session::loop,
|
||||||
self_.shared_from_this(),
|
self_.shared_from_this(),
|
||||||
@ -253,6 +260,7 @@ class session
|
|||||||
boost::beast::flat_buffer buffer_;
|
boost::beast::flat_buffer buffer_;
|
||||||
std::string const& doc_root_;
|
std::string const& doc_root_;
|
||||||
http::request<http::string_body> req_;
|
http::request<http::string_body> req_;
|
||||||
|
std::shared_ptr<void> res_;
|
||||||
send_lambda lambda_;
|
send_lambda lambda_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -319,6 +327,9 @@ public:
|
|||||||
}
|
}
|
||||||
if(ec)
|
if(ec)
|
||||||
return fail(ec, "write");
|
return fail(ec, "write");
|
||||||
|
|
||||||
|
// We're done with the response so delete it
|
||||||
|
res_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform the SSL shutdown
|
// Perform the SSL shutdown
|
||||||
|
@ -8,12 +8,10 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
GroupSources(include/boost/beast beast)
|
GroupSources(include/boost/beast beast)
|
||||||
GroupSources(example/common common)
|
|
||||||
GroupSources(example/http/server/stackless "/")
|
GroupSources(example/http/server/stackless "/")
|
||||||
|
|
||||||
add_executable (http-server-stackless
|
add_executable (http-server-stackless
|
||||||
${BOOST_BEAST_INCLUDES}
|
${BOOST_BEAST_INCLUDES}
|
||||||
${PROJECT_SOURCE_DIR}/example/common/write_msg.hpp
|
|
||||||
Jamfile
|
Jamfile
|
||||||
http_server_stackless.cpp
|
http_server_stackless.cpp
|
||||||
)
|
)
|
||||||
|
@ -13,8 +13,6 @@
|
|||||||
//
|
//
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
#include "example/common/write_msg.hpp"
|
|
||||||
|
|
||||||
#include <boost/beast/core.hpp>
|
#include <boost/beast/core.hpp>
|
||||||
#include <boost/beast/http.hpp>
|
#include <boost/beast/http.hpp>
|
||||||
#include <boost/beast/version.hpp>
|
#include <boost/beast/version.hpp>
|
||||||
@ -220,6 +218,7 @@ class session
|
|||||||
struct send_lambda
|
struct send_lambda
|
||||||
{
|
{
|
||||||
session& self_;
|
session& self_;
|
||||||
|
std::shared_ptr<void> res_;
|
||||||
|
|
||||||
explicit
|
explicit
|
||||||
send_lambda(session& self)
|
send_lambda(session& self)
|
||||||
@ -231,12 +230,20 @@ class session
|
|||||||
void
|
void
|
||||||
operator()(http::message<isRequest, Body, Fields>&& msg) const
|
operator()(http::message<isRequest, Body, Fields>&& msg) const
|
||||||
{
|
{
|
||||||
// This function takes ownership of the message by moving
|
// The lifetime of the message has to extend
|
||||||
// it into a temporary buffer, otherwise we would have
|
// for the duration of the async operation so
|
||||||
// to manage the lifetime of the message and serializer.
|
// we use a shared_ptr to manage it.
|
||||||
async_write_msg(
|
auto sp = std::make_shared<
|
||||||
|
http::message<isRequest, Body, Fields>>(std::move(msg));
|
||||||
|
|
||||||
|
// Store a type-erased version of the shared
|
||||||
|
// pointer in the class to keep it alive.
|
||||||
|
self_.res_ = sp;
|
||||||
|
|
||||||
|
// Write the response
|
||||||
|
http::async_write(
|
||||||
self_.socket_,
|
self_.socket_,
|
||||||
std::move(msg),
|
*sp,
|
||||||
self_.strand_.wrap(std::bind(
|
self_.strand_.wrap(std::bind(
|
||||||
&session::loop,
|
&session::loop,
|
||||||
self_.shared_from_this(),
|
self_.shared_from_this(),
|
||||||
@ -249,6 +256,7 @@ class session
|
|||||||
boost::beast::flat_buffer buffer_;
|
boost::beast::flat_buffer buffer_;
|
||||||
std::string const& doc_root_;
|
std::string const& doc_root_;
|
||||||
http::request<http::string_body> req_;
|
http::request<http::string_body> req_;
|
||||||
|
std::shared_ptr<void> res_;
|
||||||
send_lambda lambda_;
|
send_lambda lambda_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -303,6 +311,9 @@ public:
|
|||||||
}
|
}
|
||||||
if(ec)
|
if(ec)
|
||||||
return fail(ec, "write");
|
return fail(ec, "write");
|
||||||
|
|
||||||
|
// We're done with the response so delete it
|
||||||
|
res_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send a TCP shutdown
|
// Send a TCP shutdown
|
||||||
|
Reference in New Issue
Block a user