mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-25 13:35:54 +00:00
Refactor net buffers classes
This commit is contained in:
@@ -131,6 +131,8 @@
|
|||||||
<ClInclude Include="..\..\beast\mpl\RemoveReference.h" />
|
<ClInclude Include="..\..\beast\mpl\RemoveReference.h" />
|
||||||
<ClInclude Include="..\..\beast\mpl\RemoveVolatile.h" />
|
<ClInclude Include="..\..\beast\mpl\RemoveVolatile.h" />
|
||||||
<ClInclude Include="..\..\beast\Net.h" />
|
<ClInclude Include="..\..\beast\Net.h" />
|
||||||
|
<ClInclude Include="..\..\beast\net\BufferType.h" />
|
||||||
|
<ClInclude Include="..\..\beast\net\DynamicBuffer.h" />
|
||||||
<ClInclude Include="..\..\beast\net\IPEndpoint.h" />
|
<ClInclude Include="..\..\beast\net\IPEndpoint.h" />
|
||||||
<ClInclude Include="..\..\beast\SafeBool.h" />
|
<ClInclude Include="..\..\beast\SafeBool.h" />
|
||||||
<ClInclude Include="..\..\beast\SmartPtr.h" />
|
<ClInclude Include="..\..\beast\SmartPtr.h" />
|
||||||
@@ -174,8 +176,6 @@
|
|||||||
<ClInclude Include="..\..\modules\beast_asio\async\SharedHandlerAllocator.h" />
|
<ClInclude Include="..\..\modules\beast_asio\async\SharedHandlerAllocator.h" />
|
||||||
<ClInclude Include="..\..\modules\beast_asio\async\SharedHandlerPtr.h" />
|
<ClInclude Include="..\..\modules\beast_asio\async\SharedHandlerPtr.h" />
|
||||||
<ClInclude Include="..\..\modules\beast_asio\async\SharedHandlerType.h" />
|
<ClInclude Include="..\..\modules\beast_asio\async\SharedHandlerType.h" />
|
||||||
<ClInclude Include="..\..\modules\beast_asio\basics\BufferType.h" />
|
|
||||||
<ClInclude Include="..\..\modules\beast_asio\basics\ContentBodyBuffer.h" />
|
|
||||||
<ClInclude Include="..\..\modules\beast_asio\basics\BuffersType.h" />
|
<ClInclude Include="..\..\modules\beast_asio\basics\BuffersType.h" />
|
||||||
<ClInclude Include="..\..\modules\beast_asio\basics\FixedInputBuffer.h" />
|
<ClInclude Include="..\..\modules\beast_asio\basics\FixedInputBuffer.h" />
|
||||||
<ClInclude Include="..\..\modules\beast_asio\basics\PeerRole.h" />
|
<ClInclude Include="..\..\modules\beast_asio\basics\PeerRole.h" />
|
||||||
@@ -466,6 +466,12 @@
|
|||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\beast\net\impl\DynamicBuffer.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="..\..\beast\net\impl\IPEndpoint.cpp">
|
<ClCompile Include="..\..\beast\net\impl\IPEndpoint.cpp">
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||||
@@ -511,12 +517,6 @@
|
|||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\modules\beast_asio\basics\ContentBodyBuffer.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\basics\PeerRole.cpp">
|
<ClCompile Include="..\..\modules\beast_asio\basics\PeerRole.cpp">
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||||
|
|||||||
@@ -902,9 +902,6 @@
|
|||||||
<ClInclude Include="..\..\modules\beast_asio\protocol\PrefilledReadStream.h">
|
<ClInclude Include="..\..\modules\beast_asio\protocol\PrefilledReadStream.h">
|
||||||
<Filter>beast_asio\protocol</Filter>
|
<Filter>beast_asio\protocol</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\modules\beast_asio\basics\ContentBodyBuffer.h">
|
|
||||||
<Filter>beast_asio\basics</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\modules\beast_asio\http\HTTPResponse.h">
|
<ClInclude Include="..\..\modules\beast_asio\http\HTTPResponse.h">
|
||||||
<Filter>beast_asio\http</Filter>
|
<Filter>beast_asio\http</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
@@ -935,9 +932,6 @@
|
|||||||
<ClInclude Include="..\..\modules\beast_asio\basics\BuffersType.h">
|
<ClInclude Include="..\..\modules\beast_asio\basics\BuffersType.h">
|
||||||
<Filter>beast_asio\basics</Filter>
|
<Filter>beast_asio\basics</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\modules\beast_asio\basics\BufferType.h">
|
|
||||||
<Filter>beast_asio\basics</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\modules\beast_core\memory\SharedSingleton.h">
|
<ClInclude Include="..\..\modules\beast_core\memory\SharedSingleton.h">
|
||||||
<Filter>beast_core\memory</Filter>
|
<Filter>beast_core\memory</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
@@ -1215,6 +1209,12 @@
|
|||||||
<ClInclude Include="..\..\beast\SmartPtr.h">
|
<ClInclude Include="..\..\beast\SmartPtr.h">
|
||||||
<Filter>beast</Filter>
|
<Filter>beast</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\beast\net\DynamicBuffer.h">
|
||||||
|
<Filter>beast\net</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\beast\net\BufferType.h">
|
||||||
|
<Filter>beast\net</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\modules\beast_core\containers\AbstractFifo.cpp">
|
<ClCompile Include="..\..\modules\beast_core\containers\AbstractFifo.cpp">
|
||||||
@@ -1610,9 +1610,6 @@
|
|||||||
<ClCompile Include="..\..\modules\beast_asio\protocol\HandshakeDetectLogicPROXY.cpp">
|
<ClCompile Include="..\..\modules\beast_asio\protocol\HandshakeDetectLogicPROXY.cpp">
|
||||||
<Filter>beast_asio\protocol</Filter>
|
<Filter>beast_asio\protocol</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\modules\beast_asio\basics\ContentBodyBuffer.cpp">
|
|
||||||
<Filter>beast_asio\basics</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\modules\beast_asio\http\HTTPResponse.cpp">
|
<ClCompile Include="..\..\modules\beast_asio\http\HTTPResponse.cpp">
|
||||||
<Filter>beast_asio\http</Filter>
|
<Filter>beast_asio\http</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
@@ -1748,6 +1745,9 @@
|
|||||||
<ClCompile Include="..\..\beast\utility\impl\Error.cpp">
|
<ClCompile Include="..\..\beast\utility\impl\Error.cpp">
|
||||||
<Filter>beast\utility\impl</Filter>
|
<Filter>beast\utility\impl</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\beast\net\impl\DynamicBuffer.cpp">
|
||||||
|
<Filter>beast\net\impl</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Text Include="..\..\TODO.txt">
|
<Text Include="..\..\TODO.txt">
|
||||||
|
|||||||
@@ -20,6 +20,9 @@
|
|||||||
#ifndef BEAST_NET_H_INCLUDED
|
#ifndef BEAST_NET_H_INCLUDED
|
||||||
#define BEAST_NET_H_INCLUDED
|
#define BEAST_NET_H_INCLUDED
|
||||||
|
|
||||||
|
#include "net/BufferType.h"
|
||||||
|
#include "net/DynamicBuffer.h"
|
||||||
|
|
||||||
#include "net/IPEndpoint.h"
|
#include "net/IPEndpoint.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -17,8 +17,12 @@
|
|||||||
*/
|
*/
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
|
||||||
#ifndef BEAST_ASIO_BASICS_BUFFERTYPE_H_INCLUDED
|
#ifndef BEAST_NET_BASICS_BUFFERTYPE_H_INCLUDED
|
||||||
#define BEAST_ASIO_BASICS_BUFFERTYPE_H_INCLUDED
|
#define BEAST_NET_BASICS_BUFFERTYPE_H_INCLUDED
|
||||||
|
|
||||||
|
#include "../mpl/IfCond.h"
|
||||||
|
|
||||||
|
namespace beast {
|
||||||
|
|
||||||
/** General linear memory buffer.
|
/** General linear memory buffer.
|
||||||
This wraps the underlying buffer type and provides additional methods
|
This wraps the underlying buffer type and provides additional methods
|
||||||
@@ -99,4 +103,6 @@ private:
|
|||||||
};
|
};
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
125
beast/net/DynamicBuffer.h
Normal file
125
beast/net/DynamicBuffer.h
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/*
|
||||||
|
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_NET_DYNAMICBUFFER_H_INCLUDED
|
||||||
|
#define BEAST_NET_DYNAMICBUFFER_H_INCLUDED
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace beast {
|
||||||
|
|
||||||
|
/** Disjoint, but efficient buffer storage for network operations.
|
||||||
|
This is designed to not require asio in order to compile.
|
||||||
|
*/
|
||||||
|
class DynamicBuffer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
defaultBlocksize = 32 * 1024
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef std::size_t size_type;
|
||||||
|
|
||||||
|
/** Create the dynamic buffer with the specified block size. */
|
||||||
|
explicit DynamicBuffer (size_type blocksize = defaultBlocksize);
|
||||||
|
|
||||||
|
DynamicBuffer (DynamicBuffer const& other);
|
||||||
|
|
||||||
|
~DynamicBuffer ();
|
||||||
|
|
||||||
|
DynamicBuffer& operator= (DynamicBuffer const& other);
|
||||||
|
|
||||||
|
/** Swap the contents of this buffer with another.
|
||||||
|
This is the preferred way to transfer ownership.
|
||||||
|
*/
|
||||||
|
void swapWith (DynamicBuffer& other);
|
||||||
|
|
||||||
|
/** Returns the size of the input sequence. */
|
||||||
|
size_type size () const;
|
||||||
|
|
||||||
|
/** Returns a buffer to the input sequence.
|
||||||
|
ConstBufferType must be constructible with this signature:
|
||||||
|
ConstBufferType (void const* buffer, size_type bytes);
|
||||||
|
*/
|
||||||
|
template <typename ConstBufferType>
|
||||||
|
std::vector <ConstBufferType> data () const
|
||||||
|
{
|
||||||
|
std::vector <ConstBufferType> buffers;
|
||||||
|
buffers.reserve (m_buffers.size());
|
||||||
|
size_type amount (m_size);
|
||||||
|
for (typename Buffers::const_iterator iter (m_buffers.begin());
|
||||||
|
amount > 0 && iter != m_buffers.end(); ++iter)
|
||||||
|
{
|
||||||
|
size_type const n (std::min (amount, m_blocksize));
|
||||||
|
buffers.push_back (ConstBufferType (*iter, n));
|
||||||
|
amount -= n;
|
||||||
|
}
|
||||||
|
return buffers;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Reserve space in the output sequence.
|
||||||
|
This also returns a buffer suitable for writing.
|
||||||
|
MutableBufferType must be constructible with this signature:
|
||||||
|
MutableBufferType (void* buffer, size_type bytes);
|
||||||
|
*/
|
||||||
|
template <typename MutableBufferType>
|
||||||
|
std::vector <MutableBufferType> prepare (size_type amount)
|
||||||
|
{
|
||||||
|
std::vector <MutableBufferType> buffers;
|
||||||
|
buffers.reserve (m_buffers.size());
|
||||||
|
reserve (amount);
|
||||||
|
size_type offset (m_size % m_blocksize);
|
||||||
|
for (Buffers::iterator iter = m_buffers.begin () + (m_size / m_blocksize);
|
||||||
|
amount > 0 && iter != m_buffers.end (); ++iter)
|
||||||
|
{
|
||||||
|
size_type const n (std::min (amount, m_blocksize - offset));
|
||||||
|
buffers.push_back (MutableBufferType (
|
||||||
|
((static_cast <char*> (*iter)) + offset), n));
|
||||||
|
amount -= n;
|
||||||
|
offset = 0;
|
||||||
|
}
|
||||||
|
return buffers;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Reserve space in the output sequence. */
|
||||||
|
void reserve (size_type n);
|
||||||
|
|
||||||
|
/** Move bytes from the output to the input sequence. */
|
||||||
|
void commit (size_type n);
|
||||||
|
|
||||||
|
/** Release memory while preserving the input sequence. */
|
||||||
|
void shrink_to_fit ();
|
||||||
|
|
||||||
|
/** Convert the entire buffer into a single string.
|
||||||
|
This is mostly for diagnostics, it defeats the purpose of the class!
|
||||||
|
*/
|
||||||
|
std::string to_string () const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
typedef std::vector <void*> Buffers;
|
||||||
|
|
||||||
|
size_type m_blocksize;
|
||||||
|
size_type m_size;
|
||||||
|
Buffers m_buffers;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -23,4 +23,5 @@
|
|||||||
|
|
||||||
#include "../../modules/beast_core/beast_core.h" // for UnitTest
|
#include "../../modules/beast_core/beast_core.h" // for UnitTest
|
||||||
|
|
||||||
|
#include "impl/DynamicBuffer.cpp"
|
||||||
#include "impl/IPEndpoint.cpp"
|
#include "impl/IPEndpoint.cpp"
|
||||||
|
|||||||
91
beast/net/impl/DynamicBuffer.cpp
Normal file
91
beast/net/impl/DynamicBuffer.cpp
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/*
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
//==============================================================================
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "../DynamicBuffer.h"
|
||||||
|
|
||||||
|
namespace beast {
|
||||||
|
|
||||||
|
DynamicBuffer::DynamicBuffer (size_type blocksize)
|
||||||
|
: m_blocksize (blocksize)
|
||||||
|
, m_size (0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
DynamicBuffer::~DynamicBuffer ()
|
||||||
|
{
|
||||||
|
for (Buffers::iterator iter (m_buffers.begin());
|
||||||
|
iter != m_buffers.end(); ++iter)
|
||||||
|
free (*iter);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DynamicBuffer::swapWith (DynamicBuffer& other)
|
||||||
|
{
|
||||||
|
std::swap (m_blocksize, other.m_blocksize);
|
||||||
|
std::swap (m_size, other.m_size);
|
||||||
|
m_buffers.swap (other.m_buffers);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DynamicBuffer::commit (size_type n)
|
||||||
|
{
|
||||||
|
m_size += n;
|
||||||
|
bassert (m_size <= m_buffers.size () * m_blocksize);
|
||||||
|
}
|
||||||
|
|
||||||
|
DynamicBuffer::size_type DynamicBuffer::size () const
|
||||||
|
{
|
||||||
|
return m_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DynamicBuffer::reserve (size_type n)
|
||||||
|
{
|
||||||
|
size_type count ((m_size + n + m_blocksize - 1) / m_blocksize);
|
||||||
|
if (count > m_buffers.size ())
|
||||||
|
for (count -= m_buffers.size (); count-- > 0;)
|
||||||
|
m_buffers.push_back (malloc (m_blocksize));
|
||||||
|
}
|
||||||
|
|
||||||
|
void DynamicBuffer::shrink_to_fit ()
|
||||||
|
{
|
||||||
|
size_type const count ((m_size + m_blocksize - 1) / m_blocksize);
|
||||||
|
while (m_buffers.size () > count)
|
||||||
|
{
|
||||||
|
free (m_buffers.back ());
|
||||||
|
m_buffers.erase (m_buffers.end () - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string DynamicBuffer::to_string () const
|
||||||
|
{
|
||||||
|
std::string (s);
|
||||||
|
s.reserve (m_size);
|
||||||
|
std::size_t amount (m_size);
|
||||||
|
for (Buffers::const_iterator iter (m_buffers.begin());
|
||||||
|
amount > 0 && iter != m_buffers.end(); ++iter)
|
||||||
|
{
|
||||||
|
char const* p (static_cast <char const*> (*iter));
|
||||||
|
size_type const n (std::min (amount, m_blocksize));
|
||||||
|
s.append (p, p + n);
|
||||||
|
amount -= n;
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -121,11 +121,9 @@ private:
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
/** A single linear read-only buffer. */
|
/** A single linear read-only buffer. */
|
||||||
//typedef BufferType <true> ConstBuffer;
|
|
||||||
typedef boost::asio::const_buffer ConstBuffer;
|
typedef boost::asio::const_buffer ConstBuffer;
|
||||||
|
|
||||||
/** A single linear writable buffer. */
|
/** A single linear writable buffer. */
|
||||||
//typedef BufferType <false> MutableBuffer;
|
|
||||||
typedef boost::asio::mutable_buffer MutableBuffer;
|
typedef boost::asio::mutable_buffer MutableBuffer;
|
||||||
|
|
||||||
/** Meets the requirements of ConstBufferSequence */
|
/** Meets the requirements of ConstBufferSequence */
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ namespace beast {
|
|||||||
|
|
||||||
#include "async/SharedHandler.cpp"
|
#include "async/SharedHandler.cpp"
|
||||||
|
|
||||||
#include "basics/ContentBodyBuffer.cpp"
|
|
||||||
#include "basics/PeerRole.cpp"
|
#include "basics/PeerRole.cpp"
|
||||||
#include "basics/SSLContext.cpp"
|
#include "basics/SSLContext.cpp"
|
||||||
|
|
||||||
|
|||||||
@@ -70,9 +70,7 @@ namespace beast {
|
|||||||
#include "async/SharedHandlerAllocator.h"
|
#include "async/SharedHandlerAllocator.h"
|
||||||
#include "async/AsyncObject.h"
|
#include "async/AsyncObject.h"
|
||||||
|
|
||||||
# include "basics/BufferType.h"
|
|
||||||
# include "basics/BuffersType.h"
|
# include "basics/BuffersType.h"
|
||||||
#include "basics/ContentBodyBuffer.h"
|
|
||||||
#include "basics/FixedInputBuffer.h"
|
#include "basics/FixedInputBuffer.h"
|
||||||
#include "basics/PeerRole.h"
|
#include "basics/PeerRole.h"
|
||||||
#include "basics/SSLContext.h"
|
#include "basics/SSLContext.h"
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
HTTPMessage::HTTPMessage (HTTPVersion const& version_,
|
HTTPMessage::HTTPMessage (HTTPVersion const& version_,
|
||||||
StringPairArray& fields,
|
StringPairArray& fields,
|
||||||
ContentBodyBuffer& body)
|
DynamicBuffer& body)
|
||||||
: m_version (version_)
|
: m_version (version_)
|
||||||
, m_headers (fields)
|
, m_headers (fields)
|
||||||
{
|
{
|
||||||
@@ -36,7 +36,7 @@ HTTPHeaders const& HTTPMessage::headers () const
|
|||||||
return m_headers;
|
return m_headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
ContentBodyBuffer const& HTTPMessage::body () const
|
DynamicBuffer const& HTTPMessage::body () const
|
||||||
{
|
{
|
||||||
return m_body;
|
return m_body;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
HTTPMessage (HTTPVersion const& version_,
|
HTTPMessage (HTTPVersion const& version_,
|
||||||
StringPairArray& fields,
|
StringPairArray& fields,
|
||||||
ContentBodyBuffer& body);
|
DynamicBuffer& body);
|
||||||
|
|
||||||
/** Returns the HTTP version of this message. */
|
/** Returns the HTTP version of this message. */
|
||||||
HTTPVersion const& version () const;
|
HTTPVersion const& version () const;
|
||||||
@@ -49,7 +49,7 @@ public:
|
|||||||
HTTPHeaders const& headers () const;
|
HTTPHeaders const& headers () const;
|
||||||
|
|
||||||
/** Returns the content-body. */
|
/** Returns the content-body. */
|
||||||
ContentBodyBuffer const& body () const;
|
DynamicBuffer const& body () const;
|
||||||
|
|
||||||
/** Outputs all the HTTPMessage data excluding the body into a string. */
|
/** Outputs all the HTTPMessage data excluding the body into a string. */
|
||||||
String toString () const;
|
String toString () const;
|
||||||
@@ -57,7 +57,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
HTTPVersion m_version;
|
HTTPVersion m_version;
|
||||||
HTTPHeaders m_headers;
|
HTTPHeaders m_headers;
|
||||||
ContentBodyBuffer m_body;
|
DynamicBuffer m_body;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ public:
|
|||||||
return m_headersComplete;
|
return m_headersComplete;
|
||||||
}
|
}
|
||||||
|
|
||||||
ContentBodyBuffer& body ()
|
DynamicBuffer& body ()
|
||||||
{
|
{
|
||||||
return m_body;
|
return m_body;
|
||||||
}
|
}
|
||||||
@@ -188,7 +188,8 @@ private:
|
|||||||
|
|
||||||
int onBody (char const* at, std::size_t length)
|
int onBody (char const* at, std::size_t length)
|
||||||
{
|
{
|
||||||
m_body.commit (boost::asio::buffer_copy (m_body.prepare (length),
|
m_body.commit (boost::asio::buffer_copy (
|
||||||
|
m_body.prepare <boost::asio::mutable_buffer> (length),
|
||||||
boost::asio::buffer (at, length)));
|
boost::asio::buffer (at, length)));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -258,7 +259,7 @@ private:
|
|||||||
std::string m_field;
|
std::string m_field;
|
||||||
std::string m_value;
|
std::string m_value;
|
||||||
bool m_headersComplete;
|
bool m_headersComplete;
|
||||||
ContentBodyBuffer m_body;
|
DynamicBuffer m_body;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
HTTPRequest::HTTPRequest (
|
HTTPRequest::HTTPRequest (
|
||||||
HTTPVersion const& version_,
|
HTTPVersion const& version_,
|
||||||
StringPairArray& fields,
|
StringPairArray& fields,
|
||||||
ContentBodyBuffer& body,
|
DynamicBuffer& body,
|
||||||
unsigned short method_)
|
unsigned short method_)
|
||||||
: HTTPMessage (version_, fields, body)
|
: HTTPMessage (version_, fields, body)
|
||||||
, m_method (method_)
|
, m_method (method_)
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public:
|
|||||||
HTTPRequest (
|
HTTPRequest (
|
||||||
HTTPVersion const& version_,
|
HTTPVersion const& version_,
|
||||||
StringPairArray& fields,
|
StringPairArray& fields,
|
||||||
ContentBodyBuffer& body,
|
DynamicBuffer& body,
|
||||||
unsigned short method_);
|
unsigned short method_);
|
||||||
|
|
||||||
unsigned short method () const;
|
unsigned short method () const;
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
HTTPResponse::HTTPResponse (
|
HTTPResponse::HTTPResponse (
|
||||||
HTTPVersion const& version_,
|
HTTPVersion const& version_,
|
||||||
StringPairArray& fields,
|
StringPairArray& fields,
|
||||||
ContentBodyBuffer& body,
|
DynamicBuffer& body,
|
||||||
unsigned short status_)
|
unsigned short status_)
|
||||||
: HTTPMessage (version_, fields, body)
|
: HTTPMessage (version_, fields, body)
|
||||||
, m_status (status_)
|
, m_status (status_)
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public:
|
|||||||
HTTPResponse (
|
HTTPResponse (
|
||||||
HTTPVersion const& version_,
|
HTTPVersion const& version_,
|
||||||
StringPairArray& fields,
|
StringPairArray& fields,
|
||||||
ContentBodyBuffer& body,
|
DynamicBuffer& body,
|
||||||
unsigned short status_);
|
unsigned short status_);
|
||||||
|
|
||||||
unsigned short status () const;
|
unsigned short status () const;
|
||||||
|
|||||||
Reference in New Issue
Block a user