 // Used as the handler for the async_write_some operation.
  void operator()(boost::system::error_code ec, std::size_t)
  {
    // Put the underlying socket into non-blocking mode.
    if (!ec)
      if (!sock_.native_non_blocking())
        sock_.native_non_blocking(true, ec);

    if (!ec)
    {
      for (;;)
      {
        // Try the system call.
        errno = 0;
        int n = ::sendfile(sock_.native_handle(), fd_, &amp;offset_, 65536);
        ec = boost::system::error_code(n &lt; 0 ? errno : 0,
