Move PeerRole to its own file

This commit is contained in:
Vinnie Falco
2013-08-10 12:16:46 -07:00
parent 85f4d7d025
commit 7735187d36
20 changed files with 136 additions and 68 deletions

View File

@@ -72,6 +72,7 @@
<ClInclude Include="..\..\modules\beast_asio\basics\beast_BufferType.h" />
<ClInclude Include="..\..\modules\beast_asio\basics\beast_CompletionCall.h" />
<ClInclude Include="..\..\modules\beast_asio\basics\beast_ErrorCall.h" />
<ClInclude Include="..\..\modules\beast_asio\basics\beast_PeerRole.h" />
<ClInclude Include="..\..\modules\beast_asio\basics\beast_TransferCall.h" />
<ClInclude Include="..\..\modules\beast_asio\beast_asio.h" />
<ClInclude Include="..\..\modules\beast_asio\protocol\beast_ProxyHandshake.h" />
@@ -296,6 +297,12 @@
<ClInclude Include="BeastConfig.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\modules\beast_asio\basics\beast_PeerRole.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\modules\beast_asio\beast_asio.cpp" />
<ClCompile Include="..\..\modules\beast_asio\protocol\beast_ProxyHandshake.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>

View File

@@ -833,6 +833,9 @@
<ClInclude Include="..\..\modules\beast_asio\basics\beast_TransferCall.h">
<Filter>beast_asio\basics</Filter>
</ClInclude>
<ClInclude Include="..\..\modules\beast_asio\basics\beast_PeerRole.h">
<Filter>beast_asio\basics</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\modules\beast_core\beast_core.cpp">
@@ -1291,6 +1294,9 @@
<ClCompile Include="..\..\modules\beast_asio\tests\beast_TestPeerLogicProxyClient.cpp">
<Filter>beast_asio\tests</Filter>
</ClCompile>
<ClCompile Include="..\..\modules\beast_asio\basics\beast_PeerRole.cpp">
<Filter>beast_asio\basics</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Text Include="..\..\TODO.txt" />

View File

@@ -0,0 +1,44 @@
//------------------------------------------------------------------------------
/*
This file is part of Beast: https://github.com/vinniefalco/Beast
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
PeerRole::PeerRole (role_t role)
: m_role (role)
{
}
String PeerRole::name () const noexcept
{
if (m_role == server)
return "server";
return "client";
}
bool PeerRole::operator== (role_t role) const noexcept
{
return m_role == role;
}
#if 0
PeerRole::operator Socket::handshake_type () const noexcept
{
if (m_role == server)
return Socket::server;
return Socket::client;
}
#endif

View File

@@ -0,0 +1,40 @@
//------------------------------------------------------------------------------
/*
This file is part of Beast: https://github.com/vinniefalco/Beast
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef BEAST_PEERROLE_H_INCLUDED
#define BEAST_PEERROLE_H_INCLUDED
/** Identifies if the peer is a client or a server. */
struct PeerRole
{
enum role_t
{
client,
server
};
PeerRole (role_t role);
String name () const noexcept;
bool operator== (role_t role) const noexcept;
private:
role_t m_role;
};
#endif

View File

