forked from boostorg/beast
Boost prep
This commit is contained in:
+38
-35
@@ -4,6 +4,8 @@
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// Official repository: https://github.com/boostorg/beast
|
||||
//
|
||||
|
||||
#include "example/server-framework/http_sync_port.hpp"
|
||||
#include "example/server-framework/http_async_port.hpp"
|
||||
@@ -11,18 +13,19 @@
|
||||
#include "example/server-framework/ws_async_port.hpp"
|
||||
#include "example/server-framework/ws_upgrade_service.hpp"
|
||||
|
||||
#if BEAST_USE_OPENSSL
|
||||
#if BOOST_BEAST_USE_OPENSSL
|
||||
# include "example/server-framework/https_ports.hpp"
|
||||
# include "example/server-framework/multi_port.hpp"
|
||||
# include "example/server-framework/ssl_certificate.hpp"
|
||||
# include "example/server-framework/wss_ports.hpp"
|
||||
#endif
|
||||
|
||||
#include <beast/core/drain_buffer.hpp>
|
||||
#include <beast/websocket.hpp>
|
||||
#include <beast/test/yield_to.hpp>
|
||||
#include <beast/unit_test/suite.hpp>
|
||||
#include <boost/beast/core/drain_buffer.hpp>
|
||||
#include <boost/beast/websocket.hpp>
|
||||
#include <boost/beast/test/yield_to.hpp>
|
||||
#include <boost/beast/unit_test/suite.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace beast {
|
||||
namespace websocket {
|
||||
|
||||
@@ -75,7 +78,7 @@ public:
|
||||
req.set(beast::http::field::connection, "close");
|
||||
|
||||
beast::http::write(stream, req, ec);
|
||||
if(! BEAST_EXPECTS(
|
||||
if(! BOOST_BEAST_EXPECTS(
|
||||
ec == beast::http::error::end_of_stream,
|
||||
ec.message()))
|
||||
return;
|
||||
@@ -83,7 +86,7 @@ public:
|
||||
beast::flat_buffer b;
|
||||
beast::http::response<beast::http::string_body> res;
|
||||
beast::http::read(stream, b, res, ec);
|
||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -92,17 +95,17 @@ public:
|
||||
doHello(stream<NextLayer>& ws, error_code& ec)
|
||||
{
|
||||
ws.handshake("localhost", "/", ec);
|
||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
|
||||
return;
|
||||
ws.write(boost::asio::buffer(std::string("Hello, world!")), ec);
|
||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
|
||||
return;
|
||||
beast::multi_buffer b;
|
||||
ws.read(b, ec);
|
||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
|
||||
return;
|
||||
ws.close(beast::websocket::close_code::normal, ec);
|
||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
|
||||
return;
|
||||
// VFALCO Verify the buffer's contents
|
||||
drain_buffer drain;
|
||||
@@ -111,7 +114,7 @@ public:
|
||||
ws.read(drain, ec);
|
||||
if(ec == beast::websocket::error::closed)
|
||||
break;
|
||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -122,7 +125,7 @@ public:
|
||||
error_code ec;
|
||||
boost::asio::ip::tcp::socket con{ios_};
|
||||
con.connect(ep, ec);
|
||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
|
||||
return;
|
||||
doOptions(con, ec);
|
||||
}
|
||||
@@ -133,7 +136,7 @@ public:
|
||||
error_code ec;
|
||||
stream<boost::asio::ip::tcp::socket> ws{ios_};
|
||||
ws.next_layer().connect(ep, ec);
|
||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
|
||||
return;
|
||||
doHello(ws, ec);
|
||||
}
|
||||
@@ -151,7 +154,7 @@ public:
|
||||
address_type::from_string("127.0.0.1"), port_num};
|
||||
auto const wsp = instance.make_port<ws_sync_port>(
|
||||
ec, ep1, instance, log, get_ws_options());
|
||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
|
||||
return;
|
||||
auto const ep2 = endpoint_type{
|
||||
address_type::from_string("127.0.0.1"),
|
||||
@@ -159,10 +162,10 @@ public:
|
||||
auto const sp = instance.make_port<
|
||||
http_sync_port<ws_upgrade_service<ws_sync_port>>>(
|
||||
ec, ep2, instance, log);
|
||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
|
||||
return;
|
||||
sp->template init<0>(ec, *wsp);
|
||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
|
||||
return;
|
||||
|
||||
wsClient(ep1);
|
||||
@@ -179,7 +182,7 @@ public:
|
||||
address_type::from_string("127.0.0.1"), port_num};
|
||||
auto const wsp = instance.make_port<ws_async_port>(
|
||||
ec, ep1, instance, log, get_ws_options());
|
||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
|
||||
return;
|
||||
auto const ep2 = endpoint_type{
|
||||
address_type::from_string("127.0.0.1"),
|
||||
@@ -187,10 +190,10 @@ public:
|
||||
auto const sp = instance.make_port<
|
||||
http_async_port<ws_upgrade_service<ws_async_port>>>(
|
||||
ec, ep2, instance, log);
|
||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
|
||||
return;
|
||||
sp->template init<0>(ec, *wsp);
|
||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
|
||||
return;
|
||||
|
||||
wsClient(ep1);
|
||||
@@ -200,7 +203,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
#if BEAST_USE_OPENSSL
|
||||
#if BOOST_BEAST_USE_OPENSSL
|
||||
//
|
||||
// OpenSSL enabled ports
|
||||
//
|
||||
@@ -212,11 +215,11 @@ public:
|
||||
error_code ec;
|
||||
boost::asio::ssl::stream<boost::asio::ip::tcp::socket> con{ios_, ctx};
|
||||
con.next_layer().connect(ep, ec);
|
||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
|
||||
return;
|
||||
con.handshake(
|
||||
boost::asio::ssl::stream_base::client, ec);
|
||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
|
||||
return;
|
||||
doOptions(con, ec);
|
||||
if(ec)
|
||||
@@ -225,7 +228,7 @@ public:
|
||||
// VFALCO No idea why we get eof in the normal case
|
||||
if(ec == boost::asio::error::eof)
|
||||
ec.assign(0, ec.category());
|
||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -236,11 +239,11 @@ public:
|
||||
error_code ec;
|
||||
stream<boost::asio::ssl::stream<boost::asio::ip::tcp::socket>> wss{ios_, ctx};
|
||||
wss.next_layer().next_layer().connect(ep, ec);
|
||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
|
||||
return;
|
||||
wss.next_layer().handshake(
|
||||
boost::asio::ssl::stream_base::client, ec);
|
||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
|
||||
return;
|
||||
doHello(wss, ec);
|
||||
}
|
||||
@@ -260,7 +263,7 @@ public:
|
||||
address_type::from_string("127.0.0.1"), port_num};
|
||||
auto const wsp = instance.make_port<wss_sync_port>(
|
||||
ec, ep1, instance, log, cert.get(), get_ws_options());
|
||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
|
||||
return;
|
||||
auto const ep2 = endpoint_type{
|
||||
address_type::from_string("127.0.0.1"),
|
||||
@@ -268,10 +271,10 @@ public:
|
||||
auto const sp = instance.make_port<
|
||||
https_sync_port<ws_upgrade_service<wss_sync_port>>>(
|
||||
ec, ep2, instance, log, cert.get());
|
||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
|
||||
return;
|
||||
sp->template init<0>(ec, *wsp);
|
||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
|
||||
return;
|
||||
|
||||
wssClient(ep1, cert.get());
|
||||
@@ -288,7 +291,7 @@ public:
|
||||
address_type::from_string("127.0.0.1"), port_num};
|
||||
auto const wsp = instance.make_port<wss_async_port>(
|
||||
ec, ep1, instance, log, cert.get(), get_ws_options());
|
||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
|
||||
return;
|
||||
auto const ep2 = endpoint_type{
|
||||
address_type::from_string("127.0.0.1"),
|
||||
@@ -296,10 +299,10 @@ public:
|
||||
auto const sp = instance.make_port<
|
||||
https_async_port<ws_upgrade_service<wss_async_port>>>(
|
||||
ec, ep2, instance, log, cert.get());
|
||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
|
||||
return;
|
||||
sp->template init<0>(ec, *wsp);
|
||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
|
||||
return;
|
||||
|
||||
wssClient(ep1, cert.get());
|
||||
@@ -315,14 +318,14 @@ public:
|
||||
{
|
||||
testPlain();
|
||||
|
||||
#if BEAST_USE_OPENSSL
|
||||
#if BOOST_BEAST_USE_OPENSSL
|
||||
testSSL();
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(server,websocket,beast);
|
||||
BOOST_BEAST_DEFINE_TESTSUITE(server,websocket,beast);
|
||||
|
||||
} // websocket
|
||||
} // beast
|
||||
|
||||
} // boost
|
||||
|
||||
Reference in New Issue
Block a user