Boost logo

Boost-Commit :

From: chris_at_[hidden]
Date: 2007-09-21 08:34:19


Author: chris_kohlhoff
Date: 2007-09-21 08:34:19 EDT (Fri, 21 Sep 2007)
New Revision: 39443
URL: http://svn.boost.org/trac/boost/changeset/39443

Log:
Strict compilers don't like it when you pass a function with C linkage
as an argument when the parameter type has C++ linkage. Try using the type
of the msghdr::msg_namelen field as an alternative way of deducing the
socklen_t-equivalent type.

Text files modified:
   trunk/boost/asio/detail/socket_ops.hpp | 91 ++++++++++++++++++---------------------
   1 files changed, 42 insertions(+), 49 deletions(-)

Modified: trunk/boost/asio/detail/socket_ops.hpp
==============================================================================
--- trunk/boost/asio/detail/socket_ops.hpp (original)
+++ trunk/boost/asio/detail/socket_ops.hpp 2007-09-21 08:34:19 EDT (Fri, 21 Sep 2007)
@@ -31,17 +31,15 @@
 #include <boost/asio/error.hpp>
 #include <boost/asio/detail/socket_types.hpp>
 
-#if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
-# define BOOST_ASIO_SOCKET_CALL __stdcall
-#else
-# define BOOST_ASIO_SOCKET_CALL
-#endif
-
 namespace boost {
 namespace asio {
 namespace detail {
 namespace socket_ops {
 
+#if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
+struct msghdr { int msg_namelen; };
+#endif // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
+
 inline void clear_error(boost::system::error_code& ec)
 {
   errno = 0;
@@ -64,13 +62,12 @@
   return return_value;
 }
 
-template <typename R, typename Arg1, typename Arg2, typename Arg3>
-inline socket_type call_accept(
- R (BOOST_ASIO_SOCKET_CALL*)(Arg1, Arg2, Arg3*),
+template <typename SockLenType>
+inline socket_type call_accept(SockLenType msghdr::*,
     socket_type s, socket_addr_type* addr, std::size_t* addrlen)
 {
- Arg3 tmp_addrlen = addrlen ? (Arg3)*addrlen : 0;
- R result = ::accept(s, addr, addrlen ? &tmp_addrlen : 0);
+ SockLenType tmp_addrlen = addrlen ? (SockLenType)*addrlen : 0;
+ socket_type result = ::accept(s, addr, addrlen ? &tmp_addrlen : 0);
   if (addrlen)
     *addrlen = (std::size_t)tmp_addrlen;
   return result;
@@ -82,7 +79,7 @@
   clear_error(ec);
 
   socket_type new_s = error_wrapper(call_accept(
- ::accept, s, addr, addrlen), ec);
+ &msghdr::msg_namelen, s, addr, addrlen), ec);
   if (new_s == invalid_socket)
     return new_s;
 
@@ -100,19 +97,18 @@
   return new_s;
 }
 
-template <typename R, typename Arg1, typename Arg2, typename Arg3>
-inline socket_type call_bind(
- R (BOOST_ASIO_SOCKET_CALL*)(Arg1, Arg2, Arg3),
+template <typename SockLenType>
+inline int call_bind(SockLenType msghdr::*,
     socket_type s, const socket_addr_type* addr, std::size_t addrlen)
 {
- return ::bind(s, addr, (Arg3)addrlen);
+ return ::bind(s, addr, (SockLenType)addrlen);
 }
 
 inline int bind(socket_type s, const socket_addr_type* addr,
     std::size_t addrlen, boost::system::error_code& ec)
 {
   clear_error(ec);
- return error_wrapper(call_bind(::bind, s, addr, addrlen), ec);
+ return error_wrapper(call_bind(&msghdr::msg_namelen, s, addr, addrlen), ec);
 }
 
 inline int close(socket_type s, boost::system::error_code& ec)
@@ -131,19 +127,19 @@
   return error_wrapper(::shutdown(s, what), ec);
 }
 
-template <typename R, typename Arg1, typename Arg2, typename Arg3>
-inline socket_type call_connect(
- R (BOOST_ASIO_SOCKET_CALL*)(Arg1, Arg2, Arg3),
+template <typename SockLenType>
+inline int call_connect(SockLenType msghdr::*,
     socket_type s, const socket_addr_type* addr, std::size_t addrlen)
 {
- return ::connect(s, addr, (Arg3)addrlen);
+ return ::connect(s, addr, (SockLenType)addrlen);
 }
 
 inline int connect(socket_type s, const socket_addr_type* addr,
     std::size_t addrlen, boost::system::error_code& ec)
 {
   clear_error(ec);
- return error_wrapper(call_connect(::connect, s, addr, addrlen), ec);
+ return error_wrapper(call_connect(
+ &msghdr::msg_namelen, s, addr, addrlen), ec);
 }
 
 inline int listen(socket_type s, int backlog, boost::system::error_code& ec)
@@ -346,14 +342,13 @@
 #endif
 }
 
-template <typename R, typename Arg1, typename Arg2,
- typename Arg3, typename Arg4, typename Arg5>
-inline socket_type call_setsockopt(
- R (BOOST_ASIO_SOCKET_CALL*)(Arg1, Arg2, Arg3, Arg4, Arg5),
+template <typename SockLenType>
+inline int call_setsockopt(SockLenType msghdr::*,
     socket_type s, int level, int optname,
     const void* optval, std::size_t optlen)
 {
- return ::setsockopt(s, level, optname, (Arg4)optval, (Arg5)optlen);
+ return ::setsockopt(s, level, optname,
+ (const char*)optval, (SockLenType)optlen);
 }
 
 inline int setsockopt(socket_type s, int level, int optname,
@@ -384,20 +379,18 @@
   return -1;
 #else // defined(__BORLANDC__)
   clear_error(ec);
- return error_wrapper(call_setsockopt(::setsockopt,
+ return error_wrapper(call_setsockopt(&msghdr::msg_namelen,
         s, level, optname, optval, optlen), ec);
 #endif // defined(__BORLANDC__)
 }
 
-template <typename R, typename Arg1, typename Arg2,
- typename Arg3, typename Arg4, typename Arg5>
-inline socket_type call_getsockopt(
- R (BOOST_ASIO_SOCKET_CALL*)(Arg1, Arg2, Arg3, Arg4, Arg5*),
+template <typename SockLenType>
+inline int call_getsockopt(SockLenType msghdr::*,
     socket_type s, int level, int optname,
- const void* optval, std::size_t* optlen)
+ void* optval, std::size_t* optlen)
 {
- Arg5 tmp_optlen = (Arg5)*optlen;
- R result = ::getsockopt(s, level, optname, (Arg4)optval, &tmp_optlen);
+ SockLenType tmp_optlen = (SockLenType)*optlen;
+ int result = ::getsockopt(s, level, optname, (char*)optval, &tmp_optlen);
   *optlen = (std::size_t)tmp_optlen;
   return result;
 }
@@ -443,7 +436,7 @@
   return -1;
 #elif defined(BOOST_WINDOWS) || defined(__CYGWIN__)
   clear_error(ec);
- int result = error_wrapper(call_getsockopt(::getsockopt,
+ int result = error_wrapper(call_getsockopt(&msghdr::msg_namelen,
         s, level, optname, optval, optlen), ec);
   if (result != 0 && level == IPPROTO_IPV6 && optname == IPV6_V6ONLY
       && ec.value() == WSAENOPROTOOPT && *optlen == sizeof(DWORD))
@@ -459,7 +452,7 @@
   return result;
 #else // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
   clear_error(ec);
- int result = error_wrapper(call_getsockopt(::getsockopt,
+ int result = error_wrapper(call_getsockopt(&msghdr::msg_namelen,
         s, level, optname, optval, optlen), ec);
 #if defined(__linux__)
   if (result == 0 && level == SOL_SOCKET && *optlen == sizeof(int)
@@ -477,13 +470,12 @@
 #endif // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
 }
 
-template <typename R, typename Arg1, typename Arg2, typename Arg3>
-inline socket_type call_getpeername(
- R (BOOST_ASIO_SOCKET_CALL*)(Arg1, Arg2, Arg3*),
+template <typename SockLenType>
+inline int call_getpeername(SockLenType msghdr::*,
     socket_type s, socket_addr_type* addr, std::size_t* addrlen)
 {
- Arg3 tmp_addrlen = (Arg3)*addrlen;
- R result = ::getpeername(s, addr, &tmp_addrlen);
+ SockLenType tmp_addrlen = (SockLenType)*addrlen;
+ int result = ::getpeername(s, addr, &tmp_addrlen);
   *addrlen = (std::size_t)tmp_addrlen;
   return result;
 }
@@ -492,16 +484,16 @@
     std::size_t* addrlen, boost::system::error_code& ec)
 {
   clear_error(ec);
- return error_wrapper(call_getpeername(::getpeername, s, addr, addrlen), ec);
+ return error_wrapper(call_getpeername(
+ &msghdr::msg_namelen, s, addr, addrlen), ec);
 }
 
-template <typename R, typename Arg1, typename Arg2, typename Arg3>
-inline socket_type call_getsockname(
- R (BOOST_ASIO_SOCKET_CALL*)(Arg1, Arg2, Arg3*),
+template <typename SockLenType>
+inline int call_getsockname(SockLenType msghdr::*,
     socket_type s, socket_addr_type* addr, std::size_t* addrlen)
 {
- Arg3 tmp_addrlen = (Arg3)*addrlen;
- R result = ::getsockname(s, addr, &tmp_addrlen);
+ SockLenType tmp_addrlen = (SockLenType)*addrlen;
+ int result = ::getsockname(s, addr, &tmp_addrlen);
   *addrlen = (std::size_t)tmp_addrlen;
   return result;
 }
@@ -510,7 +502,8 @@
     std::size_t* addrlen, boost::system::error_code& ec)
 {
   clear_error(ec);
- return error_wrapper(call_getsockname(::getsockname, s, addr, addrlen), ec);
+ return error_wrapper(call_getsockname(
+ &msghdr::msg_namelen, s, addr, addrlen), ec);
 }
 
 inline int ioctl(socket_type s, long cmd, ioctl_arg_type* arg,


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