Boost logo

Boost-Commit :

From: chris_at_[hidden]
Date: 2008-04-21 00:43:07


Author: chris_kohlhoff
Date: 2008-04-21 00:43:05 EDT (Mon, 21 Apr 2008)
New Revision: 44674
URL: http://svn.boost.org/trac/boost/changeset/44674

Log:
Add support for UNIX domain sockets.

Added:
   trunk/boost/asio/local/
   trunk/boost/asio/local/basic_endpoint.hpp (contents, props changed)
   trunk/boost/asio/local/connect_pair.hpp (contents, props changed)
   trunk/boost/asio/local/datagram_protocol.hpp (contents, props changed)
   trunk/boost/asio/local/stream_protocol.hpp (contents, props changed)
   trunk/libs/asio/test/local/
   trunk/libs/asio/test/local/basic_endpoint.cpp (contents, props changed)
   trunk/libs/asio/test/local/connect_pair.cpp (contents, props changed)
   trunk/libs/asio/test/local/datagram_protocol.cpp (contents, props changed)
   trunk/libs/asio/test/local/stream_protocol.cpp (contents, props changed)
Text files modified:
   trunk/boost/asio.hpp | 4 ++++
   trunk/boost/asio/detail/socket_ops.hpp | 12 ++++++++++++
   trunk/boost/asio/detail/socket_types.hpp | 2 ++
   trunk/boost/asio/error.hpp | 3 +++
   trunk/libs/asio/test/Jamfile | 4 ++++
   trunk/libs/asio/test/Jamfile.v2 | 8 ++++++++
   6 files changed, 33 insertions(+), 0 deletions(-)

Modified: trunk/boost/asio.hpp
==============================================================================
--- trunk/boost/asio.hpp (original)
+++ trunk/boost/asio.hpp 2008-04-21 00:43:05 EDT (Mon, 21 Apr 2008)
@@ -58,6 +58,10 @@
 #include <boost/asio/ip/v6_only.hpp>
 #include <boost/asio/is_read_buffered.hpp>
 #include <boost/asio/is_write_buffered.hpp>
+#include <boost/asio/local/basic_endpoint.hpp>
+#include <boost/asio/local/connect_pair.hpp>
+#include <boost/asio/local/datagram_protocol.hpp>
+#include <boost/asio/local/stream_protocol.hpp>
 #include <boost/asio/placeholders.hpp>
 #include <boost/asio/read.hpp>
 #include <boost/asio/read_until.hpp>

Modified: trunk/boost/asio/detail/socket_ops.hpp
==============================================================================
--- trunk/boost/asio/detail/socket_ops.hpp (original)
+++ trunk/boost/asio/detail/socket_ops.hpp 2008-04-21 00:43:05 EDT (Mon, 21 Apr 2008)
@@ -176,6 +176,18 @@
   return result;
 }
 
