Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r74818 - in trunk/boost/asio/detail: . impl
From: chris_at_[hidden]
Date: 2011-10-08 17:15:44


Author: chris_kohlhoff
Date: 2011-10-08 17:15:42 EDT (Sat, 08 Oct 2011)
New Revision: 74818
URL: http://svn.boost.org/trac/boost/changeset/74818

Log:
Make sure the synchronous null_buffers operations obey the user's non_blocking setting. Refs #5756

Text files modified:
   trunk/boost/asio/detail/descriptor_ops.hpp | 6 ++-
   trunk/boost/asio/detail/impl/descriptor_ops.ipp | 24 +++++++++++-----
   trunk/boost/asio/detail/impl/socket_ops.ipp | 58 +++++++++++++++++++++++----------------
   trunk/boost/asio/detail/reactive_descriptor_service.hpp | 4 +-
   trunk/boost/asio/detail/reactive_socket_service.hpp | 4 +-
   trunk/boost/asio/detail/reactive_socket_service_base.hpp | 6 ++--
   trunk/boost/asio/detail/socket_ops.hpp | 6 ++-
   trunk/boost/asio/detail/win_iocp_socket_service.hpp | 4 +-
   trunk/boost/asio/detail/win_iocp_socket_service_base.hpp | 6 ++--
   9 files changed, 70 insertions(+), 48 deletions(-)

Modified: trunk/boost/asio/detail/descriptor_ops.hpp
==============================================================================
--- trunk/boost/asio/detail/descriptor_ops.hpp (original)
+++ trunk/boost/asio/detail/descriptor_ops.hpp 2011-10-08 17:15:42 EDT (Sat, 08 Oct 2011)
@@ -93,9 +93,11 @@
 BOOST_ASIO_DECL int fcntl(int d, long cmd,
     long arg, boost::system::error_code& ec);
 
-BOOST_ASIO_DECL int poll_read(int d, boost::system::error_code& ec);
+BOOST_ASIO_DECL int poll_read(int d,
+ state_type state, boost::system::error_code& ec);
 
-BOOST_ASIO_DECL int poll_write(int d, boost::system::error_code& ec);
+BOOST_ASIO_DECL int poll_write(int d,
+ state_type state, boost::system::error_code& ec);
 
 } // namespace descriptor_ops
 } // namespace detail

Modified: trunk/boost/asio/detail/impl/descriptor_ops.ipp
==============================================================================
--- trunk/boost/asio/detail/impl/descriptor_ops.ipp (original)
+++ trunk/boost/asio/detail/impl/descriptor_ops.ipp 2011-10-08 17:15:42 EDT (Sat, 08 Oct 2011)
@@ -203,7 +203,7 @@
       return 0;
 
     // Wait for descriptor to become ready.
- if (descriptor_ops::poll_read(d, ec) < 0)
+ if (descriptor_ops::poll_read(d, 0, ec) < 0)
       return 0;
   }
 }
@@ -280,7 +280,7 @@
       return 0;
 
     // Wait for descriptor to become ready.
- if (descriptor_ops::poll_write(d, ec) < 0)
+ if (descriptor_ops::poll_write(d, 0, ec) < 0)
       return 0;
   }
 }
@@ -387,7 +387,7 @@
   return result;
 }
 
