mirror of
https://github.com/boostorg/asio.git
synced 2026-01-19 04:02: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
4.1 KiB
C++
148 lines
4.1 KiB
C++
//
|
|
// socket_base_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/socket_base.hpp>
|
|
|
|
#include <boost/asio.hpp>
|
|
#include "unit_test.hpp"
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// socket_base_compile test
|
|
// ~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// The following test checks that all nested classes, enums and constants in
|
|
// socket_base compile and link correctly. Runtime failures are ignored.
|
|
|
|
namespace socket_base_compile {
|
|
|
|
using namespace boost::asio;
|
|
|
|
void test()
|
|
{
|
|
try
|
|
{
|
|
io_service ios;
|
|
ip::tcp::socket sock(ios);
|
|
char buf[1024];
|
|
|
|
// shutdown_type enumeration.
|
|
|
|
sock.shutdown(socket_base::shutdown_receive);
|
|
sock.shutdown(socket_base::shutdown_send);
|
|
sock.shutdown(socket_base::shutdown_both);
|
|
|
|
// message_flags constants.
|
|
|
|
sock.receive(buffer(buf), socket_base::message_peek);
|
|
sock.receive(buffer(buf), socket_base::message_out_of_band);
|
|
sock.send(buffer(buf), socket_base::message_do_not_route);
|
|
|
|
// broadcast class.
|
|
|
|
socket_base::broadcast broadcast1(true);
|
|
sock.set_option(broadcast1);
|
|
socket_base::broadcast broadcast2;
|
|
sock.get_option(broadcast2);
|
|
|
|
// do_not_route class.
|
|
|
|
socket_base::do_not_route do_not_route1(true);
|
|
sock.set_option(do_not_route1);
|
|
socket_base::do_not_route do_not_route2;
|
|
sock.get_option(do_not_route2);
|
|
|
|
// keep_alive class.
|
|
|
|
socket_base::keep_alive keep_alive1(true);
|
|
sock.set_option(keep_alive1);
|
|
socket_base::keep_alive keep_alive2;
|
|
sock.get_option(keep_alive2);
|
|
|
|
// send_buffer_size class.
|
|
|
|
socket_base::send_buffer_size send_buffer_size1(1024);
|
|
sock.set_option(send_buffer_size1);
|
|
socket_base::send_buffer_size send_buffer_size2;
|
|
sock.get_option(send_buffer_size2);
|
|
|
|
// send_low_watermark class.
|
|
|
|
socket_base::send_low_watermark send_low_watermark1(128);
|
|
sock.set_option(send_low_watermark1);
|
|
socket_base::send_low_watermark send_low_watermark2;
|
|
sock.get_option(send_low_watermark2);
|
|
|
|
// receive_buffer_size class.
|
|
|
|
socket_base::receive_buffer_size receive_buffer_size1(1024);
|
|
sock.set_option(receive_buffer_size1);
|
|
socket_base::receive_buffer_size receive_buffer_size2;
|
|
sock.get_option(receive_buffer_size2);
|
|
|
|
// receive_low_watermark class.
|
|
|
|
socket_base::receive_low_watermark receive_low_watermark1(128);
|
|
sock.set_option(receive_low_watermark1);
|
|
socket_base::receive_low_watermark receive_low_watermark2;
|
|
sock.get_option(receive_low_watermark2);
|
|
|
|
// reuse_address class.
|
|
|
|
socket_base::reuse_address reuse_address1(true);
|
|
sock.set_option(reuse_address1);
|
|
socket_base::reuse_address reuse_address2;
|
|
sock.get_option(reuse_address2);
|
|
|
|
// linger class.
|
|
|
|
socket_base::linger linger1(true, 30);
|
|
sock.set_option(linger1);
|
|
socket_base::linger linger2;
|
|
sock.get_option(linger2);
|
|
|
|
// enable_connection_aborted class.
|
|
|
|
socket_base::enable_connection_aborted enable_connection_aborted1(true);
|
|
sock.set_option(enable_connection_aborted1);
|
|
socket_base::enable_connection_aborted enable_connection_aborted2;
|
|
sock.get_option(enable_connection_aborted2);
|
|
|
|
// non_blocking_io class.
|
|
|
|
socket_base::non_blocking_io non_blocking_io(true);
|
|
sock.io_control(non_blocking_io);
|
|
|
|
// bytes_readable class.
|
|
|
|
socket_base::bytes_readable bytes_readable;
|
|
sock.io_control(bytes_readable);
|
|
std::size_t bytes = bytes_readable.get();
|
|
(void)bytes;
|
|
}
|
|
catch (std::exception&)
|
|
{
|
|
}
|
|
}
|
|
|
|
} // namespace socket_base_compile
|
|
|
|
test_suite* init_unit_test_suite(int argc, char* argv[])
|
|
{
|
|
test_suite* test = BOOST_TEST_SUITE("socket_base");
|
|
test->add(BOOST_TEST_CASE(&socket_base_compile::test));
|
|
return test;
|
|
}
|