+inline int socketpair(int af, int type, int protocol,
+ socket_type sv[2], boost::system::error_code& ec)
+{
+#if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
+ ec = boost::asio::error::operation_not_supported;
+ return -1;
+#else
+ clear_error(ec);
+ return error_wrapper(::socketpair(af, type, protocol, sv), ec);
+#endif
+}
+
 inline int listen(socket_type s, int backlog, boost::system::error_code& ec)
 {
   clear_error(ec);

Modified: trunk/boost/asio/detail/socket_types.hpp
==============================================================================
--- trunk/boost/asio/detail/socket_types.hpp (original)
+++ trunk/boost/asio/detail/socket_types.hpp 2008-04-21 00:43:05 EDT (Mon, 21 Apr 2008)
@@ -99,6 +99,7 @@
 # endif
 # include <sys/socket.h>
 # include <sys/uio.h>
+# include <sys/un.h>
 # include <netinet/in.h>
 # include <netinet/tcp.h>
 # include <arpa/inet.h>
@@ -176,6 +177,7 @@
 typedef ipv6_mreq in6_mreq_type;
 typedef sockaddr_in6 sockaddr_in6_type;
 typedef sockaddr_storage sockaddr_storage_type;
+typedef sockaddr_un sockaddr_un_type;
 typedef addrinfo addrinfo_type;
 typedef int ioctl_arg_type;
 typedef uint32_t u_long_type;

Modified: trunk/boost/asio/error.hpp
==============================================================================
--- trunk/boost/asio/error.hpp (original)
+++ trunk/boost/asio/error.hpp 2008-04-21 00:43:05 EDT (Mon, 21 Apr 2008)
@@ -106,6 +106,9 @@
   /// Message too long.
   message_size = BOOST_ASIO_SOCKET_ERROR(EMSGSIZE),
 
+ /// The name was too long.
+ name_too_long = BOOST_ASIO_SOCKET_ERROR(ENAMETOOLONG),
+
   /// Network is down.
   network_down = BOOST_ASIO_SOCKET_ERROR(ENETDOWN),
 

Added: trunk/boost/asio/local/basic_endpoint.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/asio/local/basic_endpoint.hpp 2008-04-21 00:43:05 EDT (Mon, 21 Apr 2008)
@@ -0,0 +1,267 @@
+//
+// basic_endpoint.hpp
+// ~~~~~~~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+// Derived from a public domain implementation written by Daniel Casimiro.
+//
+// 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)
+//
+
+#ifndef BOOST_ASIO_LOCAL_BASIC_ENDPOINT_HPP
+#define BOOST_ASIO_LOCAL_BASIC_ENDPOINT_HPP
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1200)
+# pragma once
+#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
+
+#include <boost/asio/detail/push_options.hpp>
+
+#include <boost/asio/detail/push_options.hpp>
+#include <boost/throw_exception.hpp>
+#include <cstddef>
+#include <cstring>
+#include <ostream>
+#include <boost/system/system_error.hpp>
+#include <boost/asio/detail/pop_options.hpp>
+
+#include <boost/asio/error.hpp>
+#include <boost/asio/detail/socket_ops.hpp>
+#include <boost/asio/detail/socket_types.hpp>
+#include <boost/asio/detail/throw_error.hpp>
+
+#if !defined(BOOST_ASIO_DISABLE_LOCAL_SOCKETS)
+# if !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
+# define BOOST_ASIO_HAS_LOCAL_SOCKETS 1
+# endif // !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
+#endif // !defined(BOOST_ASIO_DISABLE_LOCAL_SOCKETS)
+
+#if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) \
+ || defined(GENERATING_DOCUMENTATION)
+
+
+namespace boost {
+namespace asio {
+namespace local {
+
+/// Describes an endpoint for a UNIX socket.
+/**
+ * The boost::asio::local::basic_endpoint class template describes an endpoint
+ * that may be associated with a particular UNIX socket.
+ *
+ * @par Thread Safety
+ * @e Distinct @e objects: Safe._at_n
+ * @e Shared @e objects: Unsafe.
+ *
+ * @par Concepts:
+ * Endpoint.
+ */
+template <typename Protocol>
+class basic_endpoint
+{
+public:
+ /// The protocol type associated with the endpoint.
+ typedef Protocol protocol_type;
+
+ /// The type of the endpoint structure. This type is dependent on the
+ /// underlying implementation of the socket layer.
+#if defined(GENERATING_DOCUMENTATION)
+ typedef implementation_defined data_type;
+#else
+ typedef boost::asio::detail::socket_addr_type data_type;
+#endif
+
+ /// Default constructor.
+ basic_endpoint()
+ {
+ init("", 0);
+ }
+
+ /// Construct an endpoint using the specified path name.
+ basic_endpoint(const char* path)
+ {
+ using namespace std; // For strlen.
+ init(path, strlen(path));
+ }
+
+ /// Construct an endpoint using the specified path name.
+ basic_endpoint(const std::string& path)
+ {
+ init(path.data(), path.length());
+ }
+
+ /// Copy constructor.
+ basic_endpoint(const basic_endpoint& other)
+ : data_(other.data_),
+ path_length_(other.path_length_)
+ {
+ }
+
+ /// Assign from another endpoint.
+ basic_endpoint& operator=(const basic_endpoint& other)
+ {
+ data_ = other.data_;
+ path_length_ = other.path_length_;
+ return *this;
+ }
+
+ /// The protocol associated with the endpoint.
+ protocol_type protocol() const
+ {
+ return protocol_type();
+ }
+
+ /// Get the underlying endpoint in the native type.
+ data_type* data()
+ {
+ return &data_.base;
+ }
+
+ /// Get the underlying endpoint in the native type.
+ const data_type* data() const
+ {
+ return &data_.base;
+ }
+
+ /// Get the underlying size of the endpoint in the native type.
+ std::size_t size() const
+ {
+ return path_length_
+ + offsetof(boost::asio::detail::sockaddr_un_type, sun_path);
+ }
+
+ /// Set the underlying size of the endpoint in the native type.
+ void resize(std::size_t size)
+ {
+ if (size > sizeof(boost::asio::detail::sockaddr_un_type))
+ {
+ boost::system::system_error e(boost::asio::error::invalid_argument);
+ boost::throw_exception(e);
+ }
+ else if (size == 0)
+ {
+ path_length_ = 0;
+ }
+ else
+ {
+ path_length_ = size
+ - offsetof(boost::asio::detail::sockaddr_un_type, sun_path);
+
+ // The path returned by the operating system may be NUL-terminated.
+ if (path_length_ > 0 && data_.local.sun_path[path_length_] == 0)
+ --path_length_;
+ }
+ }
+
+ /// Get the capacity of the endpoint in the native type.
+ std::size_t capacity() const
+ {
+ return sizeof(boost::asio::detail::sockaddr_un_type);
+ }
+
+ /// Get the path associated with the endpoint.
+ std::string path() const
+ {
+ return std::string(data_.local.sun_path, path_length_);
+ }
+
+ /// Set the path associated with the endpoint.
+ void path(const char* p)
+ {
+ using namespace std; // For strlen.
+ init(p, strlen(p));
+ }
+
+ /// Set the path associated with the endpoint.
+ void path(const std::string& p)
+ {
+ init(p.data(), p.length());
+ }
+
+ /// Compare two endpoints for equality.
+ friend bool operator==(const basic_endpoint<Protocol>& e1,
+ const basic_endpoint<Protocol>& e2)
+ {
+ return e1.path() == e2.path();
+ }
+
+ /// Compare two endpoints for inequality.
+ friend bool operator!=(const basic_endpoint<Protocol>& e1,
+ const basic_endpoint<Protocol>& e2)
+ {
+ return e1.path() != e2.path();
+ }
+
+ /// Compare endpoints for ordering.
+ friend bool operator<(const basic_endpoint<Protocol>& e1,
+ const basic_endpoint<Protocol>& e2)
+ {
+ return e1.path() < e2.path();
+ }
+
+private:
+ // The underlying UNIX socket address.
+ union data_union
+ {
+ boost::asio::detail::socket_addr_type base;
+ boost::asio::detail::sockaddr_un_type local;
+ } data_;
+
+ // The length of the path associated with the endpoint.
+ std::size_t path_length_;
+
+ // Initialise with a specified path.
+ void init(const char* path, std::size_t path_length)
+ {
+ if (path_length > sizeof(data_.local.sun_path) - 1)
+ {
+ // The buffer is not large enough to store this address.
+ boost::system::error_code ec(boost::asio::error::name_too_long);
+ boost::asio::detail::throw_error(ec);
+ }
+
+ using namespace std; // For memcpy.
+ data_.local = boost::asio::detail::sockaddr_un_type();
+ data_.local.sun_family = AF_UNIX;
+ memcpy(data_.local.sun_path, path, path_length);
+ path_length_ = path_length;
+
+ // NUL-terminate normal path names. Names that start with a NUL are in the
+ // UNIX domain protocol's "abstract namespace" and are not NUL-terminated.
+ if (path_length > 0 && data_.local.sun_path[0] == 0)
+ data_.local.sun_path[path_length] = 0;
+ }
+};
+
+/// Output an endpoint as a string.
+/**
+ * Used to output a human-readable string for a specified endpoint.
+ *
+ * @param os The output stream to which the string will be written.
+ *
+ * @param endpoint The endpoint to be written.
+ *
+ * @return The output stream.
+ *
+ * @relates boost::asio::local::basic_endpoint
+ */
+template <typename Elem, typename Traits, typename Protocol>
+std::basic_ostream<Elem, Traits>& operator<<(
+ std::basic_ostream<Elem, Traits>& os,
+ const basic_endpoint<Protocol>& endpoint)
+{
+ os << endpoint.path();
+ return os;
+}
+
+} // namespace local
+} // namespace asio
+} // namespace boost
+
+#endif // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
+ // || defined(GENERATING_DOCUMENTATION)
+
+#include <boost/asio/detail/pop_options.hpp>
+
+#endif // BOOST_ASIO_LOCAL_BASIC_ENDPOINT_HPP