-int poll_read(int d, boost::system::error_code& ec)
+int poll_read(int d, state_type state, boost::system::error_code& ec)
 {
   if (d == -1)
   {
@@ -399,14 +399,18 @@
   fds.fd = d;
   fds.events = POLLIN;
   fds.revents = 0;
+ int timeout = (state & user_set_non_blocking) ? 0 : -1;
   errno = 0;
- int result = error_wrapper(::poll(&fds, 1, -1), ec);
- if (result >= 0)
+ int result = error_wrapper(::poll(&fds, 1, timeout), ec);
+ if (result == 0)
+ ec = (state & user_set_non_blocking)
+ ? boost::asio::error::would_block : boost::system::error_code();
+ else if (result > 0)
     ec = boost::system::error_code();
   return result;
 }
 
-int poll_write(int d, boost::system::error_code& ec)
+int poll_write(int d, state_type state, boost::system::error_code& ec)
 {
   if (d == -1)
   {
@@ -418,9 +422,13 @@
   fds.fd = d;
   fds.events = POLLOUT;
   fds.revents = 0;
+ int timeout = (state & user_set_non_blocking) ? 0 : -1;
   errno = 0;
- int result = error_wrapper(::poll(&fds, 1, -1), ec);
- if (result >= 0)
+ int result = error_wrapper(::poll(&fds, 1, timeout), ec);
+ if (result == 0)
+ ec = (state & user_set_non_blocking)
+ ? boost::asio::error::would_block : boost::system::error_code();
+ else if (result > 0)
     ec = boost::system::error_code();
   return result;
 }

Modified: trunk/boost/asio/detail/impl/socket_ops.ipp
==============================================================================
--- trunk/boost/asio/detail/impl/socket_ops.ipp (original)
+++ trunk/boost/asio/detail/impl/socket_ops.ipp 2011-10-08 17:15:42 EDT (Sat, 08 Oct 2011)
@@ -148,7 +148,7 @@
       return invalid_socket;
 
     // Wait for socket to become ready.
- if (socket_ops::poll_read(s, ec) < 0)
+ if (socket_ops::poll_read(s, 0, ec) < 0)
       return invalid_socket;
   }
 }
@@ -735,7 +735,7 @@
       return 0;
 
     // Wait for socket to become ready.
- if (socket_ops::poll_read(s, ec) < 0)
+ if (socket_ops::poll_read(s, 0, ec) < 0)
       return 0;
   }
 }
@@ -873,7 +873,7 @@
       return 0;
 
     // Wait for socket to become ready.
- if (socket_ops::poll_read(s, ec) < 0)
+ if (socket_ops::poll_read(s, 0, ec) < 0)
       return 0;
   }
 }
@@ -984,7 +984,7 @@
       return 0;
 
     // Wait for socket to become ready.
- if (socket_ops::poll_read(s, ec) < 0)
+ if (socket_ops::poll_read(s, 0, ec) < 0)
       return 0;
   }
 }
@@ -1110,7 +1110,7 @@
       return 0;
 
     // Wait for socket to become ready.
- if (socket_ops::poll_write(s, ec) < 0)
+ if (socket_ops::poll_write(s, 0, ec) < 0)
       return 0;
   }
 }
@@ -1233,7 +1233,7 @@
       return 0;
 
     // Wait for socket to become ready.
- if (socket_ops::poll_write(s, ec) < 0)
+ if (socket_ops::poll_write(s, 0, ec) < 0)
       return 0;
   }
 }
@@ -1683,7 +1683,7 @@
 #endif
 }
 
