]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/asio/impl/write.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / asio / impl / write.hpp
1 //
2 // impl/write.hpp
3 // ~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 //
10
11 #ifndef BOOST_ASIO_IMPL_WRITE_HPP
12 #define BOOST_ASIO_IMPL_WRITE_HPP
13
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17
18 #include <boost/asio/associated_allocator.hpp>
19 #include <boost/asio/associated_executor.hpp>
20 #include <boost/asio/buffer.hpp>
21 #include <boost/asio/completion_condition.hpp>
22 #include <boost/asio/detail/array_fwd.hpp>
23 #include <boost/asio/detail/base_from_completion_cond.hpp>
24 #include <boost/asio/detail/bind_handler.hpp>
25 #include <boost/asio/detail/consuming_buffers.hpp>
26 #include <boost/asio/detail/dependent_type.hpp>
27 #include <boost/asio/detail/handler_alloc_helpers.hpp>
28 #include <boost/asio/detail/handler_cont_helpers.hpp>
29 #include <boost/asio/detail/handler_invoke_helpers.hpp>
30 #include <boost/asio/detail/handler_type_requirements.hpp>
31 #include <boost/asio/detail/throw_error.hpp>
32
33 #include <boost/asio/detail/push_options.hpp>
34
35 namespace boost {
36 namespace asio {
37
38 namespace detail
39 {
40 template <typename SyncWriteStream, typename ConstBufferSequence,
41 typename ConstBufferIterator, typename CompletionCondition>
42 std::size_t write_buffer_sequence(SyncWriteStream& s,
43 const ConstBufferSequence& buffers, const ConstBufferIterator&,
44 CompletionCondition completion_condition, boost::system::error_code& ec)
45 {
46 ec = boost::system::error_code();
47 boost::asio::detail::consuming_buffers<const_buffer,
48 ConstBufferSequence, ConstBufferIterator> tmp(buffers);
49 while (!tmp.empty())
50 {
51 if (std::size_t max_size = detail::adapt_completion_condition_result(
52 completion_condition(ec, tmp.total_consumed())))
53 tmp.consume(s.write_some(tmp.prepare(max_size), ec));
54 else
55 break;
56 }
57 return tmp.total_consumed();;
58 }
59 } // namespace detail
60
61 template <typename SyncWriteStream, typename ConstBufferSequence,
62 typename CompletionCondition>
63 inline std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers,
64 CompletionCondition completion_condition, boost::system::error_code& ec,
65 typename enable_if<
66 is_const_buffer_sequence<ConstBufferSequence>::value
67 >::type*)
68 {
69 return detail::write_buffer_sequence(s, buffers,
70 boost::asio::buffer_sequence_begin(buffers), completion_condition, ec);
71 }
72
73 template <typename SyncWriteStream, typename ConstBufferSequence>
74 inline std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers,
75 typename enable_if<
76 is_const_buffer_sequence<ConstBufferSequence>::value
77 >::type*)
78 {
79 boost::system::error_code ec;
80 std::size_t bytes_transferred = write(s, buffers, transfer_all(), ec);
81 boost::asio::detail::throw_error(ec, "write");
82 return bytes_transferred;
83 }
84
85 template <typename SyncWriteStream, typename ConstBufferSequence>
86 inline std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers,
87 boost::system::error_code& ec,
88 typename enable_if<
89 is_const_buffer_sequence<ConstBufferSequence>::value
90 >::type*)
91 {
92 return write(s, buffers, transfer_all(), ec);
93 }
94
95 template <typename SyncWriteStream, typename ConstBufferSequence,
96 typename CompletionCondition>
97 inline std::size_t write(SyncWriteStream& s, const ConstBufferSequence& buffers,
98 CompletionCondition completion_condition,
99 typename enable_if<
100 is_const_buffer_sequence<ConstBufferSequence>::value
101 >::type*)
102 {
103 boost::system::error_code ec;
104 std::size_t bytes_transferred = write(s, buffers, completion_condition, ec);
105 boost::asio::detail::throw_error(ec, "write");
106 return bytes_transferred;
107 }
108
109 template <typename SyncWriteStream, typename DynamicBuffer,
110 typename CompletionCondition>
111 std::size_t write(SyncWriteStream& s,
112 BOOST_ASIO_MOVE_ARG(DynamicBuffer) buffers,
113 CompletionCondition completion_condition, boost::system::error_code& ec,
114 typename enable_if<
115 is_dynamic_buffer<DynamicBuffer>::value
116 >::type*)
117 {
118 typename decay<DynamicBuffer>::type b(
119 BOOST_ASIO_MOVE_CAST(DynamicBuffer)(buffers));
120
121 std::size_t bytes_transferred = write(s, b.data(), completion_condition, ec);
122 b.consume(bytes_transferred);
123 return bytes_transferred;
124 }
125
126 template <typename SyncWriteStream, typename DynamicBuffer>
127 inline std::size_t write(SyncWriteStream& s,
128 BOOST_ASIO_MOVE_ARG(DynamicBuffer) buffers,
129 typename enable_if<
130 is_dynamic_buffer<DynamicBuffer>::value
131 >::type*)
132 {
133 boost::system::error_code ec;
134 std::size_t bytes_transferred = write(s,
135 BOOST_ASIO_MOVE_CAST(DynamicBuffer)(buffers),
136 transfer_all(), ec);
137 boost::asio::detail::throw_error(ec, "write");
138 return bytes_transferred;
139 }
140
141 template <typename SyncWriteStream, typename DynamicBuffer>
142 inline std::size_t write(SyncWriteStream& s,
143 BOOST_ASIO_MOVE_ARG(DynamicBuffer) buffers,
144 boost::system::error_code& ec,
145 typename enable_if<
146 is_dynamic_buffer<DynamicBuffer>::value
147 >::type*)
148 {
149 return write(s, BOOST_ASIO_MOVE_CAST(DynamicBuffer)(buffers),
150 transfer_all(), ec);
151 }
152
153 template <typename SyncWriteStream, typename DynamicBuffer,
154 typename CompletionCondition>
155 inline std::size_t write(SyncWriteStream& s,
156 BOOST_ASIO_MOVE_ARG(DynamicBuffer) buffers,
157 CompletionCondition completion_condition,
158 typename enable_if<
159 is_dynamic_buffer<DynamicBuffer>::value
160 >::type*)
161 {
162 boost::system::error_code ec;
163 std::size_t bytes_transferred = write(s,
164 BOOST_ASIO_MOVE_CAST(DynamicBuffer)(buffers),
165 completion_condition, ec);
166 boost::asio::detail::throw_error(ec, "write");
167 return bytes_transferred;
168 }
169
170 #if !defined(BOOST_ASIO_NO_EXTENSIONS)
171 #if !defined(BOOST_ASIO_NO_IOSTREAM)
172
173 template <typename SyncWriteStream, typename Allocator,
174 typename CompletionCondition>
175 inline std::size_t write(SyncWriteStream& s,
176 boost::asio::basic_streambuf<Allocator>& b,
177 CompletionCondition completion_condition, boost::system::error_code& ec)
178 {
179 return write(s, basic_streambuf_ref<Allocator>(b), completion_condition, ec);
180 }
181
182 template <typename SyncWriteStream, typename Allocator>
183 inline std::size_t write(SyncWriteStream& s,
184 boost::asio::basic_streambuf<Allocator>& b)
185 {
186 return write(s, basic_streambuf_ref<Allocator>(b));
187 }
188
189 template <typename SyncWriteStream, typename Allocator>
190 inline std::size_t write(SyncWriteStream& s,
191 boost::asio::basic_streambuf<Allocator>& b,
192 boost::system::error_code& ec)
193 {
194 return write(s, basic_streambuf_ref<Allocator>(b), ec);
195 }
196
197 template <typename SyncWriteStream, typename Allocator,
198 typename CompletionCondition>
199 inline std::size_t write(SyncWriteStream& s,
200 boost::asio::basic_streambuf<Allocator>& b,
201 CompletionCondition completion_condition)
202 {
203 return write(s, basic_streambuf_ref<Allocator>(b), completion_condition);
204 }
205
206 #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
207 #endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
208
209 namespace detail
210 {
211 template <typename AsyncWriteStream, typename ConstBufferSequence,
212 typename ConstBufferIterator, typename CompletionCondition,
213 typename WriteHandler>
214 class write_op
215 : detail::base_from_completion_cond<CompletionCondition>
216 {
217 public:
218 write_op(AsyncWriteStream& stream, const ConstBufferSequence& buffers,
219 CompletionCondition completion_condition, WriteHandler& handler)
220 : detail::base_from_completion_cond<
221 CompletionCondition>(completion_condition),
222 stream_(stream),
223 buffers_(buffers),
224 start_(0),
225 handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(handler))
226 {
227 }
228
229 #if defined(BOOST_ASIO_HAS_MOVE)
230 write_op(const write_op& other)
231 : detail::base_from_completion_cond<CompletionCondition>(other),
232 stream_(other.stream_),
233 buffers_(other.buffers_),
234 start_(other.start_),
235 handler_(other.handler_)
236 {
237 }
238
239 write_op(write_op&& other)
240 : detail::base_from_completion_cond<CompletionCondition>(other),
241 stream_(other.stream_),
242 buffers_(other.buffers_),
243 start_(other.start_),
244 handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(other.handler_))
245 {
246 }
247 #endif // defined(BOOST_ASIO_HAS_MOVE)
248
249 void operator()(const boost::system::error_code& ec,
250 std::size_t bytes_transferred, int start = 0)
251 {
252 std::size_t max_size;
253 switch (start_ = start)
254 {
255 case 1:
256 max_size = this->check_for_completion(ec, buffers_.total_consumed());
257 do
258 {
259 stream_.async_write_some(buffers_.prepare(max_size),
260 BOOST_ASIO_MOVE_CAST(write_op)(*this));
261 return; default:
262 buffers_.consume(bytes_transferred);
263 if ((!ec && bytes_transferred == 0) || buffers_.empty())
264 break;
265 max_size = this->check_for_completion(ec, buffers_.total_consumed());
266 } while (max_size > 0);
267
268 handler_(ec, buffers_.total_consumed());
269 }
270 }
271
272 //private:
273 AsyncWriteStream& stream_;
274 boost::asio::detail::consuming_buffers<const_buffer,
275 ConstBufferSequence, ConstBufferIterator> buffers_;
276 int start_;
277 WriteHandler handler_;
278 };
279
280 template <typename AsyncWriteStream, typename ConstBufferSequence,
281 typename ConstBufferIterator, typename CompletionCondition,
282 typename WriteHandler>
283 inline void* asio_handler_allocate(std::size_t size,
284 write_op<AsyncWriteStream, ConstBufferSequence, ConstBufferIterator,
285 CompletionCondition, WriteHandler>* this_handler)
286 {
287 return boost_asio_handler_alloc_helpers::allocate(
288 size, this_handler->handler_);
289 }
290
291 template <typename AsyncWriteStream, typename ConstBufferSequence,
292 typename ConstBufferIterator, typename CompletionCondition,
293 typename WriteHandler>
294 inline void asio_handler_deallocate(void* pointer, std::size_t size,
295 write_op<AsyncWriteStream, ConstBufferSequence, ConstBufferIterator,
296 CompletionCondition, WriteHandler>* this_handler)
297 {
298 boost_asio_handler_alloc_helpers::deallocate(
299 pointer, size, this_handler->handler_);
300 }
301
302 template <typename AsyncWriteStream, typename ConstBufferSequence,
303 typename ConstBufferIterator, typename CompletionCondition,
304 typename WriteHandler>
305 inline bool asio_handler_is_continuation(
306 write_op<AsyncWriteStream, ConstBufferSequence, ConstBufferIterator,
307 CompletionCondition, WriteHandler>* this_handler)
308 {
309 return this_handler->start_ == 0 ? true
310 : boost_asio_handler_cont_helpers::is_continuation(
311 this_handler->handler_);
312 }
313
314 template <typename Function, typename AsyncWriteStream,
315 typename ConstBufferSequence, typename ConstBufferIterator,
316 typename CompletionCondition, typename WriteHandler>
317 inline void asio_handler_invoke(Function& function,
318 write_op<AsyncWriteStream, ConstBufferSequence, ConstBufferIterator,
319 CompletionCondition, WriteHandler>* this_handler)
320 {
321 boost_asio_handler_invoke_helpers::invoke(
322 function, this_handler->handler_);
323 }
324
325 template <typename Function, typename AsyncWriteStream,
326 typename ConstBufferSequence, typename ConstBufferIterator,
327 typename CompletionCondition, typename WriteHandler>
328 inline void asio_handler_invoke(const Function& function,
329 write_op<AsyncWriteStream, ConstBufferSequence, ConstBufferIterator,
330 CompletionCondition, WriteHandler>* this_handler)
331 {
332 boost_asio_handler_invoke_helpers::invoke(
333 function, this_handler->handler_);
334 }
335
336 template <typename AsyncWriteStream, typename ConstBufferSequence,
337 typename ConstBufferIterator, typename CompletionCondition,
338 typename WriteHandler>
339 inline void start_write_buffer_sequence_op(AsyncWriteStream& stream,
340 const ConstBufferSequence& buffers, const ConstBufferIterator&,
341 CompletionCondition completion_condition, WriteHandler& handler)
342 {
343 detail::write_op<AsyncWriteStream, ConstBufferSequence,
344 ConstBufferIterator, CompletionCondition, WriteHandler>(
345 stream, buffers, completion_condition, handler)(
346 boost::system::error_code(), 0, 1);
347 }
348
349 } // namespace detail
350
351 #if !defined(GENERATING_DOCUMENTATION)
352
353 template <typename AsyncWriteStream, typename ConstBufferSequence,
354 typename ConstBufferIterator, typename CompletionCondition,
355 typename WriteHandler, typename Allocator>
356 struct associated_allocator<
357 detail::write_op<AsyncWriteStream, ConstBufferSequence,
358 ConstBufferIterator, CompletionCondition, WriteHandler>,
359 Allocator>
360 {
361 typedef typename associated_allocator<WriteHandler, Allocator>::type type;
362
363 static type get(
364 const detail::write_op<AsyncWriteStream, ConstBufferSequence,
365 ConstBufferIterator, CompletionCondition, WriteHandler>& h,
366 const Allocator& a = Allocator()) BOOST_ASIO_NOEXCEPT
367 {
368 return associated_allocator<WriteHandler, Allocator>::get(h.handler_, a);
369 }
370 };
371
372 template <typename AsyncWriteStream, typename ConstBufferSequence,
373 typename ConstBufferIterator, typename CompletionCondition,
374 typename WriteHandler, typename Executor>
375 struct associated_executor<
376 detail::write_op<AsyncWriteStream, ConstBufferSequence,
377 ConstBufferIterator, CompletionCondition, WriteHandler>,
378 Executor>
379 {
380 typedef typename associated_executor<WriteHandler, Executor>::type type;
381
382 static type get(
383 const detail::write_op<AsyncWriteStream, ConstBufferSequence,
384 ConstBufferIterator, CompletionCondition, WriteHandler>& h,
385 const Executor& ex = Executor()) BOOST_ASIO_NOEXCEPT
386 {
387 return associated_executor<WriteHandler, Executor>::get(h.handler_, ex);
388 }
389 };
390
391 #endif // !defined(GENERATING_DOCUMENTATION)
392
393 template <typename AsyncWriteStream, typename ConstBufferSequence,
394 typename CompletionCondition, typename WriteHandler>
395 inline BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
396 void (boost::system::error_code, std::size_t))
397 async_write(AsyncWriteStream& s, const ConstBufferSequence& buffers,
398 CompletionCondition completion_condition,
399 BOOST_ASIO_MOVE_ARG(WriteHandler) handler,
400 typename enable_if<
401 is_const_buffer_sequence<ConstBufferSequence>::value
402 >::type*)
403 {
404 // If you get an error on the following line it means that your handler does
405 // not meet the documented type requirements for a WriteHandler.
406 BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
407
408 async_completion<WriteHandler,
409 void (boost::system::error_code, std::size_t)> init(handler);
410
411 detail::start_write_buffer_sequence_op(s, buffers,
412 boost::asio::buffer_sequence_begin(buffers), completion_condition,
413 init.completion_handler);
414
415 return init.result.get();
416 }
417
418 template <typename AsyncWriteStream, typename ConstBufferSequence,
419 typename WriteHandler>
420 inline BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
421 void (boost::system::error_code, std::size_t))
422 async_write(AsyncWriteStream& s, const ConstBufferSequence& buffers,
423 BOOST_ASIO_MOVE_ARG(WriteHandler) handler,
424 typename enable_if<
425 is_const_buffer_sequence<ConstBufferSequence>::value
426 >::type*)
427 {
428 // If you get an error on the following line it means that your handler does
429 // not meet the documented type requirements for a WriteHandler.
430 BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
431
432 async_completion<WriteHandler,
433 void (boost::system::error_code, std::size_t)> init(handler);
434
435 detail::start_write_buffer_sequence_op(s, buffers,
436 boost::asio::buffer_sequence_begin(buffers), transfer_all(),
437 init.completion_handler);
438
439 return init.result.get();
440 }
441
442 namespace detail
443 {
444 template <typename AsyncWriteStream, typename DynamicBuffer,
445 typename CompletionCondition, typename WriteHandler>
446 class write_dynbuf_op
447 {
448 public:
449 template <typename BufferSequence>
450 write_dynbuf_op(AsyncWriteStream& stream,
451 BOOST_ASIO_MOVE_ARG(BufferSequence) buffers,
452 CompletionCondition completion_condition, WriteHandler& handler)
453 : stream_(stream),
454 buffers_(BOOST_ASIO_MOVE_CAST(BufferSequence)(buffers)),
455 completion_condition_(
456 BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition)),
457 handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(handler))
458 {
459 }
460
461 #if defined(BOOST_ASIO_HAS_MOVE)
462 write_dynbuf_op(const write_dynbuf_op& other)
463 : stream_(other.stream_),
464 buffers_(other.buffers_),
465 completion_condition_(other.completion_condition_),
466 handler_(other.handler_)
467 {
468 }
469
470 write_dynbuf_op(write_dynbuf_op&& other)
471 : stream_(other.stream_),
472 buffers_(BOOST_ASIO_MOVE_CAST(DynamicBuffer)(other.buffers_)),
473 completion_condition_(
474 BOOST_ASIO_MOVE_CAST(CompletionCondition)(
475 other.completion_condition_)),
476 handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(other.handler_))
477 {
478 }
479 #endif // defined(BOOST_ASIO_HAS_MOVE)
480
481 void operator()(const boost::system::error_code& ec,
482 std::size_t bytes_transferred, int start = 0)
483 {
484 switch (start)
485 {
486 case 1:
487 async_write(stream_, buffers_.data(), completion_condition_,
488 BOOST_ASIO_MOVE_CAST(write_dynbuf_op)(*this));
489 return; default:
490 buffers_.consume(bytes_transferred);
491 handler_(ec, static_cast<const std::size_t&>(bytes_transferred));
492 }
493 }
494
495 //private:
496 AsyncWriteStream& stream_;
497 DynamicBuffer buffers_;
498 CompletionCondition completion_condition_;
499 WriteHandler handler_;
500 };
501
502 template <typename AsyncWriteStream, typename DynamicBuffer,
503 typename CompletionCondition, typename WriteHandler>
504 inline void* asio_handler_allocate(std::size_t size,
505 write_dynbuf_op<AsyncWriteStream, DynamicBuffer,
506 CompletionCondition, WriteHandler>* this_handler)
507 {
508 return boost_asio_handler_alloc_helpers::allocate(
509 size, this_handler->handler_);
510 }
511
512 template <typename AsyncWriteStream, typename DynamicBuffer,
513 typename CompletionCondition, typename WriteHandler>
514 inline void asio_handler_deallocate(void* pointer, std::size_t size,
515 write_dynbuf_op<AsyncWriteStream, DynamicBuffer,
516 CompletionCondition, WriteHandler>* this_handler)
517 {
518 boost_asio_handler_alloc_helpers::deallocate(
519 pointer, size, this_handler->handler_);
520 }
521
522 template <typename AsyncWriteStream, typename DynamicBuffer,
523 typename CompletionCondition, typename WriteHandler>
524 inline bool asio_handler_is_continuation(
525 write_dynbuf_op<AsyncWriteStream, DynamicBuffer,
526 CompletionCondition, WriteHandler>* this_handler)
527 {
528 return boost_asio_handler_cont_helpers::is_continuation(
529 this_handler->handler_);
530 }
531
532 template <typename Function, typename AsyncWriteStream,
533 typename DynamicBuffer, typename CompletionCondition,
534 typename WriteHandler>
535 inline void asio_handler_invoke(Function& function,
536 write_dynbuf_op<AsyncWriteStream, DynamicBuffer,
537 CompletionCondition, WriteHandler>* this_handler)
538 {
539 boost_asio_handler_invoke_helpers::invoke(
540 function, this_handler->handler_);
541 }
542
543 template <typename Function, typename AsyncWriteStream,
544 typename DynamicBuffer, typename CompletionCondition,
545 typename WriteHandler>
546 inline void asio_handler_invoke(const Function& function,
547 write_dynbuf_op<AsyncWriteStream, DynamicBuffer,
548 CompletionCondition, WriteHandler>* this_handler)
549 {
550 boost_asio_handler_invoke_helpers::invoke(
551 function, this_handler->handler_);
552 }
553 } // namespace detail
554
555 #if !defined(GENERATING_DOCUMENTATION)
556
557 template <typename AsyncWriteStream, typename DynamicBuffer,
558 typename CompletionCondition, typename WriteHandler, typename Allocator>
559 struct associated_allocator<
560 detail::write_dynbuf_op<AsyncWriteStream,
561 DynamicBuffer, CompletionCondition, WriteHandler>,
562 Allocator>
563 {
564 typedef typename associated_allocator<WriteHandler, Allocator>::type type;
565
566 static type get(
567 const detail::write_dynbuf_op<AsyncWriteStream,
568 DynamicBuffer, CompletionCondition, WriteHandler>& h,
569 const Allocator& a = Allocator()) BOOST_ASIO_NOEXCEPT
570 {
571 return associated_allocator<WriteHandler, Allocator>::get(h.handler_, a);
572 }
573 };
574
575 template <typename AsyncWriteStream, typename DynamicBuffer,
576 typename CompletionCondition, typename WriteHandler, typename Executor>
577 struct associated_executor<
578 detail::write_dynbuf_op<AsyncWriteStream,
579 DynamicBuffer, CompletionCondition, WriteHandler>,
580 Executor>
581 {
582 typedef typename associated_executor<WriteHandler, Executor>::type type;
583
584 static type get(
585 const detail::write_dynbuf_op<AsyncWriteStream,
586 DynamicBuffer, CompletionCondition, WriteHandler>& h,
587 const Executor& ex = Executor()) BOOST_ASIO_NOEXCEPT
588 {
589 return associated_executor<WriteHandler, Executor>::get(h.handler_, ex);
590 }
591 };
592
593 #endif // !defined(GENERATING_DOCUMENTATION)
594
595 template <typename AsyncWriteStream,
596 typename DynamicBuffer, typename WriteHandler>
597 inline BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
598 void (boost::system::error_code, std::size_t))
599 async_write(AsyncWriteStream& s,
600 BOOST_ASIO_MOVE_ARG(DynamicBuffer) buffers,
601 BOOST_ASIO_MOVE_ARG(WriteHandler) handler,
602 typename enable_if<
603 is_dynamic_buffer<DynamicBuffer>::value
604 >::type*)
605 {
606 return async_write(s,
607 BOOST_ASIO_MOVE_CAST(DynamicBuffer)(buffers),
608 transfer_all(), BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
609 }
610
611 template <typename AsyncWriteStream, typename DynamicBuffer,
612 typename CompletionCondition, typename WriteHandler>
613 inline BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
614 void (boost::system::error_code, std::size_t))
615 async_write(AsyncWriteStream& s,
616 BOOST_ASIO_MOVE_ARG(DynamicBuffer) buffers,
617 CompletionCondition completion_condition,
618 BOOST_ASIO_MOVE_ARG(WriteHandler) handler,
619 typename enable_if<
620 is_dynamic_buffer<DynamicBuffer>::value
621 >::type*)
622 {
623 // If you get an error on the following line it means that your handler does
624 // not meet the documented type requirements for a WriteHandler.
625 BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
626
627 async_completion<WriteHandler,
628 void (boost::system::error_code, std::size_t)> init(handler);
629
630 detail::write_dynbuf_op<AsyncWriteStream,
631 typename decay<DynamicBuffer>::type,
632 CompletionCondition, BOOST_ASIO_HANDLER_TYPE(
633 WriteHandler, void (boost::system::error_code, std::size_t))>(
634 s, BOOST_ASIO_MOVE_CAST(DynamicBuffer)(buffers),
635 completion_condition, init.completion_handler)(
636 boost::system::error_code(), 0, 1);
637
638 return init.result.get();
639 }
640
641 #if !defined(BOOST_ASIO_NO_EXTENSIONS)
642 #if !defined(BOOST_ASIO_NO_IOSTREAM)
643
644 template <typename AsyncWriteStream, typename Allocator, typename WriteHandler>
645 inline BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
646 void (boost::system::error_code, std::size_t))
647 async_write(AsyncWriteStream& s,
648 boost::asio::basic_streambuf<Allocator>& b,
649 BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
650 {
651 return async_write(s, basic_streambuf_ref<Allocator>(b),
652 BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
653 }
654
655 template <typename AsyncWriteStream, typename Allocator,
656 typename CompletionCondition, typename WriteHandler>
657 inline BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
658 void (boost::system::error_code, std::size_t))
659 async_write(AsyncWriteStream& s,
660 boost::asio::basic_streambuf<Allocator>& b,
661 CompletionCondition completion_condition,
662 BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
663 {
664 return async_write(s, basic_streambuf_ref<Allocator>(b),
665 completion_condition, BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));
666 }
667
668 #endif // !defined(BOOST_ASIO_NO_IOSTREAM)
669 #endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
670
671 } // namespace asio
672 } // namespace boost
673
674 #include <boost/asio/detail/pop_options.hpp>
675
676 #endif // BOOST_ASIO_IMPL_WRITE_HPP