Added: trunk/boost/asio/local/connect_pair.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/asio/local/connect_pair.hpp 2008-04-21 00:43:05 EDT (Mon, 21 Apr 2008)
@@ -0,0 +1,102 @@
+//
+// connect_pair.hpp
+// ~~~~~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2008 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)
+//
+
+#ifndef BOOST_ASIO_LOCAL_CONNECT_PAIR_HPP
+#define BOOST_ASIO_LOCAL_CONNECT_PAIR_HPP
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1200)
+# pragma once
+#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
+
+#include <boost/asio/detail/push_options.hpp>
+
+#include <boost/asio/basic_socket.hpp>
+#include <boost/asio/error.hpp>
+#include <boost/asio/local/basic_endpoint.hpp>
+#include <boost/asio/detail/socket_ops.hpp>
+#include <boost/asio/detail/throw_error.hpp>
+
+#if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) \
+ || defined(GENERATING_DOCUMENTATION)
+
+namespace boost {
+namespace asio {
+namespace local {
+
+/// Create a pair of connected sockets.
+template <typename Protocol, typename SocketService1, typename SocketService2>
+void connect_pair(
+ basic_socket<Protocol, SocketService1>& socket1,
+ basic_socket<Protocol, SocketService2>& socket2);
+
+/// Create a pair of connected sockets.
+template <typename Protocol, typename SocketService1, typename SocketService2>
+boost::system::error_code connect_pair(
+ basic_socket<Protocol, SocketService1>& socket1,
+ basic_socket<Protocol, SocketService2>& socket2,
+ boost::system::error_code& ec);
+
+template <typename Protocol, typename SocketService1, typename SocketService2>
+inline void connect_pair(
+ basic_socket<Protocol, SocketService1>& socket1,
+ basic_socket<Protocol, SocketService2>& socket2)
+{
+ boost::system::error_code ec;
+ connect_pair(socket1, socket2, ec);
+ boost::asio::detail::throw_error(ec);
+}
+
+template <typename Protocol, typename SocketService1, typename SocketService2>
+inline boost::system::error_code connect_pair(
+ basic_socket<Protocol, SocketService1>& socket1,
+ basic_socket<Protocol, SocketService2>& socket2,
+ boost::system::error_code& ec)
+{
+ // Check that this function is only being used with a UNIX domain socket.
+ boost::asio::local::basic_endpoint<Protocol>* tmp
+ = static_cast<typename Protocol::endpoint*>(0);
+ (void)tmp;
+
+ Protocol protocol;
+ boost::asio::detail::socket_type sv[2];
+ if (boost::asio::detail::socket_ops::socketpair(protocol.family(),
+ protocol.type(), protocol.protocol(), sv, ec)
+ == boost::asio::detail::socket_error_retval)
+ return ec;
+
+ if (socket1.assign(protocol, sv[0], ec))
+ {
+ boost::system::error_code temp_ec;
+ boost::asio::detail::socket_ops::close(sv[0], temp_ec);
+ boost::asio::detail::socket_ops::close(sv[1], temp_ec);
+ return ec;
+ }
+
+ if (socket2.assign(protocol, sv[1], ec))
+ {
+ boost::system::error_code temp_ec;
+ socket1.close(temp_ec);
+ boost::asio::detail::socket_ops::close(sv[1], temp_ec);
+ return ec;
+ }
+
+ return ec;
+}
+
+} // namespace local
+} // namespace asio
+} // namespace boost
+
+#endif // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
+ // || defined(GENERATING_DOCUMENTATION)
+
+#include <boost/asio/detail/pop_options.hpp>
+
+#endif // BOOST_ASIO_LOCAL_CONNECT_PAIR_HPP

