Create the state using the handler's associated allocator.
| 50 | |
| 51 | // Create the state using the handler's associated allocator. |
| 52 | static read_input_state* create(Handler&& handler) |
| 53 | { |
| 54 | // A unique_ptr deleter that is used to destroy uninitialised objects. |
| 55 | struct deleter |
| 56 | { |
| 57 | // Get the handler's associated allocator type. If the handler does not |
| 58 | // specify an associated allocator, we will use a recycling allocator as |
| 59 | // the default. As the associated allocator is a proto-allocator, we must |
| 60 | // rebind it to the correct type before we can use it to allocate objects. |
| 61 | typename std::allocator_traits< |
| 62 | boost::asio::associated_allocator_t<Handler, |
| 63 | boost::asio::recycling_allocator<void>>>::template |
| 64 | rebind_alloc<read_input_state> alloc; |
| 65 | |
| 66 | void operator()(read_input_state* ptr) |
| 67 | { |
| 68 | std::allocator_traits<decltype(alloc)>::deallocate(alloc, ptr, 1); |
| 69 | } |
| 70 | } d{boost::asio::get_associated_allocator(handler, |
| 71 | boost::asio::recycling_allocator<void>())}; |
| 72 | |
| 73 | // Allocate memory for the state. |
| 74 | std::unique_ptr<read_input_state, deleter> uninit_ptr( |
| 75 | std::allocator_traits<decltype(d.alloc)>::allocate(d.alloc, 1), d); |
| 76 | |
| 77 | // Construct the state into the newly allocated memory. This might throw. |
| 78 | read_input_state* ptr = |
| 79 | new (uninit_ptr.get()) read_input_state(std::move(handler)); |
| 80 | |
| 81 | // Release ownership of the memory and return the newly allocated state. |
| 82 | uninit_ptr.release(); |
| 83 | return ptr; |
| 84 | } |
| 85 | |
| 86 | static void callback(void* arg, const char* result) |
| 87 | { |
nothing calls this directly
no test coverage detected