PageRenderTime 157ms CodeModel.GetById 15ms app.highlight 131ms RepoModel.GetById 2ms app.codeStats 1ms

/test/write.cpp

https://bitbucket.org/boostorg/asio
C++ | 3914 lines | 3466 code | 437 blank | 11 comment | 203 complexity | 46442eaafa875daa55ca7f61598e5a2f MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1//
   2// write.cpp
   3// ~~~~~~~~~
   4//
   5// Copyright (c) 2003-2016 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// Disable autolinking for unit tests.
  12#if !defined(BOOST_ALL_NO_LIB)
  13#define BOOST_ALL_NO_LIB 1
  14#endif // !defined(BOOST_ALL_NO_LIB)
  15
  16// Test that header file is self-contained.
  17#include <boost/asio/write.hpp>
  18
  19#include <cstring>
  20#include <vector>
  21#include "archetypes/async_result.hpp"
  22#include <boost/asio/io_service.hpp>
  23#include <boost/asio/streambuf.hpp>
  24#include "unit_test.hpp"
  25
  26#if defined(BOOST_ASIO_HAS_BOOST_BIND)
  27# include <boost/bind.hpp>
  28#else // defined(BOOST_ASIO_HAS_BOOST_BIND)
  29# include <functional>
  30#endif // defined(BOOST_ASIO_HAS_BOOST_BIND)
  31
  32#if defined(BOOST_ASIO_HAS_BOOST_ARRAY)
  33#include <boost/array.hpp>
  34#endif // defined(BOOST_ASIO_HAS_BOOST_ARRAY)
  35
  36#if defined(BOOST_ASIO_HAS_STD_ARRAY)
  37# include <array>
  38#endif // defined(BOOST_ASIO_HAS_STD_ARRAY)
  39
  40using namespace std; // For memcmp, memcpy and memset.
  41
  42class test_stream
  43{
  44public:
  45  typedef boost::asio::io_service io_service_type;
  46
  47  test_stream(boost::asio::io_service& io_service)
  48    : io_service_(io_service),
  49      length_(max_length),
  50      position_(0),
  51      next_write_length_(max_length)
  52  {
  53    memset(data_, 0, max_length);
  54  }
  55
  56  io_service_type& get_io_service()
  57  {
  58    return io_service_;
  59  }
  60
  61  void reset(size_t length = max_length)
  62  {
  63    BOOST_ASIO_CHECK(length <= max_length);
  64
  65    memset(data_, 0, max_length);
  66    length_ = length;
  67    position_ = 0;
  68    next_write_length_ = length;
  69  }
  70
  71  void next_write_length(size_t length)
  72  {
  73    next_write_length_ = length;
  74  }
  75
  76  template <typename Const_Buffers>
  77  bool check_buffers(const Const_Buffers& buffers, size_t length)
  78  {
  79    if (length != position_)
  80      return false;
  81
  82    typename Const_Buffers::const_iterator iter = buffers.begin();
  83    typename Const_Buffers::const_iterator end = buffers.end();
  84    size_t checked_length = 0;
  85    for (; iter != end && checked_length < length; ++iter)
  86    {
  87      size_t buffer_length = boost::asio::buffer_size(*iter);
  88      if (buffer_length > length - checked_length)
  89        buffer_length = length - checked_length;
  90      if (memcmp(data_ + checked_length,
  91            boost::asio::buffer_cast<const void*>(*iter), buffer_length) != 0)
  92        return false;
  93      checked_length += buffer_length;
  94    }
  95
  96    return true;
  97  }
  98
  99  template <typename Const_Buffers>
 100  size_t write_some(const Const_Buffers& buffers)
 101  {
 102    size_t n = boost::asio::buffer_copy(
 103        boost::asio::buffer(data_, length_) + position_,
 104        buffers, next_write_length_);
 105    position_ += n;
 106    return n;
 107  }
 108
 109  template <typename Const_Buffers>
 110  size_t write_some(const Const_Buffers& buffers, boost::system::error_code& ec)
 111  {
 112    ec = boost::system::error_code();
 113    return write_some(buffers);
 114  }
 115
 116  template <typename Const_Buffers, typename Handler>
 117  void async_write_some(const Const_Buffers& buffers, Handler handler)
 118  {
 119    size_t bytes_transferred = write_some(buffers);
 120    io_service_.post(boost::asio::detail::bind_handler(
 121          handler, boost::system::error_code(), bytes_transferred));
 122  }
 123
 124private:
 125  io_service_type& io_service_;
 126  enum { max_length = 8192 };
 127  char data_[max_length];
 128  size_t length_;
 129  size_t position_;
 130  size_t next_write_length_;
 131};
 132
 133static const char write_data[]
 134  = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
 135static char mutable_write_data[]
 136  = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
 137
 138void test_2_arg_zero_buffers_write()
 139{
 140  boost::asio::io_service ios;
 141  test_stream s(ios);
 142  std::vector<boost::asio::const_buffer> buffers;
 143
 144  size_t bytes_transferred = boost::asio::write(s, buffers);
 145  BOOST_ASIO_CHECK(bytes_transferred == 0);
 146}
 147
 148void test_2_arg_const_buffers_1_write()
 149{
 150  boost::asio::io_service ios;
 151  test_stream s(ios);
 152  boost::asio::const_buffers_1 buffers
 153    = boost::asio::buffer(write_data, sizeof(write_data));
 154
 155  s.reset();
 156  size_t bytes_transferred = boost::asio::write(s, buffers);
 157  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 158  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 159
 160  s.reset();
 161  s.next_write_length(1);
 162  bytes_transferred = boost::asio::write(s, buffers);
 163  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 164  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 165
 166  s.reset();
 167  s.next_write_length(10);
 168  bytes_transferred = boost::asio::write(s, buffers);
 169  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 170  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 171}
 172
 173void test_2_arg_mutable_buffers_1_write()
 174{
 175  boost::asio::io_service ios;
 176  test_stream s(ios);
 177  boost::asio::mutable_buffers_1 buffers
 178    = boost::asio::buffer(mutable_write_data, sizeof(mutable_write_data));
 179
 180  s.reset();
 181  size_t bytes_transferred = boost::asio::write(s, buffers);
 182  BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data));
 183  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(mutable_write_data)));
 184
 185  s.reset();
 186  s.next_write_length(1);
 187  bytes_transferred = boost::asio::write(s, buffers);
 188  BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data));
 189  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(mutable_write_data)));
 190
 191  s.reset();
 192  s.next_write_length(10);
 193  bytes_transferred = boost::asio::write(s, buffers);
 194  BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data));
 195  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(mutable_write_data)));
 196}
 197
 198void test_2_arg_vector_buffers_write()
 199{
 200  boost::asio::io_service ios;
 201  test_stream s(ios);
 202  std::vector<boost::asio::const_buffer> buffers;
 203  buffers.push_back(boost::asio::buffer(write_data, 32));
 204  buffers.push_back(boost::asio::buffer(write_data) + 32);
 205
 206  s.reset();
 207  size_t bytes_transferred = boost::asio::write(s, buffers);
 208  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 209  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 210
 211  s.reset();
 212  s.next_write_length(1);
 213  bytes_transferred = boost::asio::write(s, buffers);
 214  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 215  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 216
 217  s.reset();
 218  s.next_write_length(10);
 219  bytes_transferred = boost::asio::write(s, buffers);
 220  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 221  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 222}
 223
 224void test_3_arg_nothrow_zero_buffers_write()
 225{
 226  boost::asio::io_service ios;
 227  test_stream s(ios);
 228  std::vector<boost::asio::const_buffer> buffers;
 229
 230  boost::system::error_code error;
 231  size_t bytes_transferred = boost::asio::write(s, buffers, error);
 232  BOOST_ASIO_CHECK(bytes_transferred == 0);
 233  BOOST_ASIO_CHECK(!error);
 234}
 235
 236void test_3_arg_nothrow_const_buffers_1_write()
 237{
 238  boost::asio::io_service ios;
 239  test_stream s(ios);
 240  boost::asio::const_buffers_1 buffers
 241    = boost::asio::buffer(write_data, sizeof(write_data));
 242
 243  s.reset();
 244  boost::system::error_code error;
 245  size_t bytes_transferred = boost::asio::write(s, buffers, error);
 246  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 247  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 248  BOOST_ASIO_CHECK(!error);
 249
 250  s.reset();
 251  s.next_write_length(1);
 252  bytes_transferred = boost::asio::write(s, buffers, error);
 253  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 254  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 255  BOOST_ASIO_CHECK(!error);
 256
 257  s.reset();
 258  s.next_write_length(10);
 259  bytes_transferred = boost::asio::write(s, buffers, error);
 260  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 261  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 262  BOOST_ASIO_CHECK(!error);
 263}
 264
 265void test_3_arg_nothrow_mutable_buffers_1_write()
 266{
 267  boost::asio::io_service ios;
 268  test_stream s(ios);
 269  boost::asio::mutable_buffers_1 buffers
 270    = boost::asio::buffer(mutable_write_data, sizeof(mutable_write_data));
 271
 272  s.reset();
 273  boost::system::error_code error;
 274  size_t bytes_transferred = boost::asio::write(s, buffers, error);
 275  BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data));
 276  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(mutable_write_data)));
 277  BOOST_ASIO_CHECK(!error);
 278
 279  s.reset();
 280  s.next_write_length(1);
 281  bytes_transferred = boost::asio::write(s, buffers, error);
 282  BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data));
 283  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(mutable_write_data)));
 284  BOOST_ASIO_CHECK(!error);
 285
 286  s.reset();
 287  s.next_write_length(10);
 288  bytes_transferred = boost::asio::write(s, buffers, error);
 289  BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data));
 290  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(mutable_write_data)));
 291  BOOST_ASIO_CHECK(!error);
 292}
 293
 294void test_3_arg_nothrow_vector_buffers_write()
 295{
 296  boost::asio::io_service ios;
 297  test_stream s(ios);
 298  std::vector<boost::asio::const_buffer> buffers;
 299  buffers.push_back(boost::asio::buffer(write_data, 32));
 300  buffers.push_back(boost::asio::buffer(write_data) + 32);
 301
 302  s.reset();
 303  boost::system::error_code error;
 304  size_t bytes_transferred = boost::asio::write(s, buffers, error);
 305  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 306  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 307  BOOST_ASIO_CHECK(!error);
 308
 309  s.reset();
 310  s.next_write_length(1);
 311  bytes_transferred = boost::asio::write(s, buffers, error);
 312  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 313  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 314  BOOST_ASIO_CHECK(!error);
 315
 316  s.reset();
 317  s.next_write_length(10);
 318  bytes_transferred = boost::asio::write(s, buffers, error);
 319  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 320  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 321  BOOST_ASIO_CHECK(!error);
 322}
 323
 324bool old_style_transfer_all(const boost::system::error_code& ec,
 325    size_t /*bytes_transferred*/)
 326{
 327  return !!ec;
 328}
 329
 330size_t short_transfer(const boost::system::error_code& ec,
 331    size_t /*bytes_transferred*/)
 332{
 333  return !!ec ? 0 : 3;
 334}
 335
 336void test_3_arg_const_buffers_1_write()
 337{
 338  boost::asio::io_service ios;
 339  test_stream s(ios);
 340  boost::asio::const_buffers_1 buffers
 341    = boost::asio::buffer(write_data, sizeof(write_data));
 342
 343  s.reset();
 344  size_t bytes_transferred = boost::asio::write(s, buffers,
 345      boost::asio::transfer_all());
 346  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 347  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 348
 349  s.reset();
 350  s.next_write_length(1);
 351  bytes_transferred = boost::asio::write(s, buffers,
 352      boost::asio::transfer_all());
 353  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 354  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 355
 356  s.reset();
 357  s.next_write_length(10);
 358  bytes_transferred = boost::asio::write(s, buffers,
 359      boost::asio::transfer_all());
 360  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 361  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 362
 363  s.reset();
 364  bytes_transferred = boost::asio::write(s, buffers,
 365      boost::asio::transfer_at_least(1));
 366  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 367  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 368
 369  s.reset();
 370  s.next_write_length(1);
 371  bytes_transferred = boost::asio::write(s, buffers,
 372      boost::asio::transfer_at_least(1));
 373  BOOST_ASIO_CHECK(bytes_transferred == 1);
 374  BOOST_ASIO_CHECK(s.check_buffers(buffers, 1));
 375
 376  s.reset();
 377  s.next_write_length(10);
 378  bytes_transferred = boost::asio::write(s, buffers,
 379      boost::asio::transfer_at_least(1));
 380  BOOST_ASIO_CHECK(bytes_transferred == 10);
 381  BOOST_ASIO_CHECK(s.check_buffers(buffers, 10));
 382
 383  s.reset();
 384  bytes_transferred = boost::asio::write(s, buffers,
 385      boost::asio::transfer_at_least(10));
 386  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 387  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 388
 389  s.reset();
 390  s.next_write_length(1);
 391  bytes_transferred = boost::asio::write(s, buffers,
 392      boost::asio::transfer_at_least(10));
 393  BOOST_ASIO_CHECK(bytes_transferred == 10);
 394  BOOST_ASIO_CHECK(s.check_buffers(buffers, 10));
 395
 396  s.reset();
 397  s.next_write_length(10);
 398  bytes_transferred = boost::asio::write(s, buffers,
 399      boost::asio::transfer_at_least(10));
 400  BOOST_ASIO_CHECK(bytes_transferred == 10);
 401  BOOST_ASIO_CHECK(s.check_buffers(buffers, 10));
 402
 403  s.reset();
 404  bytes_transferred = boost::asio::write(s, buffers,
 405      boost::asio::transfer_at_least(42));
 406  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 407  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 408
 409  s.reset();
 410  s.next_write_length(1);
 411  bytes_transferred = boost::asio::write(s, buffers,
 412      boost::asio::transfer_at_least(42));
 413  BOOST_ASIO_CHECK(bytes_transferred == 42);
 414  BOOST_ASIO_CHECK(s.check_buffers(buffers, 42));
 415
 416  s.reset();
 417  s.next_write_length(10);
 418  bytes_transferred = boost::asio::write(s, buffers,
 419      boost::asio::transfer_at_least(42));
 420  BOOST_ASIO_CHECK(bytes_transferred == 50);
 421  BOOST_ASIO_CHECK(s.check_buffers(buffers, 50));
 422
 423  s.reset();
 424  bytes_transferred = boost::asio::write(s, buffers,
 425      boost::asio::transfer_exactly(1));
 426  BOOST_ASIO_CHECK(bytes_transferred == 1);
 427  BOOST_ASIO_CHECK(s.check_buffers(buffers, 1));
 428
 429  s.reset();
 430  s.next_write_length(1);
 431  bytes_transferred = boost::asio::write(s, buffers,
 432      boost::asio::transfer_exactly(1));
 433  BOOST_ASIO_CHECK(bytes_transferred == 1);
 434  BOOST_ASIO_CHECK(s.check_buffers(buffers, 1));
 435
 436  s.reset();
 437  s.next_write_length(10);
 438  bytes_transferred = boost::asio::write(s, buffers,
 439      boost::asio::transfer_exactly(1));
 440  BOOST_ASIO_CHECK(bytes_transferred == 1);
 441  BOOST_ASIO_CHECK(s.check_buffers(buffers, 1));
 442
 443  s.reset();
 444  bytes_transferred = boost::asio::write(s, buffers,
 445      boost::asio::transfer_exactly(10));
 446  BOOST_ASIO_CHECK(bytes_transferred == 10);
 447  BOOST_ASIO_CHECK(s.check_buffers(buffers, 10));
 448
 449  s.reset();
 450  s.next_write_length(1);
 451  bytes_transferred = boost::asio::write(s, buffers,
 452      boost::asio::transfer_exactly(10));
 453  BOOST_ASIO_CHECK(bytes_transferred == 10);
 454  BOOST_ASIO_CHECK(s.check_buffers(buffers, 10));
 455
 456  s.reset();
 457  s.next_write_length(10);
 458  bytes_transferred = boost::asio::write(s, buffers,
 459      boost::asio::transfer_exactly(10));
 460  BOOST_ASIO_CHECK(bytes_transferred == 10);
 461  BOOST_ASIO_CHECK(s.check_buffers(buffers, 10));
 462
 463  s.reset();
 464  bytes_transferred = boost::asio::write(s, buffers,
 465      boost::asio::transfer_exactly(42));
 466  BOOST_ASIO_CHECK(bytes_transferred == 42);
 467  BOOST_ASIO_CHECK(s.check_buffers(buffers, 42));
 468
 469  s.reset();
 470  s.next_write_length(1);
 471  bytes_transferred = boost::asio::write(s, buffers,
 472      boost::asio::transfer_exactly(42));
 473  BOOST_ASIO_CHECK(bytes_transferred == 42);
 474  BOOST_ASIO_CHECK(s.check_buffers(buffers, 42));
 475
 476  s.reset();
 477  s.next_write_length(10);
 478  bytes_transferred = boost::asio::write(s, buffers,
 479      boost::asio::transfer_exactly(42));
 480  BOOST_ASIO_CHECK(bytes_transferred == 42);
 481  BOOST_ASIO_CHECK(s.check_buffers(buffers, 42));
 482
 483  s.reset();
 484  bytes_transferred = boost::asio::write(s, buffers, old_style_transfer_all);
 485  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 486  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 487
 488  s.reset();
 489  s.next_write_length(1);
 490  bytes_transferred = boost::asio::write(s, buffers, old_style_transfer_all);
 491  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 492  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 493
 494  s.reset();
 495  s.next_write_length(10);
 496  bytes_transferred = boost::asio::write(s, buffers, old_style_transfer_all);
 497  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 498  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 499
 500  s.reset();
 501  bytes_transferred = boost::asio::write(s, buffers, short_transfer);
 502  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 503  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 504
 505  s.reset();
 506  s.next_write_length(1);
 507  bytes_transferred = boost::asio::write(s, buffers, short_transfer);
 508  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 509  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 510
 511  s.reset();
 512  s.next_write_length(10);
 513  bytes_transferred = boost::asio::write(s, buffers, short_transfer);
 514  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 515  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 516}
 517
 518void test_3_arg_mutable_buffers_1_write()
 519{
 520  boost::asio::io_service ios;
 521  test_stream s(ios);
 522  boost::asio::mutable_buffers_1 buffers
 523    = boost::asio::buffer(mutable_write_data, sizeof(mutable_write_data));
 524
 525  s.reset();
 526  size_t bytes_transferred = boost::asio::write(s, buffers,
 527      boost::asio::transfer_all());
 528  BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data));
 529  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(mutable_write_data)));
 530
 531  s.reset();
 532  s.next_write_length(1);
 533  bytes_transferred = boost::asio::write(s, buffers,
 534      boost::asio::transfer_all());
 535  BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data));
 536  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(mutable_write_data)));
 537
 538  s.reset();
 539  s.next_write_length(10);
 540  bytes_transferred = boost::asio::write(s, buffers,
 541      boost::asio::transfer_all());
 542  BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data));
 543  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(mutable_write_data)));
 544
 545  s.reset();
 546  bytes_transferred = boost::asio::write(s, buffers,
 547      boost::asio::transfer_at_least(1));
 548  BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data));
 549  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(mutable_write_data)));
 550
 551  s.reset();
 552  s.next_write_length(1);
 553  bytes_transferred = boost::asio::write(s, buffers,
 554      boost::asio::transfer_at_least(1));
 555  BOOST_ASIO_CHECK(bytes_transferred == 1);
 556  BOOST_ASIO_CHECK(s.check_buffers(buffers, 1));
 557
 558  s.reset();
 559  s.next_write_length(10);
 560  bytes_transferred = boost::asio::write(s, buffers,
 561      boost::asio::transfer_at_least(1));
 562  BOOST_ASIO_CHECK(bytes_transferred == 10);
 563  BOOST_ASIO_CHECK(s.check_buffers(buffers, 10));
 564
 565  s.reset();
 566  bytes_transferred = boost::asio::write(s, buffers,
 567      boost::asio::transfer_at_least(10));
 568  BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data));
 569  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(mutable_write_data)));
 570
 571  s.reset();
 572  s.next_write_length(1);
 573  bytes_transferred = boost::asio::write(s, buffers,
 574      boost::asio::transfer_at_least(10));
 575  BOOST_ASIO_CHECK(bytes_transferred == 10);
 576  BOOST_ASIO_CHECK(s.check_buffers(buffers, 10));
 577
 578  s.reset();
 579  s.next_write_length(10);
 580  bytes_transferred = boost::asio::write(s, buffers,
 581      boost::asio::transfer_at_least(10));
 582  BOOST_ASIO_CHECK(bytes_transferred == 10);
 583  BOOST_ASIO_CHECK(s.check_buffers(buffers, 10));
 584
 585  s.reset();
 586  bytes_transferred = boost::asio::write(s, buffers,
 587      boost::asio::transfer_at_least(42));
 588  BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data));
 589  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(mutable_write_data)));
 590
 591  s.reset();
 592  s.next_write_length(1);
 593  bytes_transferred = boost::asio::write(s, buffers,
 594      boost::asio::transfer_at_least(42));
 595  BOOST_ASIO_CHECK(bytes_transferred == 42);
 596  BOOST_ASIO_CHECK(s.check_buffers(buffers, 42));
 597
 598  s.reset();
 599  s.next_write_length(10);
 600  bytes_transferred = boost::asio::write(s, buffers,
 601      boost::asio::transfer_at_least(42));
 602  BOOST_ASIO_CHECK(bytes_transferred == 50);
 603  BOOST_ASIO_CHECK(s.check_buffers(buffers, 50));
 604
 605  s.reset();
 606  bytes_transferred = boost::asio::write(s, buffers,
 607      boost::asio::transfer_exactly(1));
 608  BOOST_ASIO_CHECK(bytes_transferred == 1);
 609  BOOST_ASIO_CHECK(s.check_buffers(buffers, 1));
 610
 611  s.reset();
 612  s.next_write_length(1);
 613  bytes_transferred = boost::asio::write(s, buffers,
 614      boost::asio::transfer_exactly(1));
 615  BOOST_ASIO_CHECK(bytes_transferred == 1);
 616  BOOST_ASIO_CHECK(s.check_buffers(buffers, 1));
 617
 618  s.reset();
 619  s.next_write_length(10);
 620  bytes_transferred = boost::asio::write(s, buffers,
 621      boost::asio::transfer_exactly(1));
 622  BOOST_ASIO_CHECK(bytes_transferred == 1);
 623  BOOST_ASIO_CHECK(s.check_buffers(buffers, 1));
 624
 625  s.reset();
 626  bytes_transferred = boost::asio::write(s, buffers,
 627      boost::asio::transfer_exactly(10));
 628  BOOST_ASIO_CHECK(bytes_transferred == 10);
 629  BOOST_ASIO_CHECK(s.check_buffers(buffers, 10));
 630
 631  s.reset();
 632  s.next_write_length(1);
 633  bytes_transferred = boost::asio::write(s, buffers,
 634      boost::asio::transfer_exactly(10));
 635  BOOST_ASIO_CHECK(bytes_transferred == 10);
 636  BOOST_ASIO_CHECK(s.check_buffers(buffers, 10));
 637
 638  s.reset();
 639  s.next_write_length(10);
 640  bytes_transferred = boost::asio::write(s, buffers,
 641      boost::asio::transfer_exactly(10));
 642  BOOST_ASIO_CHECK(bytes_transferred == 10);
 643  BOOST_ASIO_CHECK(s.check_buffers(buffers, 10));
 644
 645  s.reset();
 646  bytes_transferred = boost::asio::write(s, buffers,
 647      boost::asio::transfer_exactly(42));
 648  BOOST_ASIO_CHECK(bytes_transferred == 42);
 649  BOOST_ASIO_CHECK(s.check_buffers(buffers, 42));
 650
 651  s.reset();
 652  s.next_write_length(1);
 653  bytes_transferred = boost::asio::write(s, buffers,
 654      boost::asio::transfer_exactly(42));
 655  BOOST_ASIO_CHECK(bytes_transferred == 42);
 656  BOOST_ASIO_CHECK(s.check_buffers(buffers, 42));
 657
 658  s.reset();
 659  s.next_write_length(10);
 660  bytes_transferred = boost::asio::write(s, buffers,
 661      boost::asio::transfer_exactly(42));
 662  BOOST_ASIO_CHECK(bytes_transferred == 42);
 663  BOOST_ASIO_CHECK(s.check_buffers(buffers, 42));
 664
 665  s.reset();
 666  bytes_transferred = boost::asio::write(s, buffers, old_style_transfer_all);
 667  BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data));
 668  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(mutable_write_data)));
 669
 670  s.reset();
 671  s.next_write_length(1);
 672  bytes_transferred = boost::asio::write(s, buffers, old_style_transfer_all);
 673  BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data));
 674  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(mutable_write_data)));
 675
 676  s.reset();
 677  s.next_write_length(10);
 678  bytes_transferred = boost::asio::write(s, buffers, old_style_transfer_all);
 679  BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data));
 680  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(mutable_write_data)));
 681
 682  s.reset();
 683  bytes_transferred = boost::asio::write(s, buffers, short_transfer);
 684  BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data));
 685  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(mutable_write_data)));
 686
 687  s.reset();
 688  s.next_write_length(1);
 689  bytes_transferred = boost::asio::write(s, buffers, short_transfer);
 690  BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data));
 691  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(mutable_write_data)));
 692
 693  s.reset();
 694  s.next_write_length(10);
 695  bytes_transferred = boost::asio::write(s, buffers, short_transfer);
 696  BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data));
 697  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(mutable_write_data)));
 698}
 699
 700void test_3_arg_vector_buffers_write()
 701{
 702  boost::asio::io_service ios;
 703  test_stream s(ios);
 704  std::vector<boost::asio::const_buffer> buffers;
 705  buffers.push_back(boost::asio::buffer(write_data, 32));
 706  buffers.push_back(boost::asio::buffer(write_data) + 32);
 707
 708  s.reset();
 709  size_t bytes_transferred = boost::asio::write(s, buffers,
 710      boost::asio::transfer_all());
 711  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 712  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 713
 714  s.reset();
 715  s.next_write_length(1);
 716  bytes_transferred = boost::asio::write(s, buffers,
 717      boost::asio::transfer_all());
 718  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 719  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 720
 721  s.reset();
 722  s.next_write_length(10);
 723  bytes_transferred = boost::asio::write(s, buffers,
 724      boost::asio::transfer_all());
 725  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 726  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 727
 728  s.reset();
 729  bytes_transferred = boost::asio::write(s, buffers,
 730      boost::asio::transfer_at_least(1));
 731  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 732  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 733
 734  s.reset();
 735  s.next_write_length(1);
 736  bytes_transferred = boost::asio::write(s, buffers,
 737      boost::asio::transfer_at_least(1));
 738  BOOST_ASIO_CHECK(bytes_transferred == 1);
 739  BOOST_ASIO_CHECK(s.check_buffers(buffers, 1));
 740
 741  s.reset();
 742  s.next_write_length(10);
 743  bytes_transferred = boost::asio::write(s, buffers,
 744      boost::asio::transfer_at_least(1));
 745  BOOST_ASIO_CHECK(bytes_transferred == 10);
 746  BOOST_ASIO_CHECK(s.check_buffers(buffers, 10));
 747
 748  s.reset();
 749  bytes_transferred = boost::asio::write(s, buffers,
 750      boost::asio::transfer_at_least(10));
 751  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 752  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 753
 754  s.reset();
 755  s.next_write_length(1);
 756  bytes_transferred = boost::asio::write(s, buffers,
 757      boost::asio::transfer_at_least(10));
 758  BOOST_ASIO_CHECK(bytes_transferred == 10);
 759  BOOST_ASIO_CHECK(s.check_buffers(buffers, 10));
 760
 761  s.reset();
 762  s.next_write_length(10);
 763  bytes_transferred = boost::asio::write(s, buffers,
 764      boost::asio::transfer_at_least(10));
 765  BOOST_ASIO_CHECK(bytes_transferred == 10);
 766  BOOST_ASIO_CHECK(s.check_buffers(buffers, 10));
 767
 768  s.reset();
 769  bytes_transferred = boost::asio::write(s, buffers,
 770      boost::asio::transfer_at_least(42));
 771  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 772  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 773
 774  s.reset();
 775  s.next_write_length(1);
 776  bytes_transferred = boost::asio::write(s, buffers,
 777      boost::asio::transfer_at_least(42));
 778  BOOST_ASIO_CHECK(bytes_transferred == 42);
 779  BOOST_ASIO_CHECK(s.check_buffers(buffers, 42));
 780
 781  s.reset();
 782  s.next_write_length(10);
 783  bytes_transferred = boost::asio::write(s, buffers,
 784      boost::asio::transfer_at_least(42));
 785  BOOST_ASIO_CHECK(bytes_transferred == 50);
 786  BOOST_ASIO_CHECK(s.check_buffers(buffers, 50));
 787
 788  s.reset();
 789  bytes_transferred = boost::asio::write(s, buffers,
 790      boost::asio::transfer_exactly(1));
 791  BOOST_ASIO_CHECK(bytes_transferred == 1);
 792  BOOST_ASIO_CHECK(s.check_buffers(buffers, 1));
 793
 794  s.reset();
 795  s.next_write_length(1);
 796  bytes_transferred = boost::asio::write(s, buffers,
 797      boost::asio::transfer_exactly(1));
 798  BOOST_ASIO_CHECK(bytes_transferred == 1);
 799  BOOST_ASIO_CHECK(s.check_buffers(buffers, 1));
 800
 801  s.reset();
 802  s.next_write_length(10);
 803  bytes_transferred = boost::asio::write(s, buffers,
 804      boost::asio::transfer_exactly(1));
 805  BOOST_ASIO_CHECK(bytes_transferred == 1);
 806  BOOST_ASIO_CHECK(s.check_buffers(buffers, 1));
 807
 808  s.reset();
 809  bytes_transferred = boost::asio::write(s, buffers,
 810      boost::asio::transfer_exactly(10));
 811  BOOST_ASIO_CHECK(bytes_transferred == 10);
 812  BOOST_ASIO_CHECK(s.check_buffers(buffers, 10));
 813
 814  s.reset();
 815  s.next_write_length(1);
 816  bytes_transferred = boost::asio::write(s, buffers,
 817      boost::asio::transfer_exactly(10));
 818  BOOST_ASIO_CHECK(bytes_transferred == 10);
 819  BOOST_ASIO_CHECK(s.check_buffers(buffers, 10));
 820
 821  s.reset();
 822  s.next_write_length(10);
 823  bytes_transferred = boost::asio::write(s, buffers,
 824      boost::asio::transfer_exactly(10));
 825  BOOST_ASIO_CHECK(bytes_transferred == 10);
 826  BOOST_ASIO_CHECK(s.check_buffers(buffers, 10));
 827
 828  s.reset();
 829  bytes_transferred = boost::asio::write(s, buffers,
 830      boost::asio::transfer_exactly(42));
 831  BOOST_ASIO_CHECK(bytes_transferred == 42);
 832  BOOST_ASIO_CHECK(s.check_buffers(buffers, 42));
 833
 834  s.reset();
 835  s.next_write_length(1);
 836  bytes_transferred = boost::asio::write(s, buffers,
 837      boost::asio::transfer_exactly(42));
 838  BOOST_ASIO_CHECK(bytes_transferred == 42);
 839  BOOST_ASIO_CHECK(s.check_buffers(buffers, 42));
 840
 841  s.reset();
 842  s.next_write_length(10);
 843  bytes_transferred = boost::asio::write(s, buffers,
 844      boost::asio::transfer_exactly(42));
 845  BOOST_ASIO_CHECK(bytes_transferred == 42);
 846  BOOST_ASIO_CHECK(s.check_buffers(buffers, 42));
 847
 848  s.reset();
 849  bytes_transferred = boost::asio::write(s, buffers, old_style_transfer_all);
 850  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 851  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 852
 853  s.reset();
 854  s.next_write_length(1);
 855  bytes_transferred = boost::asio::write(s, buffers, old_style_transfer_all);
 856  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 857  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 858
 859  s.reset();
 860  s.next_write_length(10);
 861  bytes_transferred = boost::asio::write(s, buffers, old_style_transfer_all);
 862  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 863  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 864
 865  s.reset();
 866  bytes_transferred = boost::asio::write(s, buffers, short_transfer);
 867  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 868  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 869
 870  s.reset();
 871  s.next_write_length(1);
 872  bytes_transferred = boost::asio::write(s, buffers, short_transfer);
 873  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 874  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 875
 876  s.reset();
 877  s.next_write_length(10);
 878  bytes_transferred = boost::asio::write(s, buffers, short_transfer);
 879  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 880  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 881}
 882
 883void test_4_arg_const_buffers_1_write()
 884{
 885  boost::asio::io_service ios;
 886  test_stream s(ios);
 887  boost::asio::const_buffers_1 buffers
 888    = boost::asio::buffer(write_data, sizeof(write_data));
 889
 890  s.reset();
 891  boost::system::error_code error;
 892  size_t bytes_transferred = boost::asio::write(s, buffers,
 893      boost::asio::transfer_all(), error);
 894  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 895  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 896  BOOST_ASIO_CHECK(!error);
 897
 898  s.reset();
 899  s.next_write_length(1);
 900  error = boost::system::error_code();
 901  bytes_transferred = boost::asio::write(s, buffers,
 902      boost::asio::transfer_all(), error);
 903  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 904  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 905  BOOST_ASIO_CHECK(!error);
 906
 907  s.reset();
 908  s.next_write_length(10);
 909  error = boost::system::error_code();
 910  bytes_transferred = boost::asio::write(s, buffers,
 911      boost::asio::transfer_all(), error);
 912  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 913  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 914  BOOST_ASIO_CHECK(!error);
 915
 916  s.reset();
 917  error = boost::system::error_code();
 918  bytes_transferred = boost::asio::write(s, buffers,
 919      boost::asio::transfer_at_least(1), error);
 920  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 921  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 922  BOOST_ASIO_CHECK(!error);
 923
 924  s.reset();
 925  s.next_write_length(1);
 926  error = boost::system::error_code();
 927  bytes_transferred = boost::asio::write(s, buffers,
 928      boost::asio::transfer_at_least(1), error);
 929  BOOST_ASIO_CHECK(bytes_transferred == 1);
 930  BOOST_ASIO_CHECK(s.check_buffers(buffers, 1));
 931  BOOST_ASIO_CHECK(!error);
 932
 933  s.reset();
 934  s.next_write_length(10);
 935  error = boost::system::error_code();
 936  bytes_transferred = boost::asio::write(s, buffers,
 937      boost::asio::transfer_at_least(1), error);
 938  BOOST_ASIO_CHECK(bytes_transferred == 10);
 939  BOOST_ASIO_CHECK(s.check_buffers(buffers, 10));
 940  BOOST_ASIO_CHECK(!error);
 941
 942  s.reset();
 943  error = boost::system::error_code();
 944  bytes_transferred = boost::asio::write(s, buffers,
 945      boost::asio::transfer_at_least(10), error);
 946  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 947  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 948  BOOST_ASIO_CHECK(!error);
 949
 950  s.reset();
 951  s.next_write_length(1);
 952  error = boost::system::error_code();
 953  bytes_transferred = boost::asio::write(s, buffers,
 954      boost::asio::transfer_at_least(10), error);
 955  BOOST_ASIO_CHECK(bytes_transferred == 10);
 956  BOOST_ASIO_CHECK(s.check_buffers(buffers, 10));
 957  BOOST_ASIO_CHECK(!error);
 958
 959  s.reset();
 960  s.next_write_length(10);
 961  error = boost::system::error_code();
 962  bytes_transferred = boost::asio::write(s, buffers,
 963      boost::asio::transfer_at_least(10), error);
 964  BOOST_ASIO_CHECK(bytes_transferred == 10);
 965  BOOST_ASIO_CHECK(s.check_buffers(buffers, 10));
 966  BOOST_ASIO_CHECK(!error);
 967
 968  s.reset();
 969  error = boost::system::error_code();
 970  bytes_transferred = boost::asio::write(s, buffers,
 971      boost::asio::transfer_at_least(42), error);
 972  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
 973  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
 974  BOOST_ASIO_CHECK(!error);
 975
 976  s.reset();
 977  s.next_write_length(1);
 978  error = boost::system::error_code();
 979  bytes_transferred = boost::asio::write(s, buffers,
 980      boost::asio::transfer_at_least(42), error);
 981  BOOST_ASIO_CHECK(bytes_transferred == 42);
 982  BOOST_ASIO_CHECK(s.check_buffers(buffers, 42));
 983  BOOST_ASIO_CHECK(!error);
 984
 985  s.reset();
 986  s.next_write_length(10);
 987  error = boost::system::error_code();
 988  bytes_transferred = boost::asio::write(s, buffers,
 989      boost::asio::transfer_at_least(42), error);
 990  BOOST_ASIO_CHECK(bytes_transferred == 50);
 991  BOOST_ASIO_CHECK(s.check_buffers(buffers, 50));
 992  BOOST_ASIO_CHECK(!error);
 993
 994  s.reset();
 995  error = boost::system::error_code();
 996  bytes_transferred = boost::asio::write(s, buffers,
 997      boost::asio::transfer_exactly(1), error);
 998  BOOST_ASIO_CHECK(bytes_transferred == 1);
 999  BOOST_ASIO_CHECK(s.check_buffers(buffers, 1));
1000  BOOST_ASIO_CHECK(!error);
1001
1002  s.reset();
1003  s.next_write_length(1);
1004  error = boost::system::error_code();
1005  bytes_transferred = boost::asio::write(s, buffers,
1006      boost::asio::transfer_exactly(1), error);
1007  BOOST_ASIO_CHECK(bytes_transferred == 1);
1008  BOOST_ASIO_CHECK(s.check_buffers(buffers, 1));
1009  BOOST_ASIO_CHECK(!error);
1010
1011  s.reset();
1012  s.next_write_length(10);
1013  error = boost::system::error_code();
1014  bytes_transferred = boost::asio::write(s, buffers,
1015      boost::asio::transfer_exactly(1), error);
1016  BOOST_ASIO_CHECK(bytes_transferred == 1);
1017  BOOST_ASIO_CHECK(s.check_buffers(buffers, 1));
1018  BOOST_ASIO_CHECK(!error);
1019
1020  s.reset();
1021  error = boost::system::error_code();
1022  bytes_transferred = boost::asio::write(s, buffers,
1023      boost::asio::transfer_exactly(10), error);
1024  BOOST_ASIO_CHECK(bytes_transferred == 10);
1025  BOOST_ASIO_CHECK(s.check_buffers(buffers, 10));
1026  BOOST_ASIO_CHECK(!error);
1027
1028  s.reset();
1029  s.next_write_length(1);
1030  error = boost::system::error_code();
1031  bytes_transferred = boost::asio::write(s, buffers,
1032      boost::asio::transfer_exactly(10), error);
1033  BOOST_ASIO_CHECK(bytes_transferred == 10);
1034  BOOST_ASIO_CHECK(s.check_buffers(buffers, 10));
1035  BOOST_ASIO_CHECK(!error);
1036
1037  s.reset();
1038  s.next_write_length(10);
1039  error = boost::system::error_code();
1040  bytes_transferred = boost::asio::write(s, buffers,
1041      boost::asio::transfer_exactly(10), error);
1042  BOOST_ASIO_CHECK(bytes_transferred == 10);
1043  BOOST_ASIO_CHECK(s.check_buffers(buffers, 10));
1044  BOOST_ASIO_CHECK(!error);
1045
1046  s.reset();
1047  error = boost::system::error_code();
1048  bytes_transferred = boost::asio::write(s, buffers,
1049      boost::asio::transfer_exactly(42), error);
1050  BOOST_ASIO_CHECK(bytes_transferred == 42);
1051  BOOST_ASIO_CHECK(s.check_buffers(buffers, 42));
1052  BOOST_ASIO_CHECK(!error);
1053
1054  s.reset();
1055  s.next_write_length(1);
1056  error = boost::system::error_code();
1057  bytes_transferred = boost::asio::write(s, buffers,
1058      boost::asio::transfer_exactly(42), error);
1059  BOOST_ASIO_CHECK(bytes_transferred == 42);
1060  BOOST_ASIO_CHECK(s.check_buffers(buffers, 42));
1061  BOOST_ASIO_CHECK(!error);
1062
1063  s.reset();
1064  s.next_write_length(10);
1065  error = boost::system::error_code();
1066  bytes_transferred = boost::asio::write(s, buffers,
1067      boost::asio::transfer_exactly(42), error);
1068  BOOST_ASIO_CHECK(bytes_transferred == 42);
1069  BOOST_ASIO_CHECK(s.check_buffers(buffers, 42));
1070  BOOST_ASIO_CHECK(!error);
1071
1072  s.reset();
1073  bytes_transferred = boost::asio::write(s, buffers,
1074      old_style_transfer_all, error);
1075  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
1076  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
1077  BOOST_ASIO_CHECK(!error);
1078
1079  s.reset();
1080  s.next_write_length(1);
1081  error = boost::system::error_code();
1082  bytes_transferred = boost::asio::write(s, buffers,
1083      old_style_transfer_all, error);
1084  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
1085  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
1086  BOOST_ASIO_CHECK(!error);
1087
1088  s.reset();
1089  s.next_write_length(10);
1090  error = boost::system::error_code();
1091  bytes_transferred = boost::asio::write(s, buffers,
1092      old_style_transfer_all, error);
1093  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
1094  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
1095  BOOST_ASIO_CHECK(!error);
1096
1097  s.reset();
1098  bytes_transferred = boost::asio::write(s, buffers, short_transfer, error);
1099  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
1100  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
1101  BOOST_ASIO_CHECK(!error);
1102
1103  s.reset();
1104  s.next_write_length(1);
1105  error = boost::system::error_code();
1106  bytes_transferred = boost::asio::write(s, buffers, short_transfer, error);
1107  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
1108  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
1109  BOOST_ASIO_CHECK(!error);
1110
1111  s.reset();
1112  s.next_write_length(10);
1113  error = boost::system::error_code();
1114  bytes_transferred = boost::asio::write(s, buffers, short_transfer, error);
1115  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
1116  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
1117  BOOST_ASIO_CHECK(!error);
1118}
1119
1120void test_4_arg_mutable_buffers_1_write()
1121{
1122  boost::asio::io_service ios;
1123  test_stream s(ios);
1124  boost::asio::mutable_buffers_1 buffers
1125    = boost::asio::buffer(mutable_write_data, sizeof(mutable_write_data));
1126
1127  s.reset();
1128  boost::system::error_code error;
1129  size_t bytes_transferred = boost::asio::write(s, buffers,
1130      boost::asio::transfer_all(), error);
1131  BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data));
1132  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(mutable_write_data)));
1133  BOOST_ASIO_CHECK(!error);
1134
1135  s.reset();
1136  s.next_write_length(1);
1137  error = boost::system::error_code();
1138  bytes_transferred = boost::asio::write(s, buffers,
1139      boost::asio::transfer_all(), error);
1140  BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data));
1141  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(mutable_write_data)));
1142  BOOST_ASIO_CHECK(!error);
1143
1144  s.reset();
1145  s.next_write_length(10);
1146  error = boost::system::error_code();
1147  bytes_transferred = boost::asio::write(s, buffers,
1148      boost::asio::transfer_all(), error);
1149  BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data));
1150  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(mutable_write_data)));
1151  BOOST_ASIO_CHECK(!error);
1152
1153  s.reset();
1154  error = boost::system::error_code();
1155  bytes_transferred = boost::asio::write(s, buffers,
1156      boost::asio::transfer_at_least(1), error);
1157  BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data));
1158  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(mutable_write_data)));
1159  BOOST_ASIO_CHECK(!error);
1160
1161  s.reset();
1162  s.next_write_length(1);
1163  error = boost::system::error_code();
1164  bytes_transferred = boost::asio::write(s, buffers,
1165      boost::asio::transfer_at_least(1), error);
1166  BOOST_ASIO_CHECK(bytes_transferred == 1);
1167  BOOST_ASIO_CHECK(s.check_buffers(buffers, 1));
1168  BOOST_ASIO_CHECK(!error);
1169
1170  s.reset();
1171  s.next_write_length(10);
1172  error = boost::system::error_code();
1173  bytes_transferred = boost::asio::write(s, buffers,
1174      boost::asio::transfer_at_least(1), error);
1175  BOOST_ASIO_CHECK(bytes_transferred == 10);
1176  BOOST_ASIO_CHECK(s.check_buffers(buffers, 10));
1177  BOOST_ASIO_CHECK(!error);
1178
1179  s.reset();
1180  error = boost::system::error_code();
1181  bytes_transferred = boost::asio::write(s, buffers,
1182      boost::asio::transfer_at_least(10), error);
1183  BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data));
1184  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(mutable_write_data)));
1185  BOOST_ASIO_CHECK(!error);
1186
1187  s.reset();
1188  s.next_write_length(1);
1189  error = boost::system::error_code();
1190  bytes_transferred = boost::asio::write(s, buffers,
1191      boost::asio::transfer_at_least(10), error);
1192  BOOST_ASIO_CHECK(bytes_transferred == 10);
1193  BOOST_ASIO_CHECK(s.check_buffers(buffers, 10));
1194  BOOST_ASIO_CHECK(!error);
1195
1196  s.reset();
1197  s.next_write_length(10);
1198  error = boost::system::error_code();
1199  bytes_transferred = boost::asio::write(s, buffers,
1200      boost::asio::transfer_at_least(10), error);
1201  BOOST_ASIO_CHECK(bytes_transferred == 10);
1202  BOOST_ASIO_CHECK(s.check_buffers(buffers, 10));
1203  BOOST_ASIO_CHECK(!error);
1204
1205  s.reset();
1206  error = boost::system::error_code();
1207  bytes_transferred = boost::asio::write(s, buffers,
1208      boost::asio::transfer_at_least(42), error);
1209  BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data));
1210  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(mutable_write_data)));
1211  BOOST_ASIO_CHECK(!error);
1212
1213  s.reset();
1214  s.next_write_length(1);
1215  error = boost::system::error_code();
1216  bytes_transferred = boost::asio::write(s, buffers,
1217      boost::asio::transfer_at_least(42), error);
1218  BOOST_ASIO_CHECK(bytes_transferred == 42);
1219  BOOST_ASIO_CHECK(s.check_buffers(buffers, 42));
1220  BOOST_ASIO_CHECK(!error);
1221
1222  s.reset();
1223  s.next_write_length(10);
1224  error = boost::system::error_code();
1225  bytes_transferred = boost::asio::write(s, buffers,
1226      boost::asio::transfer_at_least(42), error);
1227  BOOST_ASIO_CHECK(bytes_transferred == 50);
1228  BOOST_ASIO_CHECK(s.check_buffers(buffers, 50));
1229  BOOST_ASIO_CHECK(!error);
1230
1231  s.reset();
1232  error = boost::system::error_code();
1233  bytes_transferred = boost::asio::write(s, buffers,
1234      boost::asio::transfer_exactly(1), error);
1235  BOOST_ASIO_CHECK(bytes_transferred == 1);
1236  BOOST_ASIO_CHECK(s.check_buffers(buffers, 1));
1237  BOOST_ASIO_CHECK(!error);
1238
1239  s.reset();
1240  s.next_write_length(1);
1241  error = boost::system::error_code();
1242  bytes_transferred = boost::asio::write(s, buffers,
1243      boost::asio::transfer_exactly(1), error);
1244  BOOST_ASIO_CHECK(bytes_transferred == 1);
1245  BOOST_ASIO_CHECK(s.check_buffers(buffers, 1));
1246  BOOST_ASIO_CHECK(!error);
1247
1248  s.reset();
1249  s.next_write_length(10);
1250  error = boost::system::error_code();
1251  bytes_transferred = boost::asio::write(s, buffers,
1252      boost::asio::transfer_exactly(1), error);
1253  BOOST_ASIO_CHECK(bytes_transferred == 1);
1254  BOOST_ASIO_CHECK(s.check_buffers(buffers, 1));
1255  BOOST_ASIO_CHECK(!error);
1256
1257  s.reset();
1258  error = boost::system::error_code();
1259  bytes_transferred = boost::asio::write(s, buffers,
1260      boost::asio::transfer_exactly(10), error);
1261  BOOST_ASIO_CHECK(bytes_transferred == 10);
1262  BOOST_ASIO_CHECK(s.check_buffers(buffers, 10));
1263  BOOST_ASIO_CHECK(!error);
1264
1265  s.reset();
1266  s.next_write_length(1);
1267  error = boost::system::error_code();
1268  bytes_transferred = boost::asio::write(s, buffers,
1269      boost::asio::transfer_exactly(10), error);
1270  BOOST_ASIO_CHECK(bytes_transferred == 10);
1271  BOOST_ASIO_CHECK(s.check_buffers(buffers, 10));
1272  BOOST_ASIO_CHECK(!error);
1273
1274  s.reset();
1275  s.next_write_length(10);
1276  error = boost::system::error_code();
1277  bytes_transferred = boost::asio::write(s, buffers,
1278      boost::asio::transfer_exactly(10), error);
1279  BOOST_ASIO_CHECK(bytes_transferred == 10);
1280  BOOST_ASIO_CHECK(s.check_buffers(buffers, 10));
1281  BOOST_ASIO_CHECK(!error);
1282
1283  s.reset();
1284  error = boost::system::error_code();
1285  bytes_transferred = boost::asio::write(s, buffers,
1286      boost::asio::transfer_exactly(42), error);
1287  BOOST_ASIO_CHECK(bytes_transferred == 42);
1288  BOOST_ASIO_CHECK(s.check_buffers(buffers, 42));
1289  BOOST_ASIO_CHECK(!error);
1290
1291  s.reset();
1292  s.next_write_length(1);
1293  error = boost::system::error_code();
1294  bytes_transferred = boost::asio::write(s, buffers,
1295      boost::asio::transfer_exactly(42), error);
1296  BOOST_ASIO_CHECK(bytes_transferred == 42);
1297  BOOST_ASIO_CHECK(s.check_buffers(buffers, 42));
1298  BOOST_ASIO_CHECK(!error);
1299
1300  s.reset();
1301  s.next_write_length(10);
1302  error = boost::system::error_code();
1303  bytes_transferred = boost::asio::write(s, buffers,
1304      boost::asio::transfer_exactly(42), error);
1305  BOOST_ASIO_CHECK(bytes_transferred == 42);
1306  BOOST_ASIO_CHECK(s.check_buffers(buffers, 42));
1307  BOOST_ASIO_CHECK(!error);
1308
1309  s.reset();
1310  bytes_transferred = boost::asio::write(s, buffers,
1311      old_style_transfer_all, error);
1312  BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data));
1313  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(mutable_write_data)));
1314  BOOST_ASIO_CHECK(!error);
1315
1316  s.reset();
1317  s.next_write_length(1);
1318  error = boost::system::error_code();
1319  bytes_transferred = boost::asio::write(s, buffers,
1320      old_style_transfer_all, error);
1321  BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data));
1322  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(mutable_write_data)));
1323  BOOST_ASIO_CHECK(!error);
1324
1325  s.reset();
1326  s.next_write_length(10);
1327  error = boost::system::error_code();
1328  bytes_transferred = boost::asio::write(s, buffers,
1329      old_style_transfer_all, error);
1330  BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data));
1331  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(mutable_write_data)));
1332  BOOST_ASIO_CHECK(!error);
1333
1334  s.reset();
1335  bytes_transferred = boost::asio::write(s, buffers, short_transfer, error);
1336  BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data));
1337  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(mutable_write_data)));
1338  BOOST_ASIO_CHECK(!error);
1339
1340  s.reset();
1341  s.next_write_length(1);
1342  error = boost::system::error_code();
1343  bytes_transferred = boost::asio::write(s, buffers, short_transfer, error);
1344  BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data));
1345  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(mutable_write_data)));
1346  BOOST_ASIO_CHECK(!error);
1347
1348  s.reset();
1349  s.next_write_length(10);
1350  error = boost::system::error_code();
1351  bytes_transferred = boost::asio::write(s, buffers, short_transfer, error);
1352  BOOST_ASIO_CHECK(bytes_transferred == sizeof(mutable_write_data));
1353  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(mutable_write_data)));
1354  BOOST_ASIO_CHECK(!error);
1355}
1356
1357void test_4_arg_vector_buffers_write()
1358{
1359  boost::asio::io_service ios;
1360  test_stream s(ios);
1361  std::vector<boost::asio::const_buffer> buffers;
1362  buffers.push_back(boost::asio::buffer(write_data, 32));
1363  buffers.push_back(boost::asio::buffer(write_data) + 32);
1364
1365  s.reset();
1366  boost::system::error_code error;
1367  size_t bytes_transferred = boost::asio::write(s, buffers,
1368      boost::asio::transfer_all(), error);
1369  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
1370  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
1371  BOOST_ASIO_CHECK(!error);
1372
1373  s.reset();
1374  s.next_write_length(1);
1375  error = boost::system::error_code();
1376  bytes_transferred = boost::asio::write(s, buffers,
1377      boost::asio::transfer_all(), error);
1378  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
1379  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
1380  BOOST_ASIO_CHECK(!error);
1381
1382  s.reset();
1383  s.next_write_length(10);
1384  error = boost::system::error_code();
1385  bytes_transferred = boost::asio::write(s, buffers,
1386      boost::asio::transfer_all(), error);
1387  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
1388  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
1389  BOOST_ASIO_CHECK(!error);
1390
1391  s.reset();
1392  error = boost::system::error_code();
1393  bytes_transferred = boost::asio::write(s, buffers,
1394      boost::asio::transfer_at_least(1), error);
1395  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
1396  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
1397  BOOST_ASIO_CHECK(!error);
1398
1399  s.reset();
1400  s.next_write_length(1);
1401  error = boost::system::error_code();
1402  bytes_transferred = boost::asio::write(s, buffers,
1403      boost::asio::transfer_at_least(1), error);
1404  BOOST_ASIO_CHECK(bytes_transferred == 1);
1405  BOOST_ASIO_CHECK(s.check_buffers(buffers, 1));
1406  BOOST_ASIO_CHECK(!error);
1407
1408  s.reset();
1409  s.next_write_length(10);
1410  error = boost::system::error_code();
1411  bytes_transferred = boost::asio::write(s, buffers,
1412      boost::asio::transfer_at_least(1), error);
1413  BOOST_ASIO_CHECK(bytes_transferred == 10);
1414  BOOST_ASIO_CHECK(s.check_buffers(buffers, 10));
1415  BOOST_ASIO_CHECK(!error);
1416
1417  s.reset();
1418  error = boost::system::error_code();
1419  bytes_transferred = boost::asio::write(s, buffers,
1420      boost::asio::transfer_at_least(10), error);
1421  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
1422  BOOST_ASIO_CHECK(s.check_buffers(buffers, sizeof(write_data)));
1423  BOOST_ASIO_CHECK(!error);
1424
1425  s.reset();
1426  s.next_write_length(1);
1427  error = boost::system::error_code();
1428  bytes_transferred = boost::asio::write(s, buffers,
1429      boost::asio::transfer_at_least(10), error);
1430  BOOST_ASIO_CHECK(bytes_transferred == 10);
1431  BOOST_ASIO_CHECK(s.check_buffers(buffers, 10));
1432  BOOST_ASIO_CHECK(!error);
1433
1434  s.reset();
1435  s.next_write_length(10);
1436  error = boost::system::error_code();
1437  bytes_transferred = boost::asio::write(s, buffers,
1438      boost::asio::transfer_at_least(10), error);
1439  BOOST_ASIO_CHECK(bytes_transferred == 10);
1440  BOOST_ASIO_CHECK(s.check_buffers(buffers, 10));
1441  BOOST_ASIO_CHECK(!error);
1442
1443  s.reset();
1444  error = boost::system::error_code();
1445  bytes_transferred = boost::asio::write(s, buffers,
1446      boost::asio::transfer_at_least(42), error);
1447  BOOST_ASIO_CHECK(bytes_transferred == sizeof(write_data));
1448  BOOST_ASIO_CHECK(s.check_

Large files files are truncated, but you can click here to view the full file