@@ -24,6 +24,8 @@
namespace beast
{
#include "basics/beast_PeerRole.cpp"
#include "sockets/beast_SocketBase.cpp"
#include "sockets/beast_Socket.cpp"
#include "sockets/beast_SslContext.cpp"

View File

@@ -48,6 +48,7 @@ namespace beast
// Order matters
#include "basics/beast_PeerRole.h"
#include "basics/beast_BufferType.h"
#include "basics/beast_CompletionCall.h"
#include "basics/beast_ErrorCall.h"

View File

@@ -38,6 +38,7 @@
# endif
#endif
#include <boost/array.hpp>
#include <boost/asio.hpp>
#include <boost/asio/ssl.hpp>
#include <boost/bind.hpp>

View File

@@ -17,32 +17,6 @@
*/
//==============================================================================
TestPeerBasics::Role::Role (role_t role)
: m_role (role)
{
}
String TestPeerBasics::Role::name () const noexcept
{
if (m_role == server)
return "server";
return "client";
}
bool TestPeerBasics::Role::operator== (role_t role) const noexcept
{
return m_role == role;
}
TestPeerBasics::Role::operator Socket::handshake_type () const noexcept
{
if (m_role == server)
return Socket::server;
return Socket::client;
}
//------------------------------------------------------------------------------
TestPeerBasics::Model::Model (model_t model)
: m_model (model)
{
@@ -60,6 +34,14 @@ bool TestPeerBasics::Model::operator== (model_t model) const noexcept
return m_model == model;
}
boost::asio::ssl::stream_base::handshake_type
TestPeerBasics::to_handshake_type (PeerRole const& role)
{
if (role == PeerRole::client)
return boost::asio::ssl::stream_base::client;
return boost::asio::ssl::stream_base::server;
}
//------------------------------------------------------------------------------
boost::system::error_category const& TestPeerBasics::test_category () noexcept

View File

@@ -27,26 +27,6 @@
class TestPeerBasics
{
public:
/** Identifies if the peer is a client or a server. */
struct Role
{
enum role_t
{
client,
server
};
Role (role_t role);
String name () const noexcept;
bool operator== (role_t role) const noexcept;
operator Socket::handshake_type () const noexcept;
private:
role_t m_role;
};
//--------------------------------------------------------------------------
/** Selects between synchronous or asynchronous networking i/o usage. */
struct Model
{
@@ -66,6 +46,11 @@ public:
//--------------------------------------------------------------------------
/** Convert a PeerRole to boost::asio::ssl::stream_base_handshake_type */
static boost::asio::ssl::stream_base::handshake_type to_handshake_type (PeerRole const& role);
//--------------------------------------------------------------------------
// Custom error codes for distinguishing test conditions
struct errc
{

View File

@@ -79,18 +79,18 @@ public:
return m_acceptor;
}
endpoint_type get_endpoint (TestPeer::Role role)
endpoint_type get_endpoint (PeerRole role)
{
if (m_protocol == protocol_type::v4 ())
{
if (role == TestPeer::Role::server)
if (role == PeerRole::server)
return endpoint_type (m_protocol, 1053);
else
return endpoint_type (boost::asio::ip::address_v4::loopback (), 1053);
}
else
{
if (role == TestPeer::Role::server)
if (role == PeerRole::server)
return endpoint_type (m_protocol, 1052);
else
return endpoint_type (boost::asio::ip::address_v6 ().from_string ("::1"), 1052);

View File

@@ -35,7 +35,7 @@ public:
Socket& socket () noexcept;
virtual Role get_role () const noexcept = 0;
virtual PeerRole get_role () const noexcept = 0;
virtual Model get_model () const noexcept = 0;

View File

@@ -22,9 +22,9 @@ TestPeerLogicAsyncClient::TestPeerLogicAsyncClient (Socket& socket)
{
}
TestPeerBasics::Role TestPeerLogicAsyncClient::get_role () const noexcept
PeerRole TestPeerLogicAsyncClient::get_role () const noexcept
{
return Role::client;
return PeerRole::client;
}
TestPeerBasics::Model TestPeerLogicAsyncClient::get_model () const noexcept

View File

@@ -24,7 +24,7 @@ class TestPeerLogicAsyncClient : public TestPeerLogic
{
public:
explicit TestPeerLogicAsyncClient (Socket& socket);
Role get_role () const noexcept;
PeerRole get_role () const noexcept;
Model get_model () const noexcept;
void on_connect_async (error_code const& ec);
void on_handshake (error_code const& ec);

View File

@@ -22,9 +22,9 @@ TestPeerLogicAsyncServer::TestPeerLogicAsyncServer (Socket& socket)
{
}
TestPeerBasics::Role TestPeerLogicAsyncServer::get_role () const noexcept
PeerRole TestPeerLogicAsyncServer::get_role () const noexcept
{
return Role::server;
return PeerRole::server;
}
TestPeerBasics::Model TestPeerLogicAsyncServer::get_model () const noexcept

View File

@@ -24,7 +24,7 @@ class TestPeerLogicAsyncServer : public TestPeerLogic
{
public:
explicit TestPeerLogicAsyncServer (Socket& socket);
Role get_role () const noexcept;
PeerRole get_role () const noexcept;
Model get_model () const noexcept;
void on_connect_async (error_code const& ec);
void on_handshake (error_code const& ec);

View File

@@ -22,9 +22,9 @@ TestPeerLogicSyncClient::TestPeerLogicSyncClient (Socket& socket)
{
}
TestPeerBasics::Role TestPeerLogicSyncClient::get_role () const noexcept
PeerRole TestPeerLogicSyncClient::get_role () const noexcept
{
return Role::client;
return PeerRole::client;
}
TestPeerBasics::Model TestPeerLogicSyncClient::get_model () const noexcept
@@ -43,7 +43,7 @@ void TestPeerLogicSyncClient::on_connect ()
if (socket ().requires_handshake ())
{
if (failure (socket ().handshake (get_role (), error ())))
if (failure (socket ().handshake (to_handshake_type (get_role ()), error ())))
return;
}

View File

@@ -24,7 +24,7 @@ class TestPeerLogicSyncClient : public TestPeerLogic
{
public:
explicit TestPeerLogicSyncClient (Socket& socket);
Role get_role () const noexcept;
PeerRole get_role () const noexcept;
Model get_model () const noexcept;
void on_connect ();
virtual void on_pre_handshake ();

View File

@@ -22,9 +22,9 @@ TestPeerLogicSyncServer::TestPeerLogicSyncServer (Socket& socket)
{
}
TestPeerBasics::Role TestPeerLogicSyncServer::get_role () const noexcept
PeerRole TestPeerLogicSyncServer::get_role () const noexcept
{
return Role::server;
return PeerRole::server;
}
TestPeerBasics::Model TestPeerLogicSyncServer::get_model () const noexcept
@@ -36,7 +36,7 @@ void TestPeerLogicSyncServer::on_connect ()
{
if (socket ().requires_handshake ())
{
if (failure (socket ().handshake (get_role (), error ())))
if (failure (socket ().handshake (to_handshake_type (get_role ()), error ())))
return;
}

View File

@@ -24,7 +24,7 @@ class TestPeerLogicSyncServer : public TestPeerLogic
{
public:
explicit TestPeerLogicSyncServer (Socket& socket);
Role get_role () const noexcept;
PeerRole get_role () const noexcept;
Model get_model () const noexcept;
void on_connect ();
};

View File

@@ -175,11 +175,11 @@ public:
{
if (is_async ())
{
if (get_role () == Role::server)
if (get_role () == PeerRole::server)
{
run_async_server ();
}
else if (get_role () == Role::client)
else if (get_role () == PeerRole::client)
{
run_async_client ();
}
@@ -190,11 +190,11 @@ public:
}
else if (get_model () == Model::sync)
{
if (get_role () == Role::server)
if (get_role () == PeerRole::server)
{
run_sync_server ();
}
else if (get_role () == Role::client)
else if (get_role () == PeerRole::client)
{
run_sync_client ();
}