mirror of
https://github.com/boostorg/asio.git
synced 2026-01-19 16:12:09 +00:00
Make basic_io_object constructor protected. Make a 0-length send or receive on a stream socket into a no-op. Add cancel() function for cancelling asynchronous socket operations. The Win32 implementation only works if all operations for the socket have been issued from the same thread, otherwise it fails with asio::error::not_supported. Add workaround for an apparent Windows bug where using getpeername on a socket accepted using AcceptEx will sometimes return an endpoint that is all zeroes. Make a strand last as long as it has any handlers to dispatch. Make strand a nested class of io_service. Add io_service() function to io_service::work to return a reference to the io_service object on which the work is being performed. Renamed io_service::service::owner() to io_service::service::io_service(). Unset linger object when socket objects are destroyed. Rename asio_handler_dispatch to asio_handler_invoke. Rename basic_socketbuf to basic_socket_streambuf. Update ip::address_v4 and ip::address_v6 classes to match TR2 proposal. Add run_one(), poll() and poll_one() functions to the io_service. Remove need to #define FD_SETSIZE on Win32. Add detection of incorrect inclusion of WinSock.h. Fix some SSL bugs. Add ability to customise the SSL password callback function. Set the reuse_address option by default on acceptors. The macros FIONREAD and FIONBIO are not integer constants on all platforms, and so cannot be used as template arguments. Make the corresponding I/O control commands into proper classes, not templates. Fixes to better support *BSD platforms. Add support for buffer debugging, if the standard library supports iterator debugging (as MSVC8's standard lib does). Ensure the IOCP queue is drained correctly at shutdown. Move basic_resolver and resolver service into the ip namespace. Fix some issues found by the inspect tool. [SVN r35833]
148 lines
3.8 KiB
C++
148 lines
3.8 KiB
C++
//
|
|
// buffer_test.cpp
|
|
// ~~~~~~~~~~~~~~~
|
|
//
|
|
// Copyright (c) 2003-2006 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
|
//
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
//
|
|
|
|
// Disable autolinking for unit tests.
|
|
#if !defined(BOOST_ALL_NO_LIB)
|
|
#define BOOST_ALL_NO_LIB 1
|
|
#endif // !defined(BOOST_ALL_NO_LIB)
|
|
|
|
// Test that header file is self-contained.
|
|
#include <boost/asio/buffer.hpp>
|
|
|
|
#include "unit_test.hpp"
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// buffer_compile test
|
|
// ~~~~~~~~~~~~~~~~~~~
|
|
// The following test checks that all overloads of the buffer function compile
|
|
// and link correctly. Runtime failures are ignored.
|
|
|
|
namespace buffer_compile {
|
|
|
|
using namespace boost::asio;
|
|
|
|
void test()
|
|
{
|
|
try
|
|
{
|
|
char raw_data[1024];
|
|
const char const_raw_data[1024] = "";
|
|
void* void_ptr_data = raw_data;
|
|
const void* const_void_ptr_data = const_raw_data;
|
|
boost::array<char, 1024> array_data;
|
|
const boost::array<char, 1024>& const_array_data_1 = array_data;
|
|
boost::array<const char, 1024> const_array_data_2 = { 0 };
|
|
std::vector<char> vector_data(1024);
|
|
const std::vector<char>& const_vector_data = vector_data;
|
|
const std::string string_data(1024, ' ');
|
|
|
|
// mutable_buffer constructors.
|
|
|
|
mutable_buffer mb1;
|
|
mutable_buffer mb2(void_ptr_data, 1024);
|
|
mutable_buffer mb3(mb1);
|
|
|
|
// mutable_buffer functions.
|
|
|
|
void* ptr1 = buffer_cast<void*>(mb1);
|
|
(void)ptr1;
|
|
std::size_t size1 = buffer_size(mb1);
|
|
(void)size1;
|
|
|
|
// mutable_buffer operators.
|
|
|
|
mb1 = mb2 + 128;
|
|
mb1 = 128 + mb2;
|
|
|
|
// mutable_buffer_container_1 constructors.
|
|
|
|
mutable_buffer_container_1 mbc1(mb1);
|
|
mutable_buffer_container_1 mbc2(mbc1);
|
|
|
|
// mutable_buffer_container_1 functions.
|
|
|
|
mutable_buffer_container_1::const_iterator iter1 = mbc1.begin();
|
|
(void)iter1;
|
|
mutable_buffer_container_1::const_iterator iter2 = mbc1.end();
|
|
(void)iter2;
|
|
|
|
// const_buffer constructors.
|
|
|
|
const_buffer cb1;
|
|
const_buffer cb2(const_void_ptr_data, 1024);
|
|
const_buffer cb3(cb1);
|
|
const_buffer cb4(mb1);
|
|
|
|
// const_buffer functions.
|
|
|
|
const void* ptr2 = buffer_cast<const void*>(cb1);
|
|
(void)ptr2;
|
|
std::size_t size2 = buffer_size(cb1);
|
|
(void)size2;
|
|
|
|
// const_buffer operators.
|
|
|
|
cb1 = cb2 + 128;
|
|
cb1 = 128 + cb2;
|
|
|
|
// const_buffer_container_1 constructors.
|
|
|
|
const_buffer_container_1 cbc1(cb1);
|
|
const_buffer_container_1 cbc2(cbc1);
|
|
|
|
// const_buffer_container_1 functions.
|
|
|
|
const_buffer_container_1::const_iterator iter3 = cbc1.begin();
|
|
(void)iter3;
|
|
const_buffer_container_1::const_iterator iter4 = cbc1.end();
|
|
(void)iter4;
|
|
|
|
// buffer function overloads.
|
|
|
|
mb1 = buffer(mb2);
|
|
mb1 = buffer(mb2, 128);
|
|
cb1 = buffer(cb2);
|
|
cb1 = buffer(cb2, 128);
|
|
mb1 = buffer(void_ptr_data, 1024);
|
|
cb1 = buffer(const_void_ptr_data, 1024);
|
|
mb1 = buffer(raw_data);
|
|
mb1 = buffer(raw_data, 1024);
|
|
cb1 = buffer(const_raw_data);
|
|
cb1 = buffer(const_raw_data, 1024);
|
|
mb1 = buffer(array_data);
|
|
mb1 = buffer(array_data, 1024);
|
|
cb1 = buffer(const_array_data_1);
|
|
cb1 = buffer(const_array_data_1, 1024);
|
|
cb1 = buffer(const_array_data_2);
|
|
cb1 = buffer(const_array_data_2, 1024);
|
|
mb1 = buffer(vector_data);
|
|
mb1 = buffer(vector_data, 1024);
|
|
cb1 = buffer(const_vector_data);
|
|
cb1 = buffer(const_vector_data, 1024);
|
|
cb1 = buffer(string_data);
|
|
cb1 = buffer(string_data, 1024);
|
|
}
|
|
catch (std::exception&)
|
|
{
|
|
}
|
|
}
|
|
|
|
} // namespace buffer_compile
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
test_suite* init_unit_test_suite(int argc, char* argv[])
|
|
{
|
|
test_suite* test = BOOST_TEST_SUITE("buffer");
|
|
test->add(BOOST_TEST_CASE(&buffer_compile::test));
|
|
return test;
|
|
}
|