1[/
2 / Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
3 /
4 / Distributed under the Boost Software License, Version 1.0. (See accompanying
5 / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 /]
7
8[section:WriteHandler Write handler requirements]
9
10A write handler must meet the requirements for a [link
11boost_asio.reference.Handler handler]. A value `h` of a write handler class
12should work correctly in the expression `h(ec, s)`, where `ec` is an lvalue of
13type `const error_code` and `s` is an lvalue of type `const size_t`.
14
15[heading Examples]
16
17A free function as a write handler:
18
19  void write_handler(
20      const boost::system::error_code& ec,
21      std::size_t bytes_transferred)
22  {
23    ...
24  }
25
26A write handler function object:
27
28  struct write_handler
29  {
30    ...
31    void operator()(
32        const boost::system::error_code& ec,
33        std::size_t bytes_transferred)
34    {
35      ...
36    }
37    ...
38  };
39
40A lambda as a write handler:
41
42  socket.async_write(...
43      [](const boost::system::error_code& ec,
44        std::size_t bytes_transferred)
45      {
46        ...
47      });
48
49A non-static class member function adapted to a write handler using
50`std::bind()`:
51
52  void my_class::write_handler(
53      const boost::system::error_code& ec,
54      std::size_t bytes_transferred)
55  {
56    ...
57  }
58  ...
59  socket.async_write(...,
60      std::bind(&my_class::write_handler,
61        this, std::placeholders::_1,
62        std::placeholders::_2));
63
64A non-static class member function adapted to a write handler using
65`boost::bind()`:
66
67  void my_class::write_handler(
68      const boost::system::error_code& ec,
69      std::size_t bytes_transferred)
70  {
71    ...
72  }
73  ...
74  socket.async_write(...,
75      boost::bind(&my_class::write_handler,
76        this, boost::asio::placeholders::error,
77        boost::asio::placeholders::bytes_transferred));
78
79[endsect]
80