forked from boostorg/beast
Rename websocket echo servers (fix #46)
This commit is contained in:
@@ -7,8 +7,8 @@ GroupSources(test/websocket "/")
|
|||||||
add_executable (websocket-tests
|
add_executable (websocket-tests
|
||||||
${BEAST_INCLUDES}
|
${BEAST_INCLUDES}
|
||||||
../../extras/beast/unit_test/main.cpp
|
../../extras/beast/unit_test/main.cpp
|
||||||
websocket_async_echo_peer.hpp
|
websocket_async_echo_server.hpp
|
||||||
websocket_sync_echo_peer.hpp
|
websocket_sync_echo_server.hpp
|
||||||
error.cpp
|
error.cpp
|
||||||
option.cpp
|
option.cpp
|
||||||
rfc6455.cpp
|
rfc6455.cpp
|
||||||
@@ -26,8 +26,8 @@ endif()
|
|||||||
|
|
||||||
add_executable (websocket-echo
|
add_executable (websocket-echo
|
||||||
${BEAST_INCLUDES}
|
${BEAST_INCLUDES}
|
||||||
websocket_async_echo_peer.hpp
|
websocket_async_echo_server.hpp
|
||||||
websocket_sync_echo_peer.hpp
|
websocket_sync_echo_server.hpp
|
||||||
websocket_echo.cpp
|
websocket_echo.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@@ -8,8 +8,8 @@
|
|||||||
// Test that header file is self-contained.
|
// Test that header file is self-contained.
|
||||||
#include <beast/websocket/stream.hpp>
|
#include <beast/websocket/stream.hpp>
|
||||||
|
|
||||||
#include "websocket_async_echo_peer.hpp"
|
#include "websocket_async_echo_server.hpp"
|
||||||
#include "websocket_sync_echo_peer.hpp"
|
#include "websocket_sync_echo_server.hpp"
|
||||||
|
|
||||||
#include <beast/core/streambuf.hpp>
|
#include <beast/core/streambuf.hpp>
|
||||||
#include <beast/core/to_string.hpp>
|
#include <beast/core/to_string.hpp>
|
||||||
@@ -1389,7 +1389,7 @@ public:
|
|||||||
testBadHandshakes();
|
testBadHandshakes();
|
||||||
testBadResponses();
|
testBadResponses();
|
||||||
{
|
{
|
||||||
sync_echo_peer server(true, any);
|
sync_echo_server server(true, any);
|
||||||
auto const ep = server.local_endpoint();
|
auto const ep = server.local_endpoint();
|
||||||
|
|
||||||
//testInvokable1(ep);
|
//testInvokable1(ep);
|
||||||
@@ -1403,7 +1403,7 @@ public:
|
|||||||
yield_to_mf(ep, &stream_test::testAsyncClient);
|
yield_to_mf(ep, &stream_test::testAsyncClient);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
async_echo_peer server(true, any, 4);
|
async_echo_server server(true, any, 4);
|
||||||
auto const ep = server.local_endpoint();
|
auto const ep = server.local_endpoint();
|
||||||
testSyncClient(ep);
|
testSyncClient(ep);
|
||||||
testAsyncWriteFrame(ep);
|
testAsyncWriteFrame(ep);
|
||||||
|
@@ -22,7 +22,7 @@ namespace websocket {
|
|||||||
|
|
||||||
// Asynchronous WebSocket echo client/server
|
// Asynchronous WebSocket echo client/server
|
||||||
//
|
//
|
||||||
class async_echo_peer
|
class async_echo_server
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using endpoint_type = boost::asio::ip::tcp::endpoint;
|
using endpoint_type = boost::asio::ip::tcp::endpoint;
|
||||||
@@ -37,7 +37,7 @@ private:
|
|||||||
std::vector<std::thread> thread_;
|
std::vector<std::thread> thread_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
async_echo_peer(bool server,
|
async_echo_server(bool server,
|
||||||
endpoint_type const& ep, std::size_t threads)
|
endpoint_type const& ep, std::size_t threads)
|
||||||
: sock_(ios_)
|
: sock_(ios_)
|
||||||
, acceptor_(ios_)
|
, acceptor_(ios_)
|
||||||
@@ -55,7 +55,7 @@ public:
|
|||||||
boost::asio::socket_base::max_connections, ec);
|
boost::asio::socket_base::max_connections, ec);
|
||||||
maybe_throw(ec, "listen");
|
maybe_throw(ec, "listen");
|
||||||
acceptor_.async_accept(sock_,
|
acceptor_.async_accept(sock_,
|
||||||
std::bind(&async_echo_peer::on_accept, this,
|
std::bind(&async_echo_server::on_accept, this,
|
||||||
beast::asio::placeholders::error));
|
beast::asio::placeholders::error));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -68,7 +68,7 @@ public:
|
|||||||
[&]{ ios_.run(); });
|
[&]{ ios_.run(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
~async_echo_peer()
|
~async_echo_server()
|
||||||
{
|
{
|
||||||
error_code ec;
|
error_code ec;
|
||||||
ios_.dispatch(
|
ios_.dispatch(
|
||||||
@@ -325,7 +325,7 @@ private:
|
|||||||
maybe_throw(ec, "accept");
|
maybe_throw(ec, "accept");
|
||||||
socket_type sock(std::move(sock_));
|
socket_type sock(std::move(sock_));
|
||||||
acceptor_.async_accept(sock_,
|
acceptor_.async_accept(sock_,
|
||||||
std::bind(&async_echo_peer::on_accept, this,
|
std::bind(&async_echo_server::on_accept, this,
|
||||||
beast::asio::placeholders::error));
|
beast::asio::placeholders::error));
|
||||||
Peer{false, std::move(sock)};
|
Peer{false, std::move(sock)};
|
||||||
}
|
}
|
@@ -5,8 +5,8 @@
|
|||||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "websocket_async_echo_peer.hpp"
|
#include "websocket_async_echo_server.hpp"
|
||||||
#include "websocket_sync_echo_peer.hpp"
|
#include "websocket_sync_echo_server.hpp"
|
||||||
#include <beast/test/sig_wait.hpp>
|
#include <beast/test/sig_wait.hpp>
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
@@ -14,10 +14,10 @@ int main()
|
|||||||
using endpoint_type = boost::asio::ip::tcp::endpoint;
|
using endpoint_type = boost::asio::ip::tcp::endpoint;
|
||||||
using address_type = boost::asio::ip::address;
|
using address_type = boost::asio::ip::address;
|
||||||
|
|
||||||
beast::websocket::async_echo_peer s1(true, endpoint_type{
|
beast::websocket::async_echo_server s1(true, endpoint_type{
|
||||||
address_type::from_string("127.0.0.1"), 6000 }, 4);
|
address_type::from_string("127.0.0.1"), 6000 }, 4);
|
||||||
|
|
||||||
beast::websocket::sync_echo_peer s2(true, endpoint_type{
|
beast::websocket::sync_echo_server s2(true, endpoint_type{
|
||||||
address_type::from_string("127.0.0.1"), 6001 });
|
address_type::from_string("127.0.0.1"), 6001 });
|
||||||
|
|
||||||
beast::test::sig_wait();
|
beast::test::sig_wait();
|
||||||
|
@@ -21,7 +21,7 @@ namespace websocket {
|
|||||||
|
|
||||||
// Synchronous WebSocket echo client/server
|
// Synchronous WebSocket echo client/server
|
||||||
//
|
//
|
||||||
class sync_echo_peer
|
class sync_echo_server
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using endpoint_type = boost::asio::ip::tcp::endpoint;
|
using endpoint_type = boost::asio::ip::tcp::endpoint;
|
||||||
@@ -36,7 +36,7 @@ private:
|
|||||||
std::thread thread_;
|
std::thread thread_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
sync_echo_peer(bool server, endpoint_type ep)
|
sync_echo_server(bool server, endpoint_type ep)
|
||||||
: sock_(ios_)
|
: sock_(ios_)
|
||||||
, acceptor_(ios_)
|
, acceptor_(ios_)
|
||||||
{
|
{
|
||||||
@@ -51,12 +51,12 @@ public:
|
|||||||
boost::asio::socket_base::max_connections, ec);
|
boost::asio::socket_base::max_connections, ec);
|
||||||
maybe_throw(ec, "listen");
|
maybe_throw(ec, "listen");
|
||||||
acceptor_.async_accept(sock_,
|
acceptor_.async_accept(sock_,
|
||||||
std::bind(&sync_echo_peer::on_accept, this,
|
std::bind(&sync_echo_server::on_accept, this,
|
||||||
beast::asio::placeholders::error));
|
beast::asio::placeholders::error));
|
||||||
thread_ = std::thread{[&]{ ios_.run(); }};
|
thread_ = std::thread{[&]{ ios_.run(); }};
|
||||||
}
|
}
|
||||||
|
|
||||||
~sync_echo_peer()
|
~sync_echo_server()
|
||||||
{
|
{
|
||||||
error_code ec;
|
error_code ec;
|
||||||
ios_.dispatch(
|
ios_.dispatch(
|
||||||
@@ -100,13 +100,13 @@ private:
|
|||||||
struct lambda
|
struct lambda
|
||||||
{
|
{
|
||||||
int id;
|
int id;
|
||||||
sync_echo_peer& self;
|
sync_echo_server& self;
|
||||||
boost::asio::io_service::work work;
|
boost::asio::io_service::work work;
|
||||||
// Must be destroyed before work otherwise the
|
// Must be destroyed before work otherwise the
|
||||||
// io_service could be destroyed before the socket.
|
// io_service could be destroyed before the socket.
|
||||||
socket_type sock;
|
socket_type sock;
|
||||||
|
|
||||||
lambda(int id_, sync_echo_peer& self_,
|
lambda(int id_, sync_echo_server& self_,
|
||||||
socket_type&& sock_)
|
socket_type&& sock_)
|
||||||
: id(id_)
|
: id(id_)
|
||||||
, self(self_)
|
, self(self_)
|
||||||
@@ -130,7 +130,7 @@ private:
|
|||||||
static int id_ = 0;
|
static int id_ = 0;
|
||||||
std::thread{lambda{++id_, *this, std::move(sock_)}}.detach();
|
std::thread{lambda{++id_, *this, std::move(sock_)}}.detach();
|
||||||
acceptor_.async_accept(sock_,
|
acceptor_.async_accept(sock_,
|
||||||
std::bind(&sync_echo_peer::on_accept, this,
|
std::bind(&sync_echo_server::on_accept, this,
|
||||||
beast::asio::placeholders::error));
|
beast::asio::placeholders::error));
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue
Block a user