Added: trunk/boost/asio/local/datagram_protocol.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/asio/local/datagram_protocol.hpp 2008-04-21 00:43:05 EDT (Mon, 21 Apr 2008)
@@ -0,0 +1,80 @@
+//
+// datagram_protocol.hpp
+// ~~~~~~~~~~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2008 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)
+//
+
+#ifndef BOOST_ASIO_LOCAL_DATAGRAM_PROTOCOL_HPP
+#define BOOST_ASIO_LOCAL_DATAGRAM_PROTOCOL_HPP
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1200)
+# pragma once
+#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
+
+#include <boost/asio/detail/push_options.hpp>
+
+#include <boost/asio/basic_datagram_socket.hpp>
+#include <boost/asio/local/basic_endpoint.hpp>
+#include <boost/asio/detail/socket_types.hpp>
+
+#if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) \
+ || defined(GENERATING_DOCUMENTATION)
+
+namespace boost {
+namespace asio {
+namespace local {
+
+/// Encapsulates the flags needed for datagram-oriented UNIX sockets.
+/**
+ * The boost::asio::local::datagram_protocol class contains flags necessary for
+ * datagram-oriented UNIX domain sockets.
+ *
+ * @par Thread Safety
+ * @e Distinct @e objects: Safe._at_n
+ * @e Shared @e objects: Safe.
+ *
+ * @par Concepts:
+ * Protocol.
+ */
+class datagram_protocol
+{
+public:
+ /// Obtain an identifier for the type of the protocol.
+ int type() const
+ {
+ return SOCK_DGRAM;
+ }
+
+ /// Obtain an identifier for the protocol.
+ int protocol() const
+ {
+ return 0;
+ }
+
+ /// Obtain an identifier for the protocol family.
+ int family() const
+ {
+ return AF_UNIX;
+ }
+
+ /// The type of a UNIX domain endpoint.
+ typedef basic_endpoint<datagram_protocol> endpoint;
+
+ /// The UNIX domain socket type.
+ typedef basic_datagram_socket<datagram_protocol> socket;
+};
+
+} // namespace local
+} // namespace asio
+} // namespace boost
+
+#endif // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
+ // || defined(GENERATING_DOCUMENTATION)
+
+#include <boost/asio/detail/pop_options.hpp>
+
+#endif // BOOST_ASIO_LOCAL_DATAGRAM_PROTOCOL_HPP

Added: trunk/boost/asio/local/stream_protocol.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/asio/local/stream_protocol.hpp 2008-04-21 00:43:05 EDT (Mon, 21 Apr 2008)
@@ -0,0 +1,88 @@
+//
+// stream_protocol.hpp
+// ~~~~~~~~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2008 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)
+//
+
+#ifndef BOOST_ASIO_LOCAL_STREAM_PROTOCOL_HPP
+#define BOOST_ASIO_LOCAL_STREAM_PROTOCOL_HPP
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1200)
+# pragma once
+#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
+
+#include <boost/asio/detail/push_options.hpp>
+
+#include <boost/asio/basic_socket_acceptor.hpp>
+#include <boost/asio/basic_socket_iostream.hpp>
+#include <boost/asio/basic_stream_socket.hpp>
+#include <boost/asio/local/basic_endpoint.hpp>
+#include <boost/asio/detail/socket_types.hpp>
+
+#if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) \
+ || defined(GENERATING_DOCUMENTATION)
+
+namespace boost {
+namespace asio {
+namespace local {
+
+/// Encapsulates the flags needed for stream-oriented UNIX sockets.
+/**
+ * The boost::asio::local::stream_protocol class contains flags necessary for
+ * stream-oriented UNIX domain sockets.
+ *
+ * @par Thread Safety
+ * @e Distinct @e objects: Safe._at_n
+ * @e Shared @e objects: Safe.
+ *
+ * @par Concepts:
+ * Protocol.
+ */
+class stream_protocol
+{
+public:
+ /// Obtain an identifier for the type of the protocol.
+ int type() const
+ {
+ return SOCK_STREAM;
+ }
+
+ /// Obtain an identifier for the protocol.
+ int protocol() const
+ {
+ return 0;
+ }
+
+ /// Obtain an identifier for the protocol family.
+ int family() const
+ {
+ return AF_UNIX;
+ }
+
+ /// The type of a UNIX domain endpoint.
+ typedef basic_endpoint<stream_protocol> endpoint;
+
+ /// The UNIX domain socket type.
+ typedef basic_stream_socket<stream_protocol> socket;
+
+ /// The UNIX domain acceptor type.
+ typedef basic_socket_acceptor<stream_protocol> acceptor;
+
+ /// The UNIX domain iostream type.
+ typedef basic_socket_iostream<stream_protocol> iostream;
+};
+
+} // namespace local
+} // namespace asio
+} // namespace boost
+
+#endif // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
+ // || defined(GENERATING_DOCUMENTATION)
+
+#include <boost/asio/detail/pop_options.hpp>
+
+#endif // BOOST_ASIO_LOCAL_STREAM_PROTOCOL_HPP