-int poll_read(socket_type s, boost::system::error_code& ec)
+int poll_read(socket_type s, state_type state, boost::system::error_code& ec)
 {
   if (s == invalid_socket)
   {
@@ -1697,11 +1697,12 @@
   fd_set fds;
   FD_ZERO(&fds);
   FD_SET(s, &fds);
+ timeval zero_timeout;
+ zero_timeout.tv_sec = 0;
+ zero_timeout.tv_usec = 0;
+ timeval* timeout = (state & user_set_non_blocking) ? &zero_timeout : 0;
   clear_last_error();
- int result = error_wrapper(::select(s, &fds, 0, 0, 0), ec);
- if (result >= 0)
- ec = boost::system::error_code();
- return result;
+ int result = error_wrapper(::select(s, &fds, 0, 0, timeout), ec);
 #else // defined(BOOST_WINDOWS)
       // || defined(__CYGWIN__)
       // || defined(__SYMBIAN32__)
@@ -1709,17 +1710,21 @@
   fds.fd = s;
   fds.events = POLLIN;
   fds.revents = 0;
+ int timeout = (state & user_set_non_blocking) ? 0 : -1;
   clear_last_error();
- int result = error_wrapper(::poll(&fds, 1, -1), ec);
- if (result >= 0)
- ec = boost::system::error_code();
- return result;
+ int result = error_wrapper(::poll(&fds, 1, timeout), ec);
 #endif // defined(BOOST_WINDOWS)
        // || defined(__CYGWIN__)
        // || defined(__SYMBIAN32__)
+ if (result == 0)
+ ec = (state & user_set_non_blocking)
+ ? boost::asio::error::would_block : boost::system::error_code();
+ else if (result > 0)
+ ec = boost::system::error_code();
+ return result;
 }
 
-int poll_write(socket_type s, boost::system::error_code& ec)
+int poll_write(socket_type s, state_type state, boost::system::error_code& ec)
 {
   if (s == invalid_socket)
   {
@@ -1733,11 +1738,12 @@
   fd_set fds;
   FD_ZERO(&fds);
   FD_SET(s, &fds);
+ timeval zero_timeout;
+ zero_timeout.tv_sec = 0;
+ zero_timeout.tv_usec = 0;
+ timeval* timeout = (state & user_set_non_blocking) ? &zero_timeout : 0;
   clear_last_error();
- int result = error_wrapper(::select(s, 0, &fds, 0, 0), ec);
- if (result >= 0)
- ec = boost::system::error_code();
- return result;
+ int result = error_wrapper(::select(s, 0, &fds, 0, timeout), ec);
 #else // defined(BOOST_WINDOWS)
       // || defined(__CYGWIN__)
       // || defined(__SYMBIAN32__)
@@ -1745,14 +1751,18 @@
   fds.fd = s;
   fds.events = POLLOUT;
   fds.revents = 0;
+ int timeout = (state & user_set_non_blocking) ? 0 : -1;
   clear_last_error();
- int result = error_wrapper(::poll(&fds, 1, -1), ec);
- if (result >= 0)
- ec = boost::system::error_code();
- return result;
+ int result = error_wrapper(::poll(&fds, 1, timeout), ec);
 #endif // defined(BOOST_WINDOWS)
        // || defined(__CYGWIN__)
        // || defined(__SYMBIAN32__)
+ if (result == 0)
+ ec = (state & user_set_non_blocking)
+ ? boost::asio::error::would_block : boost::system::error_code();
+ else if (result > 0)
+ ec = boost::system::error_code();
+ return result;
 }
 
 int poll_connect(socket_type s, boost::system::error_code& ec)

Modified: trunk/boost/asio/detail/reactive_descriptor_service.hpp
==============================================================================
--- trunk/boost/asio/detail/reactive_descriptor_service.hpp (original)
+++ trunk/boost/asio/detail/reactive_descriptor_service.hpp 2011-10-08 17:15:42 EDT (Sat, 08 Oct 2011)
@@ -177,7 +177,7 @@
       const null_buffers&, boost::system::error_code& ec)
   {
     // Wait for descriptor to become ready.
- descriptor_ops::poll_write(impl.descriptor_, ec);
+ descriptor_ops::poll_write(impl.descriptor_, impl.state_, ec);
 
     return 0;
   }
@@ -239,7 +239,7 @@
       const null_buffers&, boost::system::error_code& ec)
   {
     // Wait for descriptor to become ready.
- descriptor_ops::poll_read(impl.descriptor_, ec);
+ descriptor_ops::poll_read(impl.descriptor_, impl.state_, ec);
 
     return 0;
   }

Modified: trunk/boost/asio/detail/reactive_socket_service.hpp
==============================================================================
--- trunk/boost/asio/detail/reactive_socket_service.hpp (original)
+++ trunk/boost/asio/detail/reactive_socket_service.hpp 2011-10-08 17:15:42 EDT (Sat, 08 Oct 2011)
@@ -204,7 +204,7 @@
       boost::system::error_code& ec)
   {
     // Wait for socket to become ready.
- socket_ops::poll_write(impl.socket_, ec);
+ socket_ops::poll_write(impl.socket_, impl.state_, ec);
 
     return 0;
   }
@@ -278,7 +278,7 @@
       boost::system::error_code& ec)
   {
     // Wait for socket to become ready.
- socket_ops::poll_read(impl.socket_, ec);
+ socket_ops::poll_read(impl.socket_, impl.state_, ec);
 
     // Reset endpoint since it can be given no sensible value at this time.
     sender_endpoint = endpoint_type();

Modified: trunk/boost/asio/detail/reactive_socket_service_base.hpp
==============================================================================
--- trunk/boost/asio/detail/reactive_socket_service_base.hpp (original)
+++ trunk/boost/asio/detail/reactive_socket_service_base.hpp 2011-10-08 17:15:42 EDT (Sat, 08 Oct 2011)
@@ -188,7 +188,7 @@
       socket_base::message_flags, boost::system::error_code& ec)
   {
     // Wait for socket to become ready.
- socket_ops::poll_write(impl.socket_, ec);
+ socket_ops::poll_write(impl.socket_, impl.state_, ec);
 
     return 0;
   }
