Boost logo

Boost-Commit :

From: chris_at_[hidden]
Date: 2007-09-01 02:25:58


Author: chris_kohlhoff
Date: 2007-09-01 02:25:55 EDT (Sat, 01 Sep 2007)
New Revision: 39095
URL: http://svn.boost.org/trac/boost/changeset/39095

Log:
Add AIX-specific compile time test for whether sockaddr_storage's family
field is called ss_family or __ss_family.

Text files modified:
   trunk/boost/asio/ip/basic_endpoint.hpp | 32 ++++++++++++++++++++++----------
   1 files changed, 22 insertions(+), 10 deletions(-)

Modified: trunk/boost/asio/ip/basic_endpoint.hpp
==============================================================================
--- trunk/boost/asio/ip/basic_endpoint.hpp (original)
+++ trunk/boost/asio/ip/basic_endpoint.hpp 2007-09-01 02:25:55 EDT (Sat, 01 Sep 2007)
@@ -173,7 +173,7 @@
   /// The protocol associated with the endpoint.
   protocol_type protocol() const
   {
- if (is_v4())
+ if (is_v4(data_))
       return InternetProtocol::v4();
     return InternetProtocol::v6();
   }
@@ -193,7 +193,7 @@
   /// Get the underlying size of the endpoint in the native type.
   size_type size() const
   {
- if (is_v4())
+ if (is_v4(data_))
       return sizeof(boost::asio::detail::sockaddr_in4_type);
     else
       return sizeof(boost::asio::detail::sockaddr_in6_type);
@@ -219,7 +219,7 @@
   /// the host's byte order.
   unsigned short port() const
   {
- if (is_v4())
+ if (is_v4(data_))
     {
       return boost::asio::detail::socket_ops::network_to_host_short(
           reinterpret_cast<const boost::asio::detail::sockaddr_in4_type&>(
@@ -237,7 +237,7 @@
   /// the host's byte order.
   void port(unsigned short port_num)
   {
- if (is_v4())
+ if (is_v4(data_))
     {
       reinterpret_cast<boost::asio::detail::sockaddr_in4_type&>(data_).sin_port
         = boost::asio::detail::socket_ops::host_to_network_short(port_num);
@@ -253,7 +253,7 @@
   boost::asio::ip::address address() const
   {
     using namespace std; // For memcpy.
- if (is_v4())
+ if (is_v4(data_))
     {
       const boost::asio::detail::sockaddr_in4_type& data
         = reinterpret_cast<const boost::asio::detail::sockaddr_in4_type&>(
@@ -307,14 +307,26 @@
 
 private:
   // Helper function to determine whether the endpoint is IPv4.
- bool is_v4() const
- {
 #if defined(_AIX)
- return data_.__ss_family == AF_INET;
+ template <typename T, unsigned short (T::*)> struct is_v4_helper {};
+
+ template <typename T>
+ static bool is_v4(const T& ss, is_v4_helper<T, &T::ss_family>* = 0)
+ {
+ return ss.ss_family == AF_INET;
+ }
+
+ template <typename T>
+ static bool is_v4(const T& ss, is_v4_helper<T, &T::__ss_family>* = 0)
+ {
+ return ss.__ss_family == AF_INET;
+ }
 #else
- return data_.ss_family == AF_INET;
-#endif
+ static bool is_v4(const boost::asio::detail::sockaddr_storage_type& ss)
+ {
+ return ss.ss_family == AF_INET;
   }
+#endif
 
   // The underlying IP socket address.
   boost::asio::detail::sockaddr_storage_type data_;


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