Modified: trunk/libs/asio/test/Jamfile
==============================================================================
--- trunk/libs/asio/test/Jamfile (original)
+++ trunk/libs/asio/test/Jamfile 2008-04-21 00:43:05 EDT (Mon, 21 Apr 2008)
@@ -69,6 +69,10 @@
   [ run ip/v6_only.cpp <template>asio_unit_test ]
   [ run is_read_buffered.cpp <template>asio_unit_test ]
   [ run is_write_buffered.cpp <template>asio_unit_test ]
+ [ run local/basic_endpoint.cpp <template>asio_unit_test ]
+ [ run local/connect_pair.cpp <template>asio_unit_test ]
+ [ run local/datagram_protocol.cpp <template>asio_unit_test ]
+ [ run local/stream_protocol.cpp <template>asio_unit_test ]
   [ run placeholders.cpp <template>asio_unit_test ]
   [ run read.cpp <template>asio_unit_test ]
   [ run read_until.cpp <template>asio_unit_test ]

Modified: trunk/libs/asio/test/Jamfile.v2
==============================================================================
--- trunk/libs/asio/test/Jamfile.v2 (original)
+++ trunk/libs/asio/test/Jamfile.v2 2008-04-21 00:43:05 EDT (Mon, 21 Apr 2008)
@@ -116,6 +116,14 @@
   [ run is_read_buffered.cpp : : : $(USE_SELECT) : is_read_buffered_select ]
   [ run is_write_buffered.cpp ]
   [ run is_write_buffered.cpp : : : $(USE_SELECT) : is_write_buffered_select ]
+ [ link local/basic_endpoint.cpp : : local_basic_endpoint ]
+ [ link local/basic_endpoint.cpp : $(USE_SELECT) : local_basic_endpoint_select ]
+ [ link local/connect_pair.cpp : : local_connect_pair ]
+ [ link local/connect_pair.cpp : $(USE_SELECT) : local_connect_pair_select ]
+ [ link local/datagram_protocol.cpp : : local_datagram_protocol ]
+ [ link local/datagram_protocol.cpp : $(USE_SELECT) : local_datagram_protocol_select ]
+ [ link local/stream_protocol.cpp : : local_stream_protocol ]
+ [ link local/stream_protocol.cpp : $(USE_SELECT) : local_stream_protocol_select ]
   [ link placeholders.cpp ]
   [ link placeholders.cpp : $(USE_SELECT) : placeholders_select ]
   [ run read.cpp ]

Added: trunk/libs/asio/test/local/basic_endpoint.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/asio/test/local/basic_endpoint.cpp 2008-04-21 00:43:05 EDT (Mon, 21 Apr 2008)
@@ -0,0 +1,26 @@
+//
+// basic_endpoint.cpp
+// ~~~~~~~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2008 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/local/basic_endpoint.hpp>
+
+#include "../unit_test.hpp"
+
+test_suite* init_unit_test_suite(int argc, char* argv[])
+{
+ test_suite* test = BOOST_TEST_SUITE("local/basic_endpoint");
+ test->add(BOOST_TEST_CASE(&null_test));
+ return test;
+}

Added: trunk/libs/asio/test/local/connect_pair.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/asio/test/local/connect_pair.cpp 2008-04-21 00:43:05 EDT (Mon, 21 Apr 2008)
@@ -0,0 +1,76 @@
+//
+// connect_pair.cpp
+// ~~~~~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2008 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/local/connect_pair.hpp>
+
+#include <boost/asio.hpp>
+#include "../unit_test.hpp"
+
+//------------------------------------------------------------------------------
+
+// local_connect_pair_compile test
+// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+// The following test checks that all host_name functions compile and link
+// correctly. Runtime failures are ignored.
+
+namespace local_connect_pair_compile {
+
+void test()
+{
+#if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
+ using namespace boost::asio;
+ namespace local = boost::asio::local;
+ typedef local::datagram_protocol dp;
+ typedef local::stream_protocol sp;
+
+ try
+ {
+ boost::asio::io_service io_service;
+ boost::system::error_code ec1;
+ boost::system::error_code ec2;
+
+ dp::socket s1(io_service);
+ dp::socket s2(io_service);
+ local::connect_pair(s1, s2);
+
+ dp::socket s3(io_service);
+ dp::socket s4(io_service);
+ ec1 = local::connect_pair(s3, s4, ec2);
+
+ sp::socket s5(io_service);
+ sp::socket s6(io_service);
+ local::connect_pair(s5, s6);
+
+ sp::socket s7(io_service);
+ sp::socket s8(io_service);
+ ec1 = local::connect_pair(s7, s8, ec2);
+ }
+ catch (std::exception&)
+ {
+ }
+#endif // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
+}
+
+} // namespace local_connect_pair_compile
+
+//------------------------------------------------------------------------------
+
+test_suite* init_unit_test_suite(int argc, char* argv[])
+{
+ test_suite* test = BOOST_TEST_SUITE("local/connect_pair");
+ test->add(BOOST_TEST_CASE(&local_connect_pair_compile::test));
+ return test;
+}

