Move some classes into their own files

This commit is contained in:
Vinnie Falco
2013-08-10 08:32:02 -07:00
parent e0eaa08597
commit 85f4d7d025
9 changed files with 370 additions and 267 deletions

View File

@@ -69,6 +69,10 @@
<None Include="..\..\README.md" />
</ItemGroup>
<ItemGroup>
<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_TransferCall.h" />
<ClInclude Include="..\..\modules\beast_asio\beast_asio.h" />
<ClInclude Include="..\..\modules\beast_asio\protocol\beast_ProxyHandshake.h" />
<ClInclude Include="..\..\modules\beast_asio\sockets\beast_Socket.h" />

View File

@@ -155,6 +155,9 @@
<Filter Include="beast_asio\protocol">
<UniqueIdentifier>{c4a7b6bb-88ec-4ff1-bc56-7c432a467500}</UniqueIdentifier>
</Filter>
<Filter Include="beast_asio\basics">
<UniqueIdentifier>{ccdc0c8e-f77a-486e-ba2f-29c10ec97f18}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\modules\beast_core\beast_core.h">
@@ -818,6 +821,18 @@
<ClInclude Include="..\..\modules\beast_asio\tests\beast_TestPeerLogicProxyClient.h">
<Filter>beast_asio\tests</Filter>
</ClInclude>
<ClInclude Include="..\..\modules\beast_asio\basics\beast_BufferType.h">
<Filter>beast_asio\basics</Filter>
</ClInclude>
<ClInclude Include="..\..\modules\beast_asio\basics\beast_CompletionCall.h">
<Filter>beast_asio\basics</Filter>
</ClInclude>
<ClInclude Include="..\..\modules\beast_asio\basics\beast_ErrorCall.h">
<Filter>beast_asio\basics</Filter>
</ClInclude>
<ClInclude Include="..\..\modules\beast_asio\basics\beast_TransferCall.h">
<Filter>beast_asio\basics</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\modules\beast_core\beast_core.cpp">

View File

@@ -0,0 +1,100 @@
//------------------------------------------------------------------------------
/*
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_BUFFERTYPE_H_INCLUDED
#define BEAST_BUFFERTYPE_H_INCLUDED
/** Storage for a BufferSequence.
Meets these requirements:
BufferSequence
ConstBufferSequence (when Buffer is mutable_buffer)
MutableBufferSequence (when Buffer is const_buffer)
*/
template <class Buffer>
class BufferType
{
public:
typedef Buffer value_type;
typedef typename std::vector <Buffer>::const_iterator const_iterator;
BufferType ()
: m_size (0)
{
}
template <class OtherBuffers>
explicit BufferType (OtherBuffers const& buffers)
: m_size (0)
{
m_buffers.reserve (std::distance (buffers.begin (), buffers.end ()));
BOOST_FOREACH (typename OtherBuffers::value_type buffer, buffers)
{
m_size += boost::asio::buffer_size (buffer);
m_buffers.push_back (buffer);
}
}
/** Determine the total size of all buffers.
This is faster than calling boost::asio::buffer_size.
*/
std::size_t size () const noexcept
{
return m_size;
}
const_iterator begin () const noexcept
{
return m_buffers.begin ();
}
const_iterator end () const noexcept
{
return m_buffers.end ();
}
/** Retrieve a consumed BufferSequence. */
BufferType consumed (std::size_t bytes) const
{
BufferType result;
result.m_buffers.reserve (m_buffers.size ());
BOOST_FOREACH (Buffer buffer, m_buffers)
{
std::size_t const have = boost::asio::buffer_size (buffer);
std::size_t const reduce = std::min (bytes, have);
bytes -= reduce;
if (have > reduce)
result.m_buffers.push_back (buffer + reduce);
}
return result;
}
private:
std::size_t m_size;
std::vector <Buffer> m_buffers;
};
/** Meets the requirements of ConstBufferSequence */
typedef BufferType <boost::asio::const_buffer> ConstBuffers;
/** Meets the requirements of MutableBufferSequence */
typedef BufferType <boost::asio::mutable_buffer> MutableBuffers;
#endif

View File

