PageRenderTime 152ms CodeModel.GetById 4ms app.highlight 137ms RepoModel.GetById 2ms app.codeStats 1ms

/test/read.cpp

https://bitbucket.org/boostorg/asio
C++ | 3919 lines | 3507 code | 401 blank | 11 comment | 293 complexity | f6f82d28bf338561bb9fcbc3145edb58 MD5 | raw file

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

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

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