Added: trunk/libs/asio/test/local/datagram_protocol.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/asio/test/local/datagram_protocol.cpp 2008-04-21 00:43:05 EDT (Mon, 21 Apr 2008)
@@ -0,0 +1,233 @@
+//
+// datagram_protocol.cpp
+// ~~~~~~~~~~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2008 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/local/datagram_protocol.hpp>
+
+#include <boost/bind.hpp>
+#include <cstring>
+#include <boost/asio.hpp>
+#include "../unit_test.hpp"
+
+//------------------------------------------------------------------------------
+
+// local_datagram_protocol_socket_compile test
+// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+// The following test checks that all public member functions on the class
+// local::datagram_socket::socket compile and link correctly. Runtime failures
+// are ignored.
+
+namespace local_datagram_protocol_socket_compile {
+
+void connect_handler(const boost::system::error_code&)
+{
+}
+
+void send_handler(const boost::system::error_code&, std::size_t)
+{
+}
+
+void receive_handler(const boost::system::error_code&, std::size_t)
+{
+}
+
+void test()
+{
+#if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
+ using namespace boost::asio;
+ namespace local = boost::asio::local;
+ typedef local::datagram_protocol dp;
+
+ try
+ {
+ io_service ios;
+ char mutable_char_buffer[128] = "";
+ const char const_char_buffer[128] = "";
+ socket_base::message_flags in_flags = 0;
+ socket_base::send_buffer_size socket_option;
+ socket_base::bytes_readable io_control_command;
+ boost::system::error_code ec;
+
+ // basic_datagram_socket constructors.
+
+ dp::socket socket1(ios);
+ dp::socket socket2(ios, dp());
+ dp::socket socket3(ios, dp::endpoint(""));
+ int native_socket1 = ::socket(AF_UNIX, SOCK_DGRAM, 0);
+ dp::socket socket4(ios, dp(), native_socket1);
+
+ // basic_io_object functions.
+
+ io_service& ios_ref = socket1.io_service();
+ (void)ios_ref;
+
+ // basic_socket functions.
+
+ dp::socket::lowest_layer_type& lowest_layer = socket1.lowest_layer();
+ (void)lowest_layer;
+
+ socket1.open(dp());
+ socket1.open(dp(), ec);
+
+ int native_socket2 = ::socket(AF_UNIX, SOCK_DGRAM, 0);
+ socket1.assign(dp(), native_socket2);
+ int native_socket3 = ::socket(AF_UNIX, SOCK_DGRAM, 0);
+ socket1.assign(dp(), native_socket3, ec);
+
+ bool is_open = socket1.is_open();
+ (void)is_open;
+
+ socket1.close();
+ socket1.close(ec);
+
+ dp::socket::native_type native_socket4 = socket1.native();
+ (void)native_socket4;
+
+ socket1.cancel();
+ socket1.cancel(ec);
+
+ bool at_mark1 = socket1.at_mark();
+ (void)at_mark1;
+ bool at_mark2 = socket1.at_mark(ec);
+ (void)at_mark2;
+
+ std::size_t available1 = socket1.available();
+ (void)available1;
+ std::size_t available2 = socket1.available(ec);
+ (void)available2;
+
+ socket1.bind(dp::endpoint(""));
+ socket1.bind(dp::endpoint(""), ec);
+
+ socket1.connect(dp::endpoint(""));
+ socket1.connect(dp::endpoint(""), ec);
+
+ socket1.async_connect(dp::endpoint(""), connect_handler);
+
+ socket1.set_option(socket_option);
+ socket1.set_option(socket_option, ec);
+
+ socket1.get_option(socket_option);
+ socket1.get_option(socket_option, ec);
+
+ socket1.io_control(io_control_command);
+ socket1.io_control(io_control_command, ec);
+
+ dp::endpoint endpoint1 = socket1.local_endpoint();
+ dp::endpoint endpoint2 = socket1.local_endpoint(ec);
+
+ dp::endpoint endpoint3 = socket1.remote_endpoint();
+ dp::endpoint endpoint4 = socket1.remote_endpoint(ec);
+
+ socket1.shutdown(socket_base::shutdown_both);
+ socket1.shutdown(socket_base::shutdown_both, ec);
+
+ // basic_datagram_socket functions.
+
+ socket1.send(buffer(mutable_char_buffer));
+ socket1.send(buffer(const_char_buffer));
+ socket1.send(null_buffers());
+ socket1.send(buffer(mutable_char_buffer), in_flags);
+ socket1.send(buffer(const_char_buffer), in_flags);
+ socket1.send(null_buffers(), in_flags);
+ socket1.send(buffer(mutable_char_buffer), in_flags, ec);
+ socket1.send(buffer(const_char_buffer), in_flags, ec);
+ socket1.send(null_buffers(), in_flags, ec);
+
+ socket1.async_send(buffer(mutable_char_buffer), send_handler);
+ socket1.async_send(buffer(const_char_buffer), send_handler);
+ socket1.async_send(null_buffers(), send_handler);
+ socket1.async_send(buffer(mutable_char_buffer), in_flags, send_handler);
+ socket1.async_send(buffer(const_char_buffer), in_flags, send_handler);
+ socket1.async_send(null_buffers(), in_flags, send_handler);
+
+ socket1.send_to(buffer(mutable_char_buffer),
+ dp::endpoint(""));
+ socket1.send_to(buffer(const_char_buffer),
+ dp::endpoint(""));
+ socket1.send_to(null_buffers(),
+ dp::endpoint(""));
+ socket1.send_to(buffer(mutable_char_buffer),
+ dp::endpoint(""), in_flags);
+ socket1.send_to(buffer(const_char_buffer),
+ dp::endpoint(""), in_flags);
+ socket1.send_to(null_buffers(),
+ dp::endpoint(""), in_flags);
+ socket1.send_to(buffer(mutable_char_buffer),
+ dp::endpoint(""), in_flags, ec);
+ socket1.send_to(buffer(const_char_buffer),
+ dp::endpoint(""), in_flags, ec);
+ socket1.send_to(null_buffers(),
+ dp::endpoint(""), in_flags, ec);
+
+ socket1.async_send_to(buffer(mutable_char_buffer),
+ dp::endpoint(""), send_handler);
+ socket1.async_send_to(buffer(const_char_buffer),
+ dp::endpoint(""), send_handler);
+ socket1.async_send_to(null_buffers(),
+ dp::endpoint(""), send_handler);
+ socket1.async_send_to(buffer(mutable_char_buffer),
+ dp::endpoint(""), in_flags, send_handler);
+ socket1.async_send_to(buffer(const_char_buffer),
+ dp::endpoint(""), in_flags, send_handler);
+ socket1.async_send_to(null_buffers(),
+ dp::endpoint(""), in_flags, send_handler);
+
+ socket1.receive(buffer(mutable_char_buffer));
+ socket1.receive(null_buffers());
+ socket1.receive(buffer(mutable_char_buffer), in_flags);
+ socket1.receive(null_buffers(), in_flags);
+ socket1.receive(buffer(mutable_char_buffer), in_flags, ec);
+ socket1.receive(null_buffers(), in_flags, ec);
+
+ socket1.async_receive(buffer(mutable_char_buffer), receive_handler);
+ socket1.async_receive(null_buffers(), receive_handler);
+ socket1.async_receive(buffer(mutable_char_buffer), in_flags,
+ receive_handler);
+ socket1.async_receive(null_buffers(), in_flags, receive_handler);
+
+ dp::endpoint endpoint;
+ socket1.receive_from(buffer(mutable_char_buffer), endpoint);
+ socket1.receive_from(null_buffers(), endpoint);
+ socket1.receive_from(buffer(mutable_char_buffer), endpoint, in_flags);
+ socket1.receive_from(null_buffers(), endpoint, in_flags);
+ socket1.receive_from(buffer(mutable_char_buffer), endpoint, in_flags, ec);
+ socket1.receive_from(null_buffers(), endpoint, in_flags, ec);
+
+ socket1.async_receive_from(buffer(mutable_char_buffer),
+ endpoint, receive_handler);
+ socket1.async_receive_from(null_buffers(),
+ endpoint, receive_handler);
+ socket1.async_receive_from(buffer(mutable_char_buffer),
+ endpoint, in_flags, receive_handler);
+ socket1.async_receive_from(null_buffers(),
+ endpoint, in_flags, receive_handler);
+ }
+ catch (std::exception&)
+ {
+ }
+#endif // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
+}
+
+} // namespace local_datagram_protocol_socket_compile
+
+//------------------------------------------------------------------------------
+
+test_suite* init_unit_test_suite(int argc, char* argv[])
+{
+ test_suite* test = BOOST_TEST_SUITE("local/datagram_protocol");
+ test->add(BOOST_TEST_CASE(&local_datagram_protocol_socket_compile::test));
+ return test;
+}