@@ -0,0 +1,75 @@
//------------------------------------------------------------------------------
/*
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_COMPLETIONCALL_H_INCLUDED
#define BEAST_COMPLETIONCALL_H_INCLUDED
// Meets these requirements:
//
// CompletionHandler
// http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/CompletionHandler.html
//
class CompletionCall
{
public:
typedef void result_type;
template <class Handler>
CompletionCall (BOOST_ASIO_MOVE_ARG(Handler) handler)
: m_call (new CallType <Handler> (BOOST_ASIO_MOVE_CAST(Handler)(handler)))
{
}
CompletionCall (CompletionCall const& other)
: m_call (other.m_call)
{
}
void operator() ()
{
(*m_call) ();
}
private:
struct Call : SharedObject, LeakChecked <Call>
{
virtual void operator() () = 0;
};
template <class Handler>
struct CallType : Call
{
CallType (BOOST_ASIO_MOVE_ARG(Handler) handler)
: m_handler (handler)
{
}
void operator() ()
{
m_handler ();
}
Handler m_handler;
};
private:
SharedObjectPtr <Call> m_call;
};
#endif

View File

@@ -0,0 +1,84 @@
//------------------------------------------------------------------------------
/*
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_ERRORCALL_H_INCLUDED
#define BEAST_ERRORCALL_H_INCLUDED
// Meets these requirements:
//
// AcceptHandler
// http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/AcceptHandler.html
//
// ConnectHandler
// http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/ConnectHandler.html
//
// ShutdownHandler
// http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/ShutdownHandler.html
//
// HandshakeHandler
// http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/HandshakeHandler.html
//
class ErrorCall
{
public:
typedef void result_type;
template <class Handler>
ErrorCall (BOOST_ASIO_MOVE_ARG(Handler) handler)
: m_call (new CallType <Handler> (BOOST_ASIO_MOVE_CAST(Handler)(handler)))
{
}
ErrorCall (ErrorCall const& other)
: m_call (other.m_call)
{
}
void operator() (boost::system::error_code const& ec)
{
(*m_call) (ec);
}
private:
struct Call : SharedObject, LeakChecked <Call>
{
virtual void operator() (boost::system::error_code const&) = 0;
};
template <class Handler>
struct CallType : Call
{
CallType (BOOST_ASIO_MOVE_ARG(Handler) handler)
: m_handler (handler)
{
}
void operator() (boost::system::error_code const& ec)
{
m_handler (ec);
}
Handler m_handler;
};
private:
SharedObjectPtr <Call> m_call;
};
#endif

View File

@@ -0,0 +1,81 @@
//------------------------------------------------------------------------------
/*
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_TRANSFERCALL_H_INCLUDED
#define BEAST_TRANSFERCALL_H_INCLUDED
// Meets these requirements
//
// ReadHandler
// http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/ReadHandler.html
//
// WriteHandler
// http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/WriteHandler.html
//
// BUfferedHandshakeHandler
// http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/BufferedHandshakeHandler.html
//
class TransferCall
{
public:
typedef void result_type;
template <class Handler>
TransferCall (BOOST_ASIO_MOVE_ARG(Handler) handler)
: m_call (new CallType <Handler> (BOOST_ASIO_MOVE_CAST(Handler)(handler)))
{
}
TransferCall (TransferCall const& other)
: m_call (other.m_call)
{
}
void operator() (boost::system::error_code const& ec, std::size_t bytes_transferred)
{
(*m_call) (ec, bytes_transferred);
}
private:
struct Call : SharedObject, LeakChecked <Call>
{
virtual void operator() (boost::system::error_code const&, std::size_t) = 0;
};
template <class Handler>
struct CallType : Call
{
CallType (BOOST_ASIO_MOVE_ARG(Handler) handler)
: m_handler (handler)
{
}
void operator() (boost::system::error_code const& ec, std::size_t bytes_transferred)
{
m_handler (ec, bytes_transferred);
}
Handler m_handler;
};
private:
SharedObjectPtr <Call> m_call;
};
#endif

View File

@@ -48,6 +48,11 @@ namespace beast
// Order matters
#include "basics/beast_BufferType.h"
#include "basics/beast_CompletionCall.h"
#include "basics/beast_ErrorCall.h"
#include "basics/beast_TransferCall.h"
#include "sockets/beast_SocketBase.h"
#include "sockets/beast_Socket.h"
#include "sockets/beast_SocketInterface.h"

View File

@@ -54,7 +54,7 @@ boost::system::error_code Socket::accept (Socket&, boost::system::error_code& ec
return pure_virtual (ec);
}
BEAST_ASIO_INITFN_RESULT_TYPE_MEMBER(Socket::ErrorCall, void (boost::system::error_code))
BEAST_ASIO_INITFN_RESULT_TYPE_MEMBER(ErrorCall, void (boost::system::error_code))
Socket::async_accept (Socket&, BOOST_ASIO_MOVE_ARG(ErrorCall) handler)
{
#if BEAST_ASIO_HAS_FUTURE_RETURNS
@@ -120,7 +120,7 @@ std::size_t Socket::write_some (ConstBuffers const&, boost::system::error_code&
return 0;
}
BEAST_ASIO_INITFN_RESULT_TYPE_MEMBER(Socket::TransferCall, void (boost::system::error_code, std::size_t))
BEAST_ASIO_INITFN_RESULT_TYPE_MEMBER(TransferCall, void (boost::system::error_code, std::size_t))
Socket::async_read_some (MutableBuffers const&, BOOST_ASIO_MOVE_ARG(TransferCall) handler)
{
#if BEAST_ASIO_HAS_FUTURE_RETURNS
@@ -138,7 +138,7 @@ Socket::async_read_some (MutableBuffers const&, BOOST_ASIO_MOVE_ARG(TransferCall
#endif
}
BEAST_ASIO_INITFN_RESULT_TYPE_MEMBER(Socket::TransferCall, void (boost::system::error_code, std::size_t))
BEAST_ASIO_INITFN_RESULT_TYPE_MEMBER(TransferCall, void (boost::system::error_code, std::size_t))
Socket::async_write_some (ConstBuffers const&, BOOST_ASIO_MOVE_ARG(TransferCall) handler)
{
#if BEAST_ASIO_HAS_FUTURE_RETURNS
@@ -169,7 +169,7 @@ boost::system::error_code Socket::handshake (handshake_type, boost::system::erro
return pure_virtual (ec);
}
BEAST_ASIO_INITFN_RESULT_TYPE_MEMBER(Socket::ErrorCall, void (boost::system::error_code))
BEAST_ASIO_INITFN_RESULT_TYPE_MEMBER(ErrorCall, void (boost::system::error_code))
Socket::async_handshake (handshake_type, BOOST_ASIO_MOVE_ARG(ErrorCall) handler)
{
#if BEAST_ASIO_HAS_FUTURE_RETURNS
@@ -199,7 +199,7 @@ boost::system::error_code Socket::handshake (handshake_type,
return pure_virtual (ec);
}
BEAST_ASIO_INITFN_RESULT_TYPE_MEMBER(Socket::TransferCall, void (boost::system::error_code, std::size_t))
BEAST_ASIO_INITFN_RESULT_TYPE_MEMBER(TransferCall, void (boost::system::error_code, std::size_t))
Socket::async_handshake (handshake_type, ConstBuffers const&,
BOOST_ASIO_MOVE_ARG(TransferCall) handler)
{
@@ -227,7 +227,7 @@ boost::system::error_code Socket::shutdown (boost::system::error_code& ec)
return pure_virtual (ec);
}
BEAST_ASIO_INITFN_RESULT_TYPE_MEMBER(Socket::ErrorCall, void (boost::system::error_code))
BEAST_ASIO_INITFN_RESULT_TYPE_MEMBER(ErrorCall, void (boost::system::error_code))
Socket::async_shutdown (BOOST_ASIO_MOVE_ARG(ErrorCall) handler)
{
#if BEAST_ASIO_HAS_FUTURE_RETURNS

View File

@@ -30,266 +30,6 @@ protected:
static boost::system::error_code pure_virtual (boost::system::error_code& ec);
protected:
//--------------------------------------------------------------------------
//
// Buffers
//
//--------------------------------------------------------------------------
/** Storage for a BufferSequence.
Meets these requirements:
BufferSequence
ConstBufferSequence (when Buffer is mutable_buffer)
MutableBufferSequence (when Buffer is const_buffer)
*/
template <class Buffer>
class Buffers
{
public:
typedef Buffer value_type;
typedef typename std::vector <Buffer>::const_iterator const_iterator;
Buffers ()
: m_size (0)
{
}
template <class OtherBuffers>
explicit Buffers (OtherBuffers const& buffers)
: m_size (0)
{
m_buffers.reserve (std::distance (buffers.begin (), buffers.end ()));
BOOST_FOREACH (typename OtherBuffers::value_type buffer, buffers)
{
m_size += boost::asio::buffer_size (buffer);
m_buffers.push_back (buffer);
}
}
/** Determine the total size of all buffers.
This is faster than calling boost::asio::buffer_size.
*/
std::size_t size () const noexcept
{
return m_size;
}
const_iterator begin () const noexcept
{
return m_buffers.begin ();
}
const_iterator end () const noexcept
{
return m_buffers.end ();
}
/** Retrieve a consumed BufferSequence. */
Buffers consumed (std::size_t bytes) const
{
Buffers result;
result.m_buffers.reserve (m_buffers.size ());
BOOST_FOREACH (Buffer buffer, m_buffers)
{
std::size_t const have = boost::asio::buffer_size (buffer);
std::size_t const reduce = std::min (bytes, have);
bytes -= reduce;
if (have > reduce)
result.m_buffers.push_back (buffer + reduce);
}
return result;
}
private:
std::size_t m_size;
std::vector <Buffer> m_buffers;
};
/** Meets the requirements of ConstBufferSequence */
typedef Buffers <boost::asio::const_buffer> ConstBuffers;
/** Meets the requirements of MutableBufferSequence */
typedef Buffers <boost::asio::mutable_buffer> MutableBuffers;
//--------------------------------------------------------------------------
//
// Handler abstractions
//
//--------------------------------------------------------------------------
// Meets these requirements:
//
// CompletionHandler
// http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/CompletionHandler.html
//
class CompletionCall
{
public:
typedef void result_type;
template <class Handler>
CompletionCall (BOOST_ASIO_MOVE_ARG(Handler) handler)
: m_call (new CallType <Handler> (BOOST_ASIO_MOVE_CAST(Handler)(handler)))
{
}
CompletionCall (CompletionCall const& other)
: m_call (other.m_call)
{
}
void operator() ()
{
(*m_call) ();
}
private:
struct Call : SharedObject, LeakChecked <Call>
{
virtual void operator() () = 0;
};
template <class Handler>
struct CallType : Call
{
CallType (BOOST_ASIO_MOVE_ARG(Handler) handler)
: m_handler (handler)
{
}
void operator() ()
{
m_handler ();
}
Handler m_handler;
};
private:
SharedObjectPtr <Call> m_call;
};
// Meets these requirements:
//
// AcceptHandler
// http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/AcceptHandler.html
//
// ConnectHandler
// http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/ConnectHandler.html
//
// ShutdownHandler
// http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/ShutdownHandler.html
//
// HandshakeHandler
// http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/HandshakeHandler.html
//
class ErrorCall
{
public:
typedef void result_type;
template <class Handler>
ErrorCall (BOOST_ASIO_MOVE_ARG(Handler) handler)
: m_call (new CallType <Handler> (BOOST_ASIO_MOVE_CAST(Handler)(handler)))
{
}
ErrorCall (ErrorCall const& other)
: m_call (other.m_call)
{
}
void operator() (boost::system::error_code const& ec)
{
(*m_call) (ec);
}
private:
struct Call : SharedObject, LeakChecked <Call>
{
virtual void operator() (boost::system::error_code const&) = 0;
};
template <class Handler>
struct CallType : Call
{
CallType (BOOST_ASIO_MOVE_ARG(Handler) handler)
: m_handler (handler)
{
}
void operator() (boost::system::error_code const& ec)
{
m_handler (ec);
}
Handler m_handler;
};
private:
SharedObjectPtr <Call> m_call;
};
// Meets these requirements
//
// ReadHandler
// http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/ReadHandler.html
//
// WriteHandler
// http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/WriteHandler.html
//
// BUfferedHandshakeHandler
// http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/BufferedHandshakeHandler.html
//
class TransferCall
{
public:
typedef void result_type;
template <class Handler>
TransferCall (BOOST_ASIO_MOVE_ARG(Handler) handler)
: m_call (new CallType <Handler> (BOOST_ASIO_MOVE_CAST(Handler)(handler)))
{
}
TransferCall (TransferCall const& other)
: m_call (other.m_call)
{
}
void operator() (boost::system::error_code const& ec, std::size_t bytes_transferred)
{
(*m_call) (ec, bytes_transferred);
}
private:
struct Call : SharedObject, LeakChecked <Call>
{
virtual void operator() (boost::system::error_code const&, std::size_t) = 0;
};
template <class Handler>
struct CallType : Call
{
CallType (BOOST_ASIO_MOVE_ARG(Handler) handler)
: m_handler (handler)
{
}
void operator() (boost::system::error_code const& ec, std::size_t bytes_transferred)
{
m_handler (ec, bytes_transferred);
}
Handler m_handler;
};
private:
SharedObjectPtr <Call> m_call;
};
/** Called when the underlying object does not support the interface. */
void throw_error (boost::system::error_code const& ec)
{
@@ -298,5 +38,4 @@ protected:
}
};
#endif