28 #ifndef WEBSOCKETPP_TRANSPORT_ASIO_BASE_HPP
29 #define WEBSOCKETPP_TRANSPORT_ASIO_BASE_HPP
31 #include <websocketpp/common/asio.hpp>
32 #include <websocketpp/common/cpp11.hpp>
33 #include <websocketpp/common/functional.hpp>
34 #include <websocketpp/common/system_error.hpp>
35 #include <websocketpp/common/type_traits.hpp>
52 class handler_allocator {
54 static const size_t size = 1024;
56 handler_allocator() : m_in_use(
false) {}
58 #ifdef _WEBSOCKETPP_DEFAULT_DELETE_FUNCTIONS_
59 handler_allocator(handler_allocator
const & cpy) =
delete;
60 handler_allocator & operator =(handler_allocator
const &) =
delete;
63 void * allocate(std::size_t memsize) {
64 if (!m_in_use && memsize < size) {
66 return static_cast<
void*>(&m_storage);
68 return ::operator
new(memsize);
72 void deallocate(
void * pointer) {
73 if (pointer == &m_storage) {
76 ::operator
delete(pointer);
82 lib::aligned_storage<size>::type m_storage;
91 template <
typename Handler>
94 custom_alloc_handler(handler_allocator& a, Handler h)
99 template <
typename Arg1>
100 void operator()(Arg1 arg1) {
104 template <
typename Arg1,
typename Arg2>
105 void operator()(Arg1 arg1, Arg2 arg2) {
106 handler_(arg1, arg2);
109 friend void* asio_handler_allocate(std::size_t size,
112 return this_handler->allocator_.allocate(size);
115 friend void asio_handler_deallocate(
void* pointer, std::size_t ,
118 this_handler->allocator_.deallocate(pointer);
122 handler_allocator & allocator_;
127 template <
typename Handler>
129 handler_allocator & a, Handler h)
142 template <
typename config>
145 typedef lib::function<
void (lib::asio::error_code
const & ec,
146 size_t bytes_transferred)> async_read_handler;
148 typedef lib::function<
void (lib::asio::error_code
const & ec,
149 size_t bytes_transferred)> async_write_handler;
151 typedef lib::function<
void (lib::error_code
const & ec)> pre_init_handler;
184 class category :
public lib::error_category {
186 char const * name()
const _WEBSOCKETPP_NOEXCEPT_TOKEN_ {
187 return "websocketpp.transport.asio";
190 std::string message(
int value)
const {
193 return "Generic asio transport policy error";
194 case error::invalid_num_bytes:
195 return "async_read_at_least call requested more bytes than buffer can store";
196 case error::pass_through:
197 return "Underlying Transport Error";
198 case error::proxy_failed:
199 return "Proxy connection failed";
200 case error::proxy_invalid:
201 return "Invalid proxy URI";
202 case error::invalid_host_service:
203 return "Invalid host or service";
212 static category instance;
218 return lib::error_code(
static_cast<
int>(e), get_category());
226 _WEBSOCKETPP_ERROR_CODE_ENUM_NS_START_
227 template<>
struct is_error_code_enum<websocketpp::transport::asio::error::value>
229 static bool const value =
true;
231 _WEBSOCKETPP_ERROR_CODE_ENUM_NS_END_