-
Notifications
You must be signed in to change notification settings - Fork 0
/
asio.hpp
49 lines (40 loc) · 1.85 KB
/
asio.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#pragma once
#include <vxldollar/boost/asio/write.hpp>
namespace vxldollar
{
class shared_const_buffer
{
public:
using value_type = boost::asio::const_buffer;
using const_iterator = boost::asio::const_buffer const *;
explicit shared_const_buffer (std::vector<uint8_t> const & data);
explicit shared_const_buffer (uint8_t data);
explicit shared_const_buffer (std::string const & data);
explicit shared_const_buffer (std::vector<uint8_t> && data);
explicit shared_const_buffer (std::shared_ptr<std::vector<uint8_t>> const & data);
boost::asio::const_buffer const * begin () const;
boost::asio::const_buffer const * end () const;
std::size_t size () const;
private:
std::shared_ptr<std::vector<uint8_t>> m_data;
boost::asio::const_buffer m_buffer;
};
static_assert (boost::asio::is_const_buffer_sequence<shared_const_buffer>::value, "Not ConstBufferSequence compliant");
template <typename AsyncWriteStream, typename WriteHandler>
BOOST_ASIO_INITFN_RESULT_TYPE (WriteHandler, void (boost::system::error_code, std::size_t))
async_write (AsyncWriteStream & s, vxldollar::shared_const_buffer const & buffer, WriteHandler && handler)
{
return boost::asio::async_write (s, buffer, std::forward<WriteHandler> (handler));
}
/**
* Alternative to vxldollar::async_write where scatter/gather is desired for best performance, and where
* the buffer originates from Flatbuffers.
* @warning The buffers must be captured in the handler to ensure their lifetimes are properly extended.
*/
template <typename AsyncWriteStream, typename BufferType, typename WriteHandler>
BOOST_ASIO_INITFN_RESULT_TYPE (WriteHandler, void (boost::system::error_code, std::size_t))
unsafe_async_write (AsyncWriteStream & s, BufferType && buffer, WriteHandler && handler)
{
return boost::asio::async_write (s, buffer, std::forward<WriteHandler> (handler));
}
}