Added: trunk/libs/asio/test/local/stream_protocol.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/asio/test/local/stream_protocol.cpp 2008-04-21 00:43:05 EDT (Mon, 21 Apr 2008)
@@ -0,0 +1,210 @@
+//
+// stream_protocol.cpp
+// ~~~~~~~~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2008 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/local/stream_protocol.hpp>
+
+#include <boost/bind.hpp>
+#include <cstring>
+#include <boost/asio.hpp>
+#include "../unit_test.hpp"
+
+//------------------------------------------------------------------------------
+
+// local_stream_protocol_socket_compile test
+// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+// The following test checks that all public member functions on the class
+// local::stream_protocol::socket compile and link correctly. Runtime failures
+// are ignored.
+
+namespace local_stream_protocol_socket_compile {
+
+void connect_handler(const boost::system::error_code&)
+{
+}
+
+void send_handler(const boost::system::error_code&, std::size_t)
+{
+}
+
+void receive_handler(const boost::system::error_code&, std::size_t)
+{
+}
+
+void write_some_handler(const boost::system::error_code&, std::size_t)
+{
+}
+
+void read_some_handler(const boost::system::error_code&, std::size_t)
+{
+}
+
+void test()
+{
+#if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
+ using namespace boost::asio;
+ namespace local = boost::asio::local;
+ typedef local::stream_protocol sp;
+
+ try
+ {
+ io_service ios;
+ char mutable_char_buffer[128] = "";
+ const char const_char_buffer[128] = "";
+ socket_base::message_flags in_flags = 0;
+ socket_base::keep_alive socket_option;
+ socket_base::bytes_readable io_control_command;
+ boost::system::error_code ec;
+
+ // basic_stream_socket constructors.
+
+ sp::socket socket1(ios);
+ sp::socket socket2(ios, sp());
+ sp::socket socket3(ios, sp::endpoint(""));
+ int native_socket1 = ::socket(AF_UNIX, SOCK_STREAM, 0);
+ sp::socket socket4(ios, sp(), native_socket1);
+
+ // basic_io_object functions.
+
+ io_service& ios_ref = socket1.io_service();
+ (void)ios_ref;
+
+ // basic_socket functions.
+
+ sp::socket::lowest_layer_type& lowest_layer = socket1.lowest_layer();
+ (void)lowest_layer;
+
+ socket1.open(sp());
+ socket1.open(sp(), ec);
+
+ int native_socket2 = ::socket(AF_UNIX, SOCK_STREAM, 0);
+ socket1.assign(sp(), native_socket2);
+ int native_socket3 = ::socket(AF_UNIX, SOCK_STREAM, 0);
+ socket1.assign(sp(), native_socket3, ec);
+
+ bool is_open = socket1.is_open();
+ (void)is_open;
+
+ socket1.close();
+ socket1.close(ec);
+
+ sp::socket::native_type native_socket4 = socket1.native();
+ (void)native_socket4;
+
+ socket1.cancel();
+ socket1.cancel(ec);
+
+ bool at_mark1 = socket1.at_mark();
+ (void)at_mark1;
+ bool at_mark2 = socket1.at_mark(ec);
+ (void)at_mark2;
+
+ std::size_t available1 = socket1.available();
+ (void)available1;
+ std::size_t available2 = socket1.available(ec);
+ (void)available2;
+
+ socket1.bind(sp::endpoint(""));
+ socket1.bind(sp::endpoint(""), ec);
+
+ socket1.connect(sp::endpoint(""));
+ socket1.connect(sp::endpoint(""), ec);
+
+ socket1.async_connect(sp::endpoint(""), connect_handler);
+
+ socket1.set_option(socket_option);
+ socket1.set_option(socket_option, ec);
+
+ socket1.get_option(socket_option);
+ socket1.get_option(socket_option, ec);
+
+ socket1.io_control(io_control_command);
+ socket1.io_control(io_control_command, ec);
+
+ sp::endpoint endpoint1 = socket1.local_endpoint();
+ sp::endpoint endpoint2 = socket1.local_endpoint(ec);
+
+ sp::endpoint endpoint3 = socket1.remote_endpoint();
+ sp::endpoint endpoint4 = socket1.remote_endpoint(ec);
+
+ socket1.shutdown(socket_base::shutdown_both);
+ socket1.shutdown(socket_base::shutdown_both, ec);
+
+ // basic_stream_socket functions.
+
+ socket1.send(buffer(mutable_char_buffer));
+ socket1.send(buffer(const_char_buffer));
+ socket1.send(null_buffers());
+ socket1.send(buffer(mutable_char_buffer), in_flags);
+ socket1.send(buffer(const_char_buffer), in_flags);
+ socket1.send(null_buffers(), in_flags);
+ socket1.send(buffer(mutable_char_buffer), in_flags, ec);
+ socket1.send(buffer(const_char_buffer), in_flags, ec);
+ socket1.send(null_buffers(), in_flags, ec);
+
+ socket1.async_send(buffer(mutable_char_buffer), send_handler);
+ socket1.async_send(buffer(const_char_buffer), send_handler);
+ socket1.async_send(null_buffers(), send_handler);
+ socket1.async_send(buffer(mutable_char_buffer), in_flags, send_handler);
+ socket1.async_send(buffer(const_char_buffer), in_flags, send_handler);
+ socket1.async_send(null_buffers(), in_flags, send_handler);
+
+ socket1.receive(buffer(mutable_char_buffer));
+ socket1.receive(null_buffers());
+ socket1.receive(buffer(mutable_char_buffer), in_flags);
+ socket1.receive(null_buffers(), in_flags);
+ socket1.receive(buffer(mutable_char_buffer), in_flags, ec);
+ socket1.receive(null_buffers(), in_flags, ec);
+
+ socket1.async_receive(buffer(mutable_char_buffer), receive_handler);
+ socket1.async_receive(null_buffers(), receive_handler);
+ socket1.async_receive(buffer(mutable_char_buffer), in_flags,
+ receive_handler);
+ socket1.async_receive(null_buffers(), in_flags, receive_handler);
+
+ socket1.write_some(buffer(mutable_char_buffer));
+ socket1.write_some(buffer(const_char_buffer));
+ socket1.write_some(null_buffers());
+ socket1.write_some(buffer(mutable_char_buffer), ec);
+ socket1.write_some(buffer(const_char_buffer), ec);
+ socket1.write_some(null_buffers(), ec);
+
+ socket1.async_write_some(buffer(mutable_char_buffer), write_some_handler);
+ socket1.async_write_some(buffer(const_char_buffer), write_some_handler);
+ socket1.async_write_some(null_buffers(), write_some_handler);
+
+ socket1.read_some(buffer(mutable_char_buffer));
+ socket1.read_some(buffer(mutable_char_buffer), ec);
+ socket1.read_some(null_buffers(), ec);
+
+ socket1.async_read_some(buffer(mutable_char_buffer), read_some_handler);
+ socket1.async_read_some(null_buffers(), read_some_handler);
+ }
+ catch (std::exception&)
+ {
+ }
+#endif // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
+}
+
+} // namespace local_stream_protocol_socket_compile
+
+//------------------------------------------------------------------------------
+
+test_suite* init_unit_test_suite(int argc, char* argv[])
+{
+ test_suite* test = BOOST_TEST_SUITE("local/stream_protocol");
+ test->add(BOOST_TEST_CASE(&local_stream_protocol_socket_compile::test));
+ return test;
+}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk