Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r50949 - trunk/boost/asio/detail
From: chris_at_[hidden]
Date: 2009-02-01 08:25:05


Author: chris_kohlhoff
Date: 2009-02-01 08:25:05 EST (Sun, 01 Feb 2009)
New Revision: 50949
URL: http://svn.boost.org/trac/boost/changeset/50949

Log:
Clear the last error following a successful Windows API call, since some
socket providers may leave last error set even when the call succeeds.

Text files modified:
   trunk/boost/asio/detail/socket_ops.hpp | 48 ++++++++-------------------------------
   1 files changed, 10 insertions(+), 38 deletions(-)

Modified: trunk/boost/asio/detail/socket_ops.hpp
==============================================================================
--- trunk/boost/asio/detail/socket_ops.hpp (original)
+++ trunk/boost/asio/detail/socket_ops.hpp 2009-02-01 08:25:05 EST (Sun, 01 Feb 2009)
@@ -103,7 +103,7 @@
   }
 #endif
 
-#if defined(BOOST_WINDOWS) && defined(UNDER_CE)
+#if defined(BOOST_WINDOWS)
   clear_error(ec);
 #endif
 
@@ -123,7 +123,7 @@
   clear_error(ec);
   int result = error_wrapper(call_bind(
         &msghdr::msg_namelen, s, addr, addrlen), ec);
-#if defined(BOOST_WINDOWS) && defined(UNDER_CE)
+#if defined(BOOST_WINDOWS)
   if (result == 0)
     clear_error(ec);
 #endif
@@ -135,10 +135,8 @@
   clear_error(ec);
 #if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
   int result = error_wrapper(::closesocket(s), ec);
-# if defined(UNDER_CE)
   if (result == 0)
     clear_error(ec);
-# endif
   return result;
 #else // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
   return error_wrapper(::close(s), ec);
@@ -149,7 +147,7 @@
 {
   clear_error(ec);
   int result = error_wrapper(::shutdown(s, what), ec);
-#if defined(BOOST_WINDOWS) && defined(UNDER_CE)
+#if defined(BOOST_WINDOWS)
   if (result == 0)
     clear_error(ec);
 #endif
@@ -169,7 +167,7 @@
   clear_error(ec);
   int result = error_wrapper(call_connect(
         &msghdr::msg_namelen, s, addr, addrlen), ec);
-#if defined(BOOST_WINDOWS) && defined(UNDER_CE)
+#if defined(BOOST_WINDOWS)
   if (result == 0)
     clear_error(ec);
 #endif
@@ -196,7 +194,7 @@
 {
   clear_error(ec);
   int result = error_wrapper(::listen(s, backlog), ec);
-#if defined(BOOST_WINDOWS) && defined(UNDER_CE)
+#if defined(BOOST_WINDOWS)
   if (result == 0)
     clear_error(ec);
 #endif
@@ -277,9 +275,7 @@
         recv_buf_count, &bytes_transferred, &recv_flags, 0, 0), ec);
   if (result != 0)
     return -1;
-# if defined(UNDER_CE)
   clear_error(ec);
-# endif
   return bytes_transferred;
 #else // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
   msghdr msg = msghdr();
@@ -305,9 +301,7 @@
   *addrlen = (std::size_t)tmp_addrlen;
   if (result != 0)
     return -1;
-# if defined(UNDER_CE)
   clear_error(ec);
-# endif
   return bytes_transferred;
 #else // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
   msghdr msg = msghdr();
@@ -334,9 +328,7 @@
         send_buf_count, &bytes_transferred, send_flags, 0, 0), ec);
   if (result != 0)
     return -1;
-# if defined(UNDER_CE)
   clear_error(ec);
-# endif
   return bytes_transferred;
 #else // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
   msghdr msg = msghdr();
@@ -363,9 +355,7 @@
         static_cast<int>(addrlen), 0, 0), ec);
   if (result != 0)
     return -1;
-# if defined(UNDER_CE)
   clear_error(ec);
-# endif
   return bytes_transferred;
 #else // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
   msghdr msg = msghdr();
@@ -400,9 +390,7 @@
         reinterpret_cast<const char*>(&optval), sizeof(optval));
   }
 
-# if defined(UNDER_CE)
   clear_error(ec);
-# endif
 
   return s;
 #elif defined(__MACH__) && defined(__APPLE__) || defined(__FreeBSD__)
@@ -464,7 +452,7 @@
   clear_error(ec);
   int result = error_wrapper(call_setsockopt(&msghdr::msg_namelen,
         s, level, optname, optval, optlen), ec);
-# if defined(BOOST_WINDOWS) && defined(UNDER_CE)
+# if defined(BOOST_WINDOWS)
   if (result == 0)
     clear_error(ec);
 # endif
@@ -537,10 +525,8 @@
     *static_cast<DWORD*>(optval) = 1;
     clear_error(ec);
   }
-# if defined(UNDER_CE)
   if (result == 0)
     clear_error(ec);
-# endif
   return result;
 #else // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
   clear_error(ec);
@@ -578,7 +564,7 @@
   clear_error(ec);
   int result = error_wrapper(call_getpeername(
         &msghdr::msg_namelen, s, addr, addrlen), ec);
-#if defined(BOOST_WINDOWS) && defined(UNDER_CE)
+#if defined(BOOST_WINDOWS)
   if (result == 0)
     clear_error(ec);
 #endif
@@ -601,7 +587,7 @@
   clear_error(ec);
   int result = error_wrapper(call_getsockname(
         &msghdr::msg_namelen, s, addr, addrlen), ec);
-#if defined(BOOST_WINDOWS) && defined(UNDER_CE)
+#if defined(BOOST_WINDOWS)
   if (result == 0)
     clear_error(ec);
 #endif
@@ -614,10 +600,8 @@
   clear_error(ec);
 #if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
   int result = error_wrapper(::ioctlsocket(s, cmd, arg), ec);
-# if defined(UNDER_CE)
   if (result == 0)
     clear_error(ec);
-# endif
   return result;
 #else // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
   return error_wrapper(::ioctl(s, cmd, arg), ec);
@@ -659,7 +643,7 @@
 #else
   int result = error_wrapper(::select(nfds, readfds,
         writefds, exceptfds, timeout), ec);
-# if defined(BOOST_WINDOWS) && defined(UNDER_CE)
+# if defined(BOOST_WINDOWS)
   if (result >= 0)
     clear_error(ec);
 # endif
@@ -675,10 +659,8 @@
   FD_SET(s, &fds);
   clear_error(ec);
   int result = error_wrapper(::select(s, &fds, 0, 0, 0), ec);
-# if defined(UNDER_CE)
   if (result >= 0)
     clear_error(ec);
-# endif
   return result;
 #else // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
   pollfd fds;
@@ -698,10 +680,8 @@
   FD_SET(s, &fds);
   clear_error(ec);
   int result = error_wrapper(::select(s, 0, &fds, 0, 0), ec);
-# if defined(UNDER_CE)
   if (result >= 0)
     clear_error(ec);
-# endif
   return result;
 #else // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
   pollfd fds;
@@ -724,10 +704,8 @@
   FD_SET(s, &except_fds);
   clear_error(ec);
   int result = error_wrapper(::select(s, 0, &write_fds, &except_fds, 0), ec);
-# if defined(UNDER_CE)
   if (result >= 0)
     clear_error(ec);
-# endif
   return result;
 #else // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
   pollfd fds;
@@ -875,10 +853,8 @@
   if (result == socket_error_retval && !ec)
     ec = boost::asio::error::invalid_argument;
 
-#if defined(UNDER_CE)
   if (result != socket_error_retval)
     clear_error(ec);
-#endif
 
   return result == socket_error_retval ? -1 : 1;
 #else // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
@@ -907,7 +883,7 @@
 {
   clear_error(ec);
   int result = error_wrapper(::gethostname(name, namelen), ec);
-#if defined(BOOST_WINDOWS) && defined(UNDER_CE)
+#if defined(BOOST_WINDOWS)
   if (result == 0)
     clear_error(ec);
 #endif
@@ -950,9 +926,7 @@
   hostent* retval = error_wrapper(::gethostbyaddr(addr, length, af), ec);
   if (!retval)
     return 0;
-# if defined(UNDER_CE)
   clear_error(ec);
-# endif
   *result = *retval;
   return retval;
 #elif defined(__sun) || defined(__QNX__)
@@ -1001,9 +975,7 @@
   hostent* retval = error_wrapper(::gethostbyname(name), ec);
   if (!retval)
     return 0;
-# if defined(UNDER_CE)
   clear_error(ec);
-# endif
   *result = *retval;
   return result;
 #elif defined(__sun) || defined(__QNX__)


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