forked from boostorg/beast
Refactor net buffers classes
This commit is contained in:
1 parent
ac37c38133
commit
44445ff1b8
17 files changed
+259
-37
No files matched your search
@@ -1,102 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
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_ASIO_BASICS_BUFFERTYPE_H_INCLUDED
|
||||
#define BEAST_ASIO_BASICS_BUFFERTYPE_H_INCLUDED
|
||||
|
||||
/** General linear memory buffer.
|
||||
This wraps the underlying buffer type and provides additional methods
|
||||
to create a uniform interface. Specializations allow asio-compatible
|
||||
buffers without having to include boost/asio.h.
|
||||
*/
|
||||
/** @{ */
|
||||
template <bool IsConst>
|
||||
class BufferType
|
||||
{
|
||||
private:
|
||||
typedef typename mpl::IfCond <IsConst,
|
||||
void const*,
|
||||
void*>::type pointer_type;
|
||||
|
||||
typedef typename mpl::IfCond <IsConst,
|
||||
uint8 const,
|
||||
uint8>::type byte_type;
|
||||
|
||||
public:
|
||||
typedef std::size_t size_type;
|
||||
|
||||
BufferType ()
|
||||
: m_data (nullptr)
|
||||
, m_size (0)
|
||||
{
|
||||
}
|
||||
|
||||
template <bool OtherIsConst>
|
||||
BufferType (BufferType <OtherIsConst> const& other)
|
||||
: m_data (other.cast <pointer_type> ())
|
||||
, m_size (other.size ())
|
||||
{
|
||||
}
|
||||
|
||||
BufferType (pointer_type data, std::size_t size) noexcept
|
||||
: m_data (data)
|
||||
, m_size (size)
|
||||
{
|
||||
}
|
||||
|
||||
BufferType& operator= (BufferType const& other) noexcept
|
||||
{
|
||||
m_data = other.cast <pointer_type> ();
|
||||
m_size = other.size ();
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <bool OtherIsConst>
|
||||
BufferType& operator= (
|
||||
BufferType <OtherIsConst> const& other) noexcept
|
||||
{
|
||||
m_data = other.cast <pointer_type> ();
|
||||
m_size = other.size ();
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T cast () const noexcept
|
||||
{
|
||||
return static_cast <T> (m_data);
|
||||
}
|
||||
|
||||
size_type size () const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
BufferType operator+ (size_type n) const noexcept
|
||||
{
|
||||
return BufferType (cast <byte_type*> (),
|
||||
size () - std::min (size(), n));
|
||||
}
|
||||
|
||||
private:
|
||||
pointer_type m_data;
|
||||
std::size_t m_size;
|
||||
};
|
||||
/** @} */
|
||||
|
||||
#endif
|
||||
@@ -121,11 +121,9 @@ private:
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** A single linear read-only buffer. */
|
||||
//typedef BufferType <true> ConstBuffer;
|
||||
typedef boost::asio::const_buffer ConstBuffer;
|
||||
|
||||
/** A single linear writable buffer. */
|
||||
//typedef BufferType <false> MutableBuffer;
|
||||
typedef boost::asio::mutable_buffer MutableBuffer;
|
||||
|
||||
/** Meets the requirements of ConstBufferSequence */
|
||||
|
||||
@@ -29,7 +29,6 @@ namespace beast {
|
||||
|
||||
#include "async/SharedHandler.cpp"
|
||||
|
||||
#include "basics/ContentBodyBuffer.cpp"
|
||||
#include "basics/PeerRole.cpp"
|
||||
#include "basics/SSLContext.cpp"
|
||||
|
||||
|
||||
@@ -70,9 +70,7 @@ namespace beast {
|
||||
#include "async/SharedHandlerAllocator.h"
|
||||
#include "async/AsyncObject.h"
|
||||
|
||||
# include "basics/BufferType.h"
|
||||
# include "basics/BuffersType.h"
|
||||
#include "basics/ContentBodyBuffer.h"
|
||||
#include "basics/FixedInputBuffer.h"
|
||||
#include "basics/PeerRole.h"
|
||||
#include "basics/SSLContext.h"
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
HTTPMessage::HTTPMessage (HTTPVersion const& version_,
|
||||
StringPairArray& fields,
|
||||
ContentBodyBuffer& body)
|
||||
DynamicBuffer& body)
|
||||
: m_version (version_)
|
||||
, m_headers (fields)
|
||||
{
|
||||
@@ -36,7 +36,7 @@ HTTPHeaders const& HTTPMessage::headers () const
|
||||
return m_headers;
|
||||
}
|
||||
|
||||
ContentBodyBuffer const& HTTPMessage::body () const
|
||||
DynamicBuffer const& HTTPMessage::body () const
|
||||
{
|
||||
return m_body;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public:
|
||||
*/
|
||||
HTTPMessage (HTTPVersion const& version_,
|
||||
StringPairArray& fields,
|
||||
ContentBodyBuffer& body);
|
||||
DynamicBuffer& body);
|
||||
|
||||
/** Returns the HTTP version of this message. */
|
||||
HTTPVersion const& version () const;
|
||||
@@ -49,7 +49,7 @@ public:
|
||||
HTTPHeaders const& headers () const;
|
||||
|
||||
/** Returns the content-body. */
|
||||
ContentBodyBuffer const& body () const;
|
||||
DynamicBuffer const& body () const;
|
||||
|
||||
/** Outputs all the HTTPMessage data excluding the body into a string. */
|
||||
String toString () const;
|
||||
@@ -57,7 +57,7 @@ public:
|
||||
private:
|
||||
HTTPVersion m_version;
|
||||
HTTPHeaders m_headers;
|
||||
ContentBodyBuffer m_body;
|
||||
DynamicBuffer m_body;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -125,7 +125,7 @@ public:
|
||||
return m_headersComplete;
|
||||
}
|
||||
|
||||
ContentBodyBuffer& body ()
|
||||
DynamicBuffer& body ()
|
||||
{
|
||||
return m_body;
|
||||
}
|
||||
@@ -188,8 +188,9 @@ private:
|
||||
|
||||
int onBody (char const* at, std::size_t length)
|
||||
{
|
||||
m_body.commit (boost::asio::buffer_copy (m_body.prepare (length),
|
||||
boost::asio::buffer (at, length)));
|
||||
m_body.commit (boost::asio::buffer_copy (
|
||||
m_body.prepare <boost::asio::mutable_buffer> (length),
|
||||
boost::asio::buffer (at, length)));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -258,7 +259,7 @@ private:
|
||||
std::string m_field;
|
||||
std::string m_value;
|
||||
bool m_headersComplete;
|
||||
ContentBodyBuffer m_body;
|
||||
DynamicBuffer m_body;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -20,7 +20,7 @@
|
||||
HTTPRequest::HTTPRequest (
|
||||
HTTPVersion const& version_,
|
||||
StringPairArray& fields,
|
||||
ContentBodyBuffer& body,
|
||||
DynamicBuffer& body,
|
||||
unsigned short method_)
|
||||
: HTTPMessage (version_, fields, body)
|
||||
, m_method (method_)
|
||||
|
||||
@@ -30,7 +30,7 @@ public:
|
||||
HTTPRequest (
|
||||
HTTPVersion const& version_,
|
||||
StringPairArray& fields,
|
||||
ContentBodyBuffer& body,
|
||||
DynamicBuffer& body,
|
||||
unsigned short method_);
|
||||
|
||||
unsigned short method () const;
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
HTTPResponse::HTTPResponse (
|
||||
HTTPVersion const& version_,
|
||||
StringPairArray& fields,
|
||||
ContentBodyBuffer& body,
|
||||
DynamicBuffer& body,
|
||||
unsigned short status_)
|
||||
: HTTPMessage (version_, fields, body)
|
||||
, m_status (status_)
|
||||
|
||||
@@ -30,7 +30,7 @@ public:
|
||||
HTTPResponse (
|
||||
HTTPVersion const& version_,
|
||||
StringPairArray& fields,
|
||||
ContentBodyBuffer& body,
|
||||
DynamicBuffer& body,
|
||||
unsigned short status_);
|
||||
|
||||
unsigned short status () const;
|
||||
|
||||
Reference in new issue
Block a user