@@ -253,7 +253,7 @@
       socket_base::message_flags, boost::system::error_code& ec)
   {
     // Wait for socket to become ready.
- socket_ops::poll_read(impl.socket_, ec);
+ socket_ops::poll_read(impl.socket_, impl.state_, ec);
 
     return 0;
   }
@@ -327,7 +327,7 @@
       socket_base::message_flags& out_flags, boost::system::error_code& ec)
   {
     // Wait for socket to become ready.
- socket_ops::poll_read(impl.socket_, ec);
+ socket_ops::poll_read(impl.socket_, impl.state_, ec);
 
     // Clear out_flags, since we cannot give it any other sensible value when
     // performing a null_buffers operation.

Modified: trunk/boost/asio/detail/socket_ops.hpp
==============================================================================
--- trunk/boost/asio/detail/socket_ops.hpp (original)
+++ trunk/boost/asio/detail/socket_ops.hpp 2011-10-08 17:15:42 EDT (Sat, 08 Oct 2011)
@@ -254,9 +254,11 @@
 BOOST_ASIO_DECL int select(int nfds, fd_set* readfds, fd_set* writefds,
     fd_set* exceptfds, timeval* timeout, boost::system::error_code& ec);
 
-BOOST_ASIO_DECL int poll_read(socket_type s, boost::system::error_code& ec);
+BOOST_ASIO_DECL int poll_read(socket_type s,
+ state_type state, boost::system::error_code& ec);
 
-BOOST_ASIO_DECL int poll_write(socket_type s, boost::system::error_code& ec);
+BOOST_ASIO_DECL int poll_write(socket_type s,
+ state_type state, boost::system::error_code& ec);
 
 BOOST_ASIO_DECL int poll_connect(socket_type s, boost::system::error_code& ec);
 

Modified: trunk/boost/asio/detail/win_iocp_socket_service.hpp
==============================================================================
--- trunk/boost/asio/detail/win_iocp_socket_service.hpp (original)
+++ trunk/boost/asio/detail/win_iocp_socket_service.hpp 2011-10-08 17:15:42 EDT (Sat, 08 Oct 2011)
@@ -281,7 +281,7 @@
       boost::system::error_code& ec)
   {
     // Wait for socket to become ready.
- socket_ops::poll_write(impl.socket_, ec);
+ socket_ops::poll_write(impl.socket_, impl.state_, ec);
 
     return 0;
   }
@@ -358,7 +358,7 @@
       socket_base::message_flags, boost::system::error_code& ec)
   {
     // Wait for socket to become ready.
- socket_ops::poll_read(impl.socket_, ec);
+ socket_ops::poll_read(impl.socket_, impl.state_, ec);
 
     // Reset endpoint since it can be given no sensible value at this time.
     sender_endpoint = endpoint_type();

Modified: trunk/boost/asio/detail/win_iocp_socket_service_base.hpp
==============================================================================
--- trunk/boost/asio/detail/win_iocp_socket_service_base.hpp (original)
+++ trunk/boost/asio/detail/win_iocp_socket_service_base.hpp 2011-10-08 17:15:42 EDT (Sat, 08 Oct 2011)
@@ -206,7 +206,7 @@
       socket_base::message_flags, boost::system::error_code& ec)
   {
     // Wait for socket to become ready.
- socket_ops::poll_write(impl.socket_, ec);
+ socket_ops::poll_write(impl.socket_, impl.state_, ec);
 
     return 0;
   }
@@ -273,7 +273,7 @@
       socket_base::message_flags, boost::system::error_code& ec)
   {
     // Wait for socket to become ready.
- socket_ops::poll_read(impl.socket_, ec);
+ socket_ops::poll_read(impl.socket_, impl.state_, ec);
 
     return 0;
   }
@@ -343,7 +343,7 @@
       socket_base::message_flags& out_flags, boost::system::error_code& ec)
   {
     // Wait for socket to become ready.
- socket_ops::poll_read(impl.socket_, ec);
+ socket_ops::poll_read(impl.socket_, impl.state_, ec);
 
     // Clear out_flags, since we cannot give it any other sensible value when
     // performing a null_buffers operation.


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