Boost prep

This commit is contained in:
Vinnie Falco committed 2017-07-23 17:34:13 -07:00
1 parent 3777cb8b9c
commit 7139dd639a
375 files changed
+5253 -3884

No files matched your search

+13 -5
View File
@@ -1,16 +1,24 @@
# Part of Beast
#
# Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
#
# 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
#
GroupSources(extras/beast extras)
GroupSources(include/beast beast)
GroupSources(extras/boost/beast extras)
GroupSources(include/boost/beast beast)
GroupSources(test/websocket "/")
#include_directories(../../example/)
add_executable (websocket-tests
${BEAST_INCLUDES}
${BOOST_BEAST_INCLUDES}
${EXTRAS_INCLUDES}
../../extras/beast/unit_test/main.cpp
Jamfile
../../extras/boost/beast/unit_test/main.cpp
websocket_async_echo_server.hpp
websocket_sync_echo_server.hpp
doc_snippets.cpp
+3 -1
View File
@@ -4,9 +4,11 @@
# 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
#
unit-test websocket-tests :
../../extras/beast/unit_test/main.cpp
../../extras/boost/beast/unit_test/main.cpp
doc_snippets.cpp
error.cpp
option.cpp
+8 -6
View File
@@ -4,8 +4,10 @@
// 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 <beast/core.hpp>
#include <boost/beast/core.hpp>
#include <boost/asio.hpp>
#include <boost/asio/spawn.hpp>
#include <boost/asio/use_future.hpp>
@@ -15,11 +17,11 @@
#include <thread>
//[ws_snippet_1
#include <beast/websocket.hpp>
using namespace beast::websocket;
#include <boost/beast/websocket.hpp>
using namespace boost::beast::websocket;
//]
using namespace beast;
using namespace boost::beast;
namespace doc_ws_snippets {
@@ -233,10 +235,10 @@ void echo(stream<boost::asio::ip::tcp::socket>& ws,
//------------------------------------------------------------------------------
#if BEAST_USE_OPENSSL
#if BOOST_BEAST_USE_OPENSSL
//[wss_snippet_1
#include <beast/websocket/ssl.hpp>
#include <boost/beast/websocket/ssl.hpp>
#include <boost/asio/ssl.hpp>
//]
+12 -8
View File
@@ -4,13 +4,16 @@
// 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
//
// Test that header file is self-contained.
#include <beast/websocket/error.hpp>
#include <boost/beast/websocket/error.hpp>
#include <beast/unit_test/suite.hpp>
#include <boost/beast/unit_test/suite.hpp>
#include <memory>
namespace boost {
namespace beast {
namespace websocket {
@@ -20,15 +23,15 @@ public:
void check(char const* name, error ev)
{
auto const ec = make_error_code(ev);
BEAST_EXPECT(std::string{ec.category().name()} == name);
BEAST_EXPECT(! ec.message().empty());
BEAST_EXPECT(std::addressof(ec.category()) ==
BOOST_BEAST_EXPECT(std::string{ec.category().name()} == name);
BOOST_BEAST_EXPECT(! ec.message().empty());
BOOST_BEAST_EXPECT(std::addressof(ec.category()) ==
std::addressof(detail::get_error_category()));
BEAST_EXPECT(detail::get_error_category().equivalent(
BOOST_BEAST_EXPECT(detail::get_error_category().equivalent(
static_cast<std::underlying_type<error>::type>(ev),
ec.category().default_error_condition(
static_cast<std::underlying_type<error>::type>(ev))));
BEAST_EXPECT(detail::get_error_category().equivalent(
BOOST_BEAST_EXPECT(detail::get_error_category().equivalent(
ec, static_cast<std::underlying_type<error>::type>(ev)));
}
@@ -41,7 +44,8 @@ public:
}
};
BEAST_DEFINE_TESTSUITE(error,websocket,beast);
BOOST_BEAST_DEFINE_TESTSUITE(error,websocket,beast);
} // websocket
} // beast
} // boost
+35 -31
View File
@@ -4,15 +4,18 @@
// 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 <beast/websocket/stream.hpp>
#include <beast/websocket/detail/frame.hpp>
#include <beast/unit_test/suite.hpp>
#include <beast/test/pipe_stream.hpp>
#include <beast/test/yield_to.hpp>
#include <boost/beast/websocket/stream.hpp>
#include <boost/beast/websocket/detail/frame.hpp>
#include <boost/beast/unit_test/suite.hpp>
#include <boost/beast/test/pipe_stream.hpp>
#include <boost/beast/test/yield_to.hpp>
#include <initializer_list>
#include <climits>
namespace boost {
namespace beast {
namespace websocket {
namespace detail {
@@ -39,20 +42,20 @@ class frame_test
public:
void testCloseCodes()
{
BEAST_EXPECT(! is_valid_close_code(0));
BEAST_EXPECT(! is_valid_close_code(1));
BEAST_EXPECT(! is_valid_close_code(999));
BEAST_EXPECT(! is_valid_close_code(1004));
BEAST_EXPECT(! is_valid_close_code(1005));
BEAST_EXPECT(! is_valid_close_code(1006));
BEAST_EXPECT(! is_valid_close_code(1016));
BEAST_EXPECT(! is_valid_close_code(2000));
BEAST_EXPECT(! is_valid_close_code(2999));
BEAST_EXPECT(is_valid_close_code(1000));
BEAST_EXPECT(is_valid_close_code(1002));
BEAST_EXPECT(is_valid_close_code(3000));
BEAST_EXPECT(is_valid_close_code(4000));
BEAST_EXPECT(is_valid_close_code(5000));
BOOST_BEAST_EXPECT(! is_valid_close_code(0));
BOOST_BEAST_EXPECT(! is_valid_close_code(1));
BOOST_BEAST_EXPECT(! is_valid_close_code(999));
BOOST_BEAST_EXPECT(! is_valid_close_code(1004));
BOOST_BEAST_EXPECT(! is_valid_close_code(1005));
BOOST_BEAST_EXPECT(! is_valid_close_code(1006));
BOOST_BEAST_EXPECT(! is_valid_close_code(1016));
BOOST_BEAST_EXPECT(! is_valid_close_code(2000));
BOOST_BEAST_EXPECT(! is_valid_close_code(2999));
BOOST_BEAST_EXPECT(is_valid_close_code(1000));
BOOST_BEAST_EXPECT(is_valid_close_code(1002));
BOOST_BEAST_EXPECT(is_valid_close_code(3000));
BOOST_BEAST_EXPECT(is_valid_close_code(4000));
BOOST_BEAST_EXPECT(is_valid_close_code(5000));
}
struct test_fh : frame_header
@@ -92,16 +95,16 @@ public:
detail::frame_header fh1;
auto const n =
stream.read_fh1(fh1, b, code);
if(! BEAST_EXPECT(! code))
if(! BOOST_BEAST_EXPECT(! code))
return;
if(! BEAST_EXPECT(b.size() == n))
if(! BOOST_BEAST_EXPECT(b.size() == n))
return;
stream.read_fh2(fh1, b, code);
if(! BEAST_EXPECT(! code))
if(! BOOST_BEAST_EXPECT(! code))
return;
if(! BEAST_EXPECT(b.size() == 0))
if(! BOOST_BEAST_EXPECT(b.size() == 0))
return;
BEAST_EXPECT(fh1 == fh);
BOOST_BEAST_EXPECT(fh1 == fh);
};
test_fh fh;
@@ -149,12 +152,12 @@ public:
pass();
return;
}
if(! BEAST_EXPECT(b.size() == n))
if(! BOOST_BEAST_EXPECT(b.size() == n))
return;
stream.read_fh2(fh1, b, code);
if(! BEAST_EXPECT(code))
if(! BOOST_BEAST_EXPECT(code))
return;
if(! BEAST_EXPECT(b.size() == 0))
if(! BOOST_BEAST_EXPECT(b.size() == 0))
return;
};
@@ -218,12 +221,12 @@ public:
pass();
return;
}
if(! BEAST_EXPECT(b.size() == n))
if(! BOOST_BEAST_EXPECT(b.size() == n))
return;
stream.read_fh2(fh, b, code);
if(! BEAST_EXPECT(code))
if(! BOOST_BEAST_EXPECT(code))
return;
if(! BEAST_EXPECT(b.size() == 0))
if(! BOOST_BEAST_EXPECT(b.size() == 0))
return;
}
@@ -246,8 +249,9 @@ public:
}
};
BEAST_DEFINE_TESTSUITE(frame,websocket,beast);
BOOST_BEAST_DEFINE_TESTSUITE(frame,websocket,beast);
} // detail
} // websocket
} // beast
} // boost
+8 -5
View File
@@ -4,12 +4,15 @@
// 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
//
// Test that header file is self-contained.
#include <beast/websocket/detail/mask.hpp>
#include <boost/beast/websocket/detail/mask.hpp>
#include <beast/unit_test/suite.hpp>
#include <boost/beast/unit_test/suite.hpp>
namespace boost {
namespace beast {
namespace websocket {
namespace detail {
@@ -43,13 +46,13 @@ public:
void run() override
{
maskgen_t<test_generator> mg;
BEAST_EXPECT(mg() != 0);
BOOST_BEAST_EXPECT(mg() != 0);
}
};
BEAST_DEFINE_TESTSUITE(mask,websocket,beast);
BOOST_BEAST_DEFINE_TESTSUITE(mask,websocket,beast);
} // detail
} // websocket
} // beast
} // boost
+3 -1
View File
@@ -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
//
// Test that header file is self-contained.
#include <beast/websocket/option.hpp>
#include <boost/beast/websocket/option.hpp>
+12 -8
View File
@@ -4,12 +4,15 @@
// 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
//
// Test that header file is self-contained.
#include <beast/websocket/rfc6455.hpp>
#include <boost/beast/websocket/rfc6455.hpp>
#include <beast/unit_test/suite.hpp>
#include <boost/beast/unit_test/suite.hpp>
namespace boost {
namespace beast {
namespace websocket {
@@ -22,18 +25,18 @@ public:
{
http::header<true> req;
req.version = 10;
BEAST_EXPECT(! is_upgrade(req));
BOOST_BEAST_EXPECT(! is_upgrade(req));
req.version = 11;
req.method(http::verb::post);
req.target("/");
BEAST_EXPECT(! is_upgrade(req));
BOOST_BEAST_EXPECT(! is_upgrade(req));
req.method(http::verb::get);
req.insert("Connection", "upgrade");
BEAST_EXPECT(! is_upgrade(req));
BOOST_BEAST_EXPECT(! is_upgrade(req));
req.insert("Upgrade", "websocket");
BEAST_EXPECT(! is_upgrade(req));
BOOST_BEAST_EXPECT(! is_upgrade(req));
req.insert("Sec-WebSocket-Version", "13");
BEAST_EXPECT(is_upgrade(req));
BOOST_BEAST_EXPECT(is_upgrade(req));
}
void
@@ -43,7 +46,8 @@ public:
}
};
BEAST_DEFINE_TESTSUITE(rfc6455,websocket,beast);
BOOST_BEAST_DEFINE_TESTSUITE(rfc6455,websocket,beast);
} // websocket
} // beast
} // boost
+89 -85
View File
@@ -4,27 +4,30 @@
// 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
//
// Test that header file is self-contained.
#include <beast/websocket/stream.hpp>
#include <boost/beast/websocket/stream.hpp>
#include "websocket_async_echo_server.hpp"
#include "websocket_sync_echo_server.hpp"
#include <beast/core/ostream.hpp>
#include <beast/core/multi_buffer.hpp>
#include <beast/test/fail_stream.hpp>
#include <beast/test/string_istream.hpp>
#include <beast/test/string_iostream.hpp>
#include <beast/test/string_ostream.hpp>
#include <beast/test/yield_to.hpp>
#include <beast/unit_test/suite.hpp>
#include <boost/beast/core/ostream.hpp>
#include <boost/beast/core/multi_buffer.hpp>
#include <boost/beast/test/fail_stream.hpp>
#include <boost/beast/test/string_istream.hpp>
#include <boost/beast/test/string_iostream.hpp>
#include <boost/beast/test/string_ostream.hpp>
#include <boost/beast/test/yield_to.hpp>
#include <boost/beast/unit_test/suite.hpp>
#include <boost/asio.hpp>
#include <boost/asio/spawn.hpp>
#include <boost/optional.hpp>
#include <mutex>
#include <condition_variable>
namespace boost {
namespace beast {
namespace websocket {
@@ -624,7 +627,7 @@ public:
, 20};
bool called = false;
c.accept_ex(ws, res_decorator{called});
BEAST_EXPECT(called);
BOOST_BEAST_EXPECT(called);
}
// request in buffers
{
@@ -653,7 +656,7 @@ public:
"Sec-WebSocket-Version: 13\r\n"
"\r\n"),
res_decorator{called});
BEAST_EXPECT(called);
BOOST_BEAST_EXPECT(called);
}
// request in buffers and stream
{
@@ -684,7 +687,7 @@ public:
"Host: localhost\r\n"
"Upgrade: websocket\r\n"),
res_decorator{called});
BEAST_EXPECT(called);
BOOST_BEAST_EXPECT(called);
}
// request in message
{
@@ -716,7 +719,7 @@ public:
bool called = false;
c.accept_ex(ws, req,
res_decorator{called});
BEAST_EXPECT(called);
BOOST_BEAST_EXPECT(called);
}
// request in message, close frame in buffers
{
@@ -761,7 +764,7 @@ public:
c.accept_ex(ws, req,
cbuf(0x88, 0x82, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x17),
res_decorator{called});
BEAST_EXPECT(called);
BOOST_BEAST_EXPECT(called);
try
{
multi_buffer b;
@@ -861,7 +864,7 @@ public:
}
break;
}
BEAST_EXPECT(n < limit);
BOOST_BEAST_EXPECT(n < limit);
}
void
@@ -932,7 +935,7 @@ public:
bool called = false;
c.handshake_ex(ws, "localhost", "/",
req_decorator{called});
BEAST_EXPECT(called);
BOOST_BEAST_EXPECT(called);
}
// handshake_ex, response
{
@@ -944,7 +947,7 @@ public:
c.handshake_ex(ws, res, "localhost", "/",
req_decorator{called});
// VFALCO validate res?
BEAST_EXPECT(called);
BOOST_BEAST_EXPECT(called);
}
}
catch(system_error const&)
@@ -953,7 +956,7 @@ public:
}
break;
}
BEAST_EXPECT(n < limit);
BOOST_BEAST_EXPECT(n < limit);
}
void
@@ -964,7 +967,7 @@ public:
auto const any = endpoint_type{
address_type::from_string("127.0.0.1"), 0};
server.open(any, ec);
BEAST_EXPECTS(! ec, ec.message());
BOOST_BEAST_EXPECTS(! ec, ec.message());
auto const ep = server.local_endpoint();
testHandshake(ep, SyncClient{});
yield_to(
@@ -989,11 +992,11 @@ public:
{
ws.accept(
boost::asio::buffer(s.data(), i));
BEAST_EXPECTS(! ev, ev.message());
BOOST_BEAST_EXPECTS(! ev, ev.message());
}
catch(system_error const& se)
{
BEAST_EXPECTS(se.code() == ev, se.what());
BOOST_BEAST_EXPECTS(se.code() == ev, se.what());
}
}
};
@@ -1099,7 +1102,7 @@ public:
}
catch(system_error const& se)
{
BEAST_EXPECT(se.code() == error::handshake_failed);
BOOST_BEAST_EXPECT(se.code() == error::handshake_failed);
}
};
// wrong HTTP version
@@ -1174,20 +1177,20 @@ public:
error_code ec = test::error::fail_error;
socket_type sock(ios_);
sock.connect(ep, ec);
if(! BEAST_EXPECTS(! ec, ec.message()))
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
break;
stream<socket_type&> ws(sock);
ws.handshake("localhost", "/", ec);
if(! BEAST_EXPECTS(! ec, ec.message()))
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
break;
ws.write(boost::asio::buffer(v), ec);
if(! BEAST_EXPECTS(! ec, ec.message()))
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
break;
multi_buffer db;
ws.read(db, ec);
if(! BEAST_EXPECTS(! ec, ec.message()))
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
break;
BEAST_EXPECT(to_string(db.data()) ==
BOOST_BEAST_EXPECT(to_string(db.data()) ==
std::string(v.data(), v.size()));
v.push_back(n+1);
}
@@ -1199,20 +1202,20 @@ public:
error_code ec = test::error::fail_error;
socket_type sock(ios_);
sock.connect(ep, ec);
if(! BEAST_EXPECTS(! ec, ec.message()))
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
break;
stream<socket_type&> ws(sock);
ws.handshake("localhost", "/", ec);
if(! BEAST_EXPECTS(! ec, ec.message()))
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
break;
ws.async_write(boost::asio::buffer(v), do_yield[ec]);
if(! BEAST_EXPECTS(! ec, ec.message()))
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
break;
multi_buffer db;
ws.async_read(db, do_yield[ec]);
if(! BEAST_EXPECTS(! ec, ec.message()))
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
break;
BEAST_EXPECT(to_string(db.data()) ==
BOOST_BEAST_EXPECT(to_string(db.data()) ==
std::string(v.data(), v.size()));
v.push_back(n+1);
}
@@ -1289,7 +1292,7 @@ public:
{
++count;
// Send is canceled because close received.
BEAST_EXPECT(ec == boost::asio::
BOOST_BEAST_EXPECT(ec == boost::asio::
error::operation_aborted,
ec.message());
// Writes after close are aborted.
@@ -1297,7 +1300,7 @@ public:
[&](error_code ec)
{
++count;
BEAST_EXPECT(ec == boost::asio::
BOOST_BEAST_EXPECT(ec == boost::asio::
error::operation_aborted,
ec.message());
});
@@ -1311,7 +1314,7 @@ public:
break;
ios.run_one();
}
BEAST_EXPECT(n < limit);
BOOST_BEAST_EXPECT(n < limit);
ios.run();
}
#endif
@@ -1336,14 +1339,14 @@ public:
{
// Read should fail with protocol error
++count;
BEAST_EXPECTS(
BOOST_BEAST_EXPECTS(
ec == error::failed, ec.message());
// Reads after failure are aborted
ws.async_read(db,
[&](error_code ec)
{
++count;
BEAST_EXPECTS(ec == boost::asio::
BOOST_BEAST_EXPECTS(ec == boost::asio::
error::operation_aborted,
ec.message());
});
@@ -1358,7 +1361,7 @@ public:
{
++count;
// Send is canceled because close received.
BEAST_EXPECTS(ec == boost::asio::
BOOST_BEAST_EXPECTS(ec == boost::asio::
error::operation_aborted,
ec.message());
// Writes after close are aborted.
@@ -1366,7 +1369,7 @@ public:
[&](error_code ec)
{
++count;
BEAST_EXPECTS(ec == boost::asio::
BOOST_BEAST_EXPECTS(ec == boost::asio::
error::operation_aborted,
ec.message());
});
@@ -1380,7 +1383,7 @@ public:
break;
ios.run_one();
}
BEAST_EXPECT(n < limit);
BOOST_BEAST_EXPECT(n < limit);
ios.run();
}
@@ -1403,19 +1406,19 @@ public:
{
// Read should complete with error::closed
++count;
BEAST_EXPECTS(ec == error::closed,
BOOST_BEAST_EXPECTS(ec == error::closed,
ec.message());
// Pings after a close are aborted
ws.async_ping("",
[&](error_code ec)
{
++count;
BEAST_EXPECTS(ec == boost::asio::
BOOST_BEAST_EXPECTS(ec == boost::asio::
error::operation_aborted,
ec.message());
});
});
if(! BEAST_EXPECT(run_until(ios, 100,
if(! BOOST_BEAST_EXPECT(run_until(ios, 100,
[&]{ return ws.wr_close_; })))
return;
// Try to ping
@@ -1424,7 +1427,7 @@ public:
{
// Pings after a close are aborted
++count;
BEAST_EXPECTS(ec == boost::asio::
BOOST_BEAST_EXPECTS(ec == boost::asio::
error::operation_aborted,
ec.message());
// Subsequent calls to close are aborted
@@ -1432,7 +1435,7 @@ public:
[&](error_code ec)
{
++count;
BEAST_EXPECTS(ec == boost::asio::
BOOST_BEAST_EXPECTS(ec == boost::asio::
error::operation_aborted,
ec.message());
});
@@ -1445,7 +1448,7 @@ public:
break;
ios.run_one();
}
BEAST_EXPECT(n < limit);
BOOST_BEAST_EXPECT(n < limit);
ios.run();
}
@@ -1465,7 +1468,7 @@ public:
[&](error_code ec)
{
++count;
BEAST_EXPECTS(ec == error::closed,
BOOST_BEAST_EXPECTS(ec == error::closed,
ec.message());
});
while(! ws.wr_block_)
@@ -1475,7 +1478,7 @@ public:
[&](error_code ec)
{
++count;
BEAST_EXPECTS(ec == boost::asio::
BOOST_BEAST_EXPECTS(ec == boost::asio::
error::operation_aborted,
ec.message());
});
@@ -1487,7 +1490,7 @@ public:
break;
ios.run_one();
}
BEAST_EXPECT(n < limit);
BOOST_BEAST_EXPECT(n < limit);
ios.run();
}
@@ -1502,20 +1505,20 @@ public:
ws.async_write(sbuf("CLOSE"),
[&](error_code ec)
{
BEAST_EXPECT(! ec);
BOOST_BEAST_EXPECT(! ec);
ws.async_write(sbuf("PING"),
[&](error_code ec)
{
BEAST_EXPECT(! ec);
BOOST_BEAST_EXPECT(! ec);
});
});
multi_buffer db;
ws.async_read(db,
[&](error_code ec)
{
BEAST_EXPECTS(ec == error::closed, ec.message());
BOOST_BEAST_EXPECTS(ec == error::closed, ec.message());
});
if(! BEAST_EXPECT(run_until(ios, 100,
if(! BOOST_BEAST_EXPECT(run_until(ios, 100,
[&]{ return ios.stopped(); })))
return;
}
@@ -1532,17 +1535,17 @@ public:
error_code ec;
socket_type sock{ios_};
sock.connect(ep, ec);
if(! BEAST_EXPECTS(! ec, ec.message()))
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
return;
stream<socket_type&> ws{sock};
ws.handshake("localhost", "/", ec);
if(! BEAST_EXPECTS(! ec, ec.message()))
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
return;
ws.write_some(false, sbuf("u"));
ws.write_some(true, sbuf("v"));
multi_buffer b;
ws.read(b, ec);
if(! BEAST_EXPECTS(! ec, ec.message()))
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
return;
}
@@ -1555,11 +1558,11 @@ public:
error_code ec;
socket_type sock(ios);
sock.connect(ep, ec);
if(! BEAST_EXPECTS(! ec, ec.message()))
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
break;
stream<socket_type&> ws(sock);
ws.handshake("localhost", "/", ec);
if(! BEAST_EXPECTS(! ec, ec.message()))
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
break;
ws.async_write_some(false,
boost::asio::null_buffers{},
@@ -1568,7 +1571,7 @@ public:
fail();
});
ws.next_layer().cancel(ec);
if(! BEAST_EXPECTS(! ec, ec.message()))
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
break;
//
// Destruction of the io_service will cause destruction
@@ -1611,7 +1614,7 @@ public:
}
error_code ec;
ws.lowest_layer().connect(ep, ec);
if(! BEAST_EXPECTS(! ec, ec.message()))
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
throw abort_test{};
c.handshake(ws, "localhost", "/");
};
@@ -1621,7 +1624,7 @@ public:
// connect
error_code ec;
ws.lowest_layer().connect(ep, ec);
if(! BEAST_EXPECTS(! ec, ec.message()))
if(! BOOST_BEAST_EXPECTS(! ec, ec.message()))
return;
}
c.handshake(ws, "localhost", "/");
@@ -1634,8 +1637,8 @@ public:
// receive echoed message
multi_buffer db;
c.read(ws, db);
BEAST_EXPECT(ws.got_text());
BEAST_EXPECT(to_string(db.data()) == "Hello");
BOOST_BEAST_EXPECT(ws.got_text());
BOOST_BEAST_EXPECT(to_string(db.data()) == "Hello");
}
// close, no payload
@@ -1657,10 +1660,10 @@ public:
ws.control_callback(
[&](frame_type kind, string_view s)
{
BEAST_EXPECT(kind == frame_type::pong);
BEAST_EXPECT(! once);
BOOST_BEAST_EXPECT(kind == frame_type::pong);
BOOST_BEAST_EXPECT(! once);
once = true;
BEAST_EXPECT(s == "");
BOOST_BEAST_EXPECT(s == "");
});
c.ping(ws, "");
ws.binary(true);
@@ -1669,9 +1672,9 @@ public:
// receive echoed message
multi_buffer db;
c.read(ws, db);
BEAST_EXPECT(once);
BEAST_EXPECT(ws.got_binary());
BEAST_EXPECT(to_string(db.data()) == "Hello");
BOOST_BEAST_EXPECT(once);
BOOST_BEAST_EXPECT(ws.got_binary());
BOOST_BEAST_EXPECT(to_string(db.data()) == "Hello");
}
ws.control_callback({});
@@ -1680,10 +1683,10 @@ public:
ws.control_callback(
[&](frame_type kind, string_view s)
{
BEAST_EXPECT(kind == frame_type::pong);
BEAST_EXPECT(! once);
BOOST_BEAST_EXPECT(kind == frame_type::pong);
BOOST_BEAST_EXPECT(! once);
once = true;
BEAST_EXPECT(s == "payload");
BOOST_BEAST_EXPECT(s == "payload");
});
ws.ping("payload");
c.write_some(ws, false, sbuf("Hello, "));
@@ -1693,8 +1696,8 @@ public:
// receive echoed message
multi_buffer db;
c.read(ws, db);
BEAST_EXPECT(once);
BEAST_EXPECT(to_string(db.data()) == "Hello, World!");
BOOST_BEAST_EXPECT(once);
BOOST_BEAST_EXPECT(to_string(db.data()) == "Hello, World!");
}
ws.control_callback({});
@@ -1709,7 +1712,7 @@ public:
// receive echoed message
multi_buffer b;
c.read(ws, b);
BEAST_EXPECT(to_string(b.data()) == "Now is the time for all good men");
BOOST_BEAST_EXPECT(to_string(b.data()) == "Now is the time for all good men");
}
ws.auto_fragment(false);
ws.write_buffer_size(4096);
@@ -1723,7 +1726,7 @@ public:
// receive echoed message
multi_buffer db;
c.read(ws, db);
BEAST_EXPECT(to_string(db.data()) == s);
BOOST_BEAST_EXPECT(to_string(db.data()) == s);
}
}
@@ -1736,8 +1739,8 @@ public:
// receive echoed message
multi_buffer db;
c.read(ws, db);
BEAST_EXPECT(ws.got_text());
BEAST_EXPECT(to_string(db.data()) == "Hello");
BOOST_BEAST_EXPECT(ws.got_text());
BOOST_BEAST_EXPECT(to_string(db.data()) == "Hello");
}
// cause close
@@ -1807,7 +1810,7 @@ public:
}
break;
}
BEAST_EXPECT(n < limit);
BOOST_BEAST_EXPECT(n < limit);
}
void
@@ -1852,7 +1855,7 @@ public:
::websocket::sync_echo_server server{nullptr};
server.set_option(pmd);
server.open(any, ec);
BEAST_EXPECTS(! ec, ec.message());
BOOST_BEAST_EXPECTS(! ec, ec.message());
auto const ep = server.local_endpoint();
//testPausation1(ep);
testPausation2(ep);
@@ -1867,7 +1870,7 @@ public:
error_code ec;
::websocket::async_echo_server server{nullptr, 4};
server.open(any, ec);
BEAST_EXPECTS(! ec, ec.message());
BOOST_BEAST_EXPECTS(! ec, ec.message());
auto const ep = server.local_endpoint();
testAsyncWriteFrame(ep);
}
@@ -1880,7 +1883,7 @@ public:
::websocket::sync_echo_server server{nullptr};
server.set_option(pmd);
server.open(any, ec);
BEAST_EXPECTS(! ec, ec.message());
BOOST_BEAST_EXPECTS(! ec, ec.message());
auto const ep = server.local_endpoint();
testEndpoint(SyncClient{}, ep, pmd);
yield_to(
@@ -1895,7 +1898,7 @@ public:
::websocket::async_echo_server server{nullptr, 4};
server.set_option(pmd);
server.open(any, ec);
BEAST_EXPECTS(! ec, ec.message());
BOOST_BEAST_EXPECTS(! ec, ec.message());
auto const ep = server.local_endpoint();
testEndpoint(SyncClient{}, ep, pmd);
yield_to(
@@ -1911,7 +1914,7 @@ public:
pmd.server_enable = false;
doClientTests(pmd);
#if ! BEAST_NO_SLOW_TESTS
#if ! BOOST_BEAST_NO_SLOW_TESTS
pmd.client_enable = true;
pmd.server_enable = true;
pmd.client_max_window_bits = 10;
@@ -1927,7 +1930,8 @@ public:
}
};
BEAST_DEFINE_TESTSUITE(stream,websocket,beast);
BOOST_BEAST_DEFINE_TESTSUITE(stream,websocket,beast);
} // websocket
} // beast
} // boost
+3 -1
View File
@@ -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
//
// Test that header file is self-contained.
#include <beast/websocket/teardown.hpp>
#include <boost/beast/websocket/teardown.hpp>
+66 -62
View File
@@ -4,15 +4,18 @@
// 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
//
// Test that header file is self-contained.
#include <beast/websocket/detail/utf8_checker.hpp>
#include <boost/beast/websocket/detail/utf8_checker.hpp>
#include <beast/core/consuming_buffers.hpp>
#include <beast/core/multi_buffer.hpp>
#include <beast/unit_test/suite.hpp>
#include <boost/beast/core/consuming_buffers.hpp>
#include <boost/beast/core/multi_buffer.hpp>
#include <boost/beast/unit_test/suite.hpp>
#include <array>
namespace boost {
namespace beast {
namespace websocket {
namespace detail {
@@ -35,22 +38,22 @@ public:
})();
// Valid range 0-127
BEAST_EXPECT(utf8.write(buf.data(), 128));
BEAST_EXPECT(utf8.finish());
BOOST_BEAST_EXPECT(utf8.write(buf.data(), 128));
BOOST_BEAST_EXPECT(utf8.finish());
// Invalid range 128-193
for(auto it = std::next(buf.begin(), 128);
it != std::next(buf.begin(), 194); ++it)
BEAST_EXPECT(! utf8.write(&(*it), 1));
BOOST_BEAST_EXPECT(! utf8.write(&(*it), 1));
// Invalid range 245-255
for(auto it = std::next(buf.begin(), 245);
it != buf.end(); ++it)
BEAST_EXPECT(! utf8.write(&(*it), 1));
BOOST_BEAST_EXPECT(! utf8.write(&(*it), 1));
// Invalid sequence
std::fill(buf.begin(), buf.end(), '\xff');
BEAST_EXPECT(! utf8.write(&buf.front(), buf.size()));
BOOST_BEAST_EXPECT(! utf8.write(&buf.front(), buf.size()));
}
void
@@ -67,27 +70,27 @@ public:
{
// Second byte valid range 128-191
buf[1] = static_cast<std::uint8_t>(j);
BEAST_EXPECT(utf8.write(buf, 2));
BEAST_EXPECT(utf8.finish());
BOOST_BEAST_EXPECT(utf8.write(buf, 2));
BOOST_BEAST_EXPECT(utf8.finish());
}
for(auto j = 0; j <= 127; ++j)
{
// Second byte invalid range 0-127
buf[1] = static_cast<std::uint8_t>(j);
BEAST_EXPECT(! utf8.write(buf, 2));
BOOST_BEAST_EXPECT(! utf8.write(buf, 2));
}
for(auto j = 192; j <= 255; ++j)
{
// Second byte invalid range 192-255
buf[1] = static_cast<std::uint8_t>(j);
BEAST_EXPECT(! utf8.write(buf, 2));
BOOST_BEAST_EXPECT(! utf8.write(buf, 2));
}
// Segmented sequence second byte invalid
BEAST_EXPECT(utf8.write(buf, 1));
BEAST_EXPECT(! utf8.write(&buf[1], 1));
BOOST_BEAST_EXPECT(utf8.write(buf, 1));
BOOST_BEAST_EXPECT(! utf8.write(&buf[1], 1));
utf8.reset();
}
}
@@ -113,15 +116,15 @@ public:
{
// Third byte valid range 128-191
buf[2] = static_cast<std::uint8_t>(k);
BEAST_EXPECT(utf8.write(buf, 3));
BEAST_EXPECT(utf8.finish());
BOOST_BEAST_EXPECT(utf8.write(buf, 3));
BOOST_BEAST_EXPECT(utf8.finish());
// Segmented sequence
BEAST_EXPECT(utf8.write(buf, 1));
BEAST_EXPECT(utf8.write(&buf[1], 2));
BOOST_BEAST_EXPECT(utf8.write(buf, 1));
BOOST_BEAST_EXPECT(utf8.write(&buf[1], 2));
utf8.reset();
// Segmented sequence
BEAST_EXPECT(utf8.write(buf, 2));
BEAST_EXPECT(utf8.write(&buf[2], 1));
BOOST_BEAST_EXPECT(utf8.write(buf, 2));
BOOST_BEAST_EXPECT(utf8.write(&buf[2], 1));
utf8.reset();
if (i == 224)
@@ -130,11 +133,11 @@ public:
{
// Second byte invalid range 0-127 or 0-159
buf[1] = static_cast<std::uint8_t>(l);
BEAST_EXPECT(! utf8.write(buf, 3));
BOOST_BEAST_EXPECT(! utf8.write(buf, 3));
if (l > 127)
{
// Segmented sequence second byte invalid
BEAST_EXPECT(! utf8.write(buf, 2));
BOOST_BEAST_EXPECT(! utf8.write(buf, 2));
utf8.reset();
}
}
@@ -146,11 +149,11 @@ public:
{
// Second byte invalid range 160-255 or 192-255
buf[1] = static_cast<std::uint8_t>(l);
BEAST_EXPECT(!utf8.write(buf, 3));
BOOST_BEAST_EXPECT(!utf8.write(buf, 3));
if (l > 159)
{
// Segmented sequence second byte invalid
BEAST_EXPECT(! utf8.write(buf, 2));
BOOST_BEAST_EXPECT(! utf8.write(buf, 2));
utf8.reset();
}
}
@@ -162,19 +165,19 @@ public:
{
// Third byte invalid range 0-127
buf[2] = static_cast<std::uint8_t>(k);
BEAST_EXPECT(! utf8.write(buf, 3));
BOOST_BEAST_EXPECT(! utf8.write(buf, 3));
}
for(auto k = 192; k <= 255; ++k)
{
// Third byte invalid range 192-255
buf[2] = static_cast<std::uint8_t>(k);
BEAST_EXPECT(! utf8.write(buf, 3));
BOOST_BEAST_EXPECT(! utf8.write(buf, 3));
}
// Segmented sequence third byte invalid
BEAST_EXPECT(utf8.write(buf, 2));
BEAST_EXPECT(! utf8.write(&buf[2], 1));
BOOST_BEAST_EXPECT(utf8.write(buf, 2));
BOOST_BEAST_EXPECT(! utf8.write(&buf[2], 1));
utf8.reset();
}
@@ -182,19 +185,19 @@ public:
{
// Second byte invalid range 0-127 or 0-159
buf[1] = static_cast<std::uint8_t>(j);
BEAST_EXPECT(! utf8.write(buf, 3));
BOOST_BEAST_EXPECT(! utf8.write(buf, 3));
}
for(auto j = e + 1; j <= 255; ++j)
{
// Second byte invalid range 160-255 or 192-255
buf[1] = static_cast<std::uint8_t>(j);
BEAST_EXPECT(! utf8.write(buf, 3));
BOOST_BEAST_EXPECT(! utf8.write(buf, 3));
}
// Segmented sequence second byte invalid
BEAST_EXPECT(utf8.write(buf, 1));
BEAST_EXPECT(! utf8.write(&buf[1], 1));
BOOST_BEAST_EXPECT(utf8.write(buf, 1));
BOOST_BEAST_EXPECT(! utf8.write(&buf[1], 1));
utf8.reset();
}
}
@@ -226,19 +229,19 @@ public:
{
// Fourth byte valid range 128-191
buf[3] = static_cast<std::uint8_t>(n);
BEAST_EXPECT(utf8.write(const_buffers_1{buf, 4}));
BEAST_EXPECT(utf8.finish());
BOOST_BEAST_EXPECT(utf8.write(const_buffers_1{buf, 4}));
BOOST_BEAST_EXPECT(utf8.finish());
// Segmented sequence
BEAST_EXPECT(utf8.write(buf, 1));
BEAST_EXPECT(utf8.write(&buf[1], 3));
BOOST_BEAST_EXPECT(utf8.write(buf, 1));
BOOST_BEAST_EXPECT(utf8.write(&buf[1], 3));
utf8.reset();
// Segmented sequence
BEAST_EXPECT(utf8.write(buf, 2));
BEAST_EXPECT(utf8.write(&buf[2], 2));
BOOST_BEAST_EXPECT(utf8.write(buf, 2));
BOOST_BEAST_EXPECT(utf8.write(&buf[2], 2));
utf8.reset();
// Segmented sequence
BEAST_EXPECT(utf8.write(buf, 3));
BEAST_EXPECT(utf8.write(&buf[3], 1));
BOOST_BEAST_EXPECT(utf8.write(buf, 3));
BOOST_BEAST_EXPECT(utf8.write(&buf[3], 1));
utf8.reset();
if (i == 240)
@@ -247,11 +250,11 @@ public:
{
// Second byte invalid range 0-127 or 0-143
buf[1] = static_cast<std::uint8_t>(l);
BEAST_EXPECT(! utf8.write(buf, 4));
BOOST_BEAST_EXPECT(! utf8.write(buf, 4));
if (l > 127)
{
// Segmented sequence second byte invalid
BEAST_EXPECT(! utf8.write(buf, 2));
BOOST_BEAST_EXPECT(! utf8.write(buf, 2));
utf8.reset();
}
}
@@ -263,11 +266,11 @@ public:
{
// Second byte invalid range 144-255 or 192-255
buf[1] = static_cast<std::uint8_t>(l);
BEAST_EXPECT(! utf8.write(buf, 4));
BOOST_BEAST_EXPECT(! utf8.write(buf, 4));
if (l > 143)
{
// Segmented sequence second byte invalid
BEAST_EXPECT(! utf8.write(buf, 2));
BOOST_BEAST_EXPECT(! utf8.write(buf, 2));
utf8.reset();
}
}
@@ -279,19 +282,19 @@ public:
{
// Fourth byte invalid range 0-127
buf[3] = static_cast<std::uint8_t>(n);
BEAST_EXPECT(! utf8.write(const_buffers_1{buf, 4}));
BOOST_BEAST_EXPECT(! utf8.write(const_buffers_1{buf, 4}));
}
for(auto n = 192; n <= 255; ++n)
{
// Fourth byte invalid range 192-255
buf[3] = static_cast<std::uint8_t>(n);
BEAST_EXPECT(! utf8.write(buf, 4));
BOOST_BEAST_EXPECT(! utf8.write(buf, 4));
}
// Segmented sequence fourth byte invalid
BEAST_EXPECT(utf8.write(buf, 3));
BEAST_EXPECT(! utf8.write(&buf[3], 1));
BOOST_BEAST_EXPECT(utf8.write(buf, 3));
BOOST_BEAST_EXPECT(! utf8.write(&buf[3], 1));
utf8.reset();
}
@@ -299,19 +302,19 @@ public:
{
// Third byte invalid range 0-127
buf[2] = static_cast<std::uint8_t>(k);
BEAST_EXPECT(! utf8.write(buf, 4));
BOOST_BEAST_EXPECT(! utf8.write(buf, 4));
}
for(auto k = 192; k <= 255; ++k)
{
// Third byte invalid range 192-255
buf[2] = static_cast<std::uint8_t>(k);
BEAST_EXPECT(! utf8.write(buf, 4));
BOOST_BEAST_EXPECT(! utf8.write(buf, 4));
}
// Segmented sequence third byte invalid
BEAST_EXPECT(utf8.write(buf, 2));
BEAST_EXPECT(! utf8.write(&buf[2], 1));
BOOST_BEAST_EXPECT(utf8.write(buf, 2));
BOOST_BEAST_EXPECT(! utf8.write(&buf[2], 1));
utf8.reset();
}
@@ -319,19 +322,19 @@ public:
{
// Second byte invalid range 0-127 or 0-143
buf[1] = static_cast<std::uint8_t>(j);
BEAST_EXPECT(! utf8.write(buf, 4));
BOOST_BEAST_EXPECT(! utf8.write(buf, 4));
}
for(auto j = e + 1; j <= 255; ++j)
{
// Second byte invalid range 144-255 or 192-255
buf[1] = static_cast<std::uint8_t>(j);
BEAST_EXPECT(! utf8.write(buf, 4));
BOOST_BEAST_EXPECT(! utf8.write(buf, 4));
}
// Segmented sequence second byte invalid
BEAST_EXPECT(utf8.write(buf, 1));
BEAST_EXPECT(! utf8.write(&buf[1], 1));
BOOST_BEAST_EXPECT(utf8.write(buf, 1));
BOOST_BEAST_EXPECT(! utf8.write(&buf[1], 1));
utf8.reset();
}
@@ -339,7 +342,7 @@ public:
{
// First byte invalid range 245-255
buf[0] = static_cast<std::uint8_t>(i);
BEAST_EXPECT(! utf8.write(buf, 4));
BOOST_BEAST_EXPECT(! utf8.write(buf, 4));
}
}
@@ -387,8 +390,8 @@ public:
cb.consume(amount);
n -= amount;
}
BEAST_EXPECT(utf8.write(b.data()));
BEAST_EXPECT(utf8.finish());
BOOST_BEAST_EXPECT(utf8.write(b.data()));
BOOST_BEAST_EXPECT(utf8.finish());
}
}
}
@@ -403,10 +406,11 @@ public:
}
};
#if defined(NDEBUG) && ! BEAST_NO_SLOW_TESTS
BEAST_DEFINE_TESTSUITE(utf8_checker,websocket,beast);
#if defined(NDEBUG) && ! BOOST_BEAST_NO_SLOW_TESTS
BOOST_BEAST_DEFINE_TESTSUITE(utf8_checker,websocket,beast);
#endif
} // detail
} // websocket
} // beast
} // boost
+18 -16
View File
@@ -4,12 +4,14 @@
// 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
//
#ifndef BEAST_WEBSOCKET_ASYNC_ECHO_SERVER_HPP
#define BEAST_WEBSOCKET_ASYNC_ECHO_SERVER_HPP
#ifndef BOOST_BEAST_WEBSOCKET_ASYNC_ECHO_SERVER_HPP
#define BOOST_BEAST_WEBSOCKET_ASYNC_ECHO_SERVER_HPP
#include <beast/core/multi_buffer.hpp>
#include <beast/websocket/stream.hpp>
#include <boost/beast/core/multi_buffer.hpp>
#include <boost/beast/websocket/stream.hpp>
#include <boost/asio.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/optional.hpp>
@@ -32,7 +34,7 @@ namespace websocket {
class async_echo_server
{
public:
using error_code = beast::error_code;
using error_code = boost::beast::error_code;
using address_type = boost::asio::ip::address;
using socket_type = boost::asio::ip::tcp::socket;
using endpoint_type = boost::asio::ip::tcp::endpoint;
@@ -48,7 +50,7 @@ private:
{
virtual ~callable() = default;
virtual void operator()(
beast::websocket::stream<NextLayer>&) = 0;
boost::beast::websocket::stream<NextLayer>&) = 0;
};
template<class T>
@@ -64,7 +66,7 @@ private:
}
void
operator()(beast::websocket::stream<NextLayer>& ws)
operator()(boost::beast::websocket::stream<NextLayer>& ws)
{
t_(ws);
}
@@ -85,7 +87,7 @@ private:
}
void
operator()(beast::websocket::stream<NextLayer>& ws) const
operator()(boost::beast::websocket::stream<NextLayer>& ws) const
{
ws.set_option(opt_);
}
@@ -106,7 +108,7 @@ private:
}
void
set_options(beast::websocket::stream<NextLayer>& ws)
set_options(boost::beast::websocket::stream<NextLayer>& ws)
{
for(auto const& op : list_)
(*op.second)(ws);
@@ -213,9 +215,9 @@ private:
async_echo_server& server;
endpoint_type ep;
int state = 0;
beast::websocket::stream<socket_type> ws;
boost::beast::websocket::stream<socket_type> ws;
boost::asio::io_service::strand strand;
beast::multi_buffer db;
boost::beast::multi_buffer db;
std::size_t id;
data(async_echo_server& server_,
@@ -261,7 +263,7 @@ private:
{
auto& d = *d_;
d.ws.async_accept_ex(
[](beast::websocket::response_type& res)
[](boost::beast::websocket::response_type& res)
{
res.insert(
"Server", "async_echo_server");
@@ -278,7 +280,7 @@ private:
using boost::asio::buffer_copy;
if(db.size() < N-1)
return false;
beast::static_string<N-1> t;
boost::beast::static_string<N-1> t;
t.resize(N-1);
buffer_copy(buffer(t.data(), t.size()),
db.data());
@@ -318,7 +320,7 @@ private:
// got message
case 2:
if(ec == beast::websocket::error::closed)
if(ec == boost::beast::websocket::error::closed)
return;
if(ec)
return fail("async_read", ec);
@@ -339,7 +341,7 @@ private:
}
else if(match(d.db, "PING"))
{
beast::websocket::ping_data payload;
boost::beast::websocket::ping_data payload;
d.db.consume(buffer_copy(
buffer(payload.data(), payload.size()),
d.db.data()));
@@ -370,7 +372,7 @@ private:
{
auto& d = *d_;
if(d.server.log_)
if(ec != beast::websocket::error::closed)
if(ec != boost::beast::websocket::error::closed)
d.server.fail("[#" + std::to_string(d.id) +
" " + boost::lexical_cast<std::string>(d.ep) +
"] " + what, ec);
+18 -16
View File
@@ -4,12 +4,14 @@
// 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
//
#ifndef BEAST_WEBSOCKET_SYNC_ECHO_SERVER_HPP
#define BEAST_WEBSOCKET_SYNC_ECHO_SERVER_HPP
#ifndef BOOST_BEAST_WEBSOCKET_SYNC_ECHO_SERVER_HPP
#define BOOST_BEAST_WEBSOCKET_SYNC_ECHO_SERVER_HPP
#include <beast/core/multi_buffer.hpp>
#include <beast/websocket.hpp>
#include <boost/beast/core/multi_buffer.hpp>
#include <boost/beast/websocket.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/optional.hpp>
#include <atomic>
@@ -31,7 +33,7 @@ namespace websocket {
class sync_echo_server
{
public:
using error_code = beast::error_code;
using error_code = boost::beast::error_code;
using endpoint_type = boost::asio::ip::tcp::endpoint;
using address_type = boost::asio::ip::address;
using socket_type = boost::asio::ip::tcp::socket;
@@ -47,7 +49,7 @@ private:
{
virtual ~callable() = default;
virtual void operator()(
beast::websocket::stream<NextLayer>&) = 0;
boost::beast::websocket::stream<NextLayer>&) = 0;
};
template<class T>
@@ -63,7 +65,7 @@ private:
}
void
operator()(beast::websocket::stream<NextLayer>& ws)
operator()(boost::beast::websocket::stream<NextLayer>& ws)
{
t_(ws);
}
@@ -84,7 +86,7 @@ private:
}
void
operator()(beast::websocket::stream<NextLayer>& ws) const
operator()(boost::beast::websocket::stream<NextLayer>& ws) const
{
ws.set_option(opt_);
}
@@ -105,7 +107,7 @@ private:
}
void
set_options(beast::websocket::stream<NextLayer>& ws)
set_options(boost::beast::websocket::stream<NextLayer>& ws)
{
for(auto const& op : list_)
(*op.second)(ws);
@@ -212,7 +214,7 @@ private:
std::size_t id, endpoint_type const& ep)
{
if(log_)
if(ec != beast::websocket::error::closed)
if(ec != boost::beast::websocket::error::closed)
fail("[#" + std::to_string(id) + " " +
boost::lexical_cast<std::string>(ep) +
"] " + what, ec);
@@ -270,7 +272,7 @@ private:
using boost::asio::buffer_copy;
if(db.size() < N-1)
return false;
beast::static_string<N-1> t;
boost::beast::static_string<N-1> t;
t.resize(N-1);
buffer_copy(buffer(t.data(), t.size()),
db.data());
@@ -286,12 +288,12 @@ private:
{
using boost::asio::buffer;
using boost::asio::buffer_copy;
beast::websocket::stream<
boost::beast::websocket::stream<
socket_type> ws{std::move(sock)};
opts_.set_options(ws);
error_code ec;
ws.accept_ex(
[](beast::websocket::response_type& res)
[](boost::beast::websocket::response_type& res)
{
res.insert(
"Server", "sync_echo_server");
@@ -304,7 +306,7 @@ private:
}
for(;;)
{
beast::multi_buffer b;
boost::beast::multi_buffer b;
ws.read(b, ec);
if(ec)
{
@@ -324,7 +326,7 @@ private:
}
else if(match(b, "PING"))
{
beast::websocket::ping_data payload;
boost::beast::websocket::ping_data payload;
b.consume(buffer_copy(
buffer(payload.data(), payload.size()),
b.data()));
@@ -341,7 +343,7 @@ private:
if(ec)
break;
}
if(ec && ec != beast::websocket::error::closed)
if(ec && ec != boost::beast::websocket::error::closed)
{
fail("read", ec, id, ep);
}