Boost logo

Boost-Commit :

From: chris_at_[hidden]
Date: 2007-11-28 08:26:33


Author: chris_kohlhoff
Date: 2007-11-28 08:26:33 EST (Wed, 28 Nov 2007)
New Revision: 41432
URL: http://svn.boost.org/trac/boost/changeset/41432

Log:
Make async operations fail with an error if the socket descriptor doesn't
fit into the select call's fd_set.

Text files modified:
   trunk/boost/asio/detail/posix_fd_set_adapter.hpp | 13 +++++++++----
   trunk/boost/asio/detail/reactor_op_queue.hpp | 7 ++++++-
   trunk/boost/asio/detail/win_fd_set_adapter.hpp | 8 ++++++--
   trunk/boost/asio/error.hpp | 7 ++++++-
   4 files changed, 27 insertions(+), 8 deletions(-)

Modified: trunk/boost/asio/detail/posix_fd_set_adapter.hpp
==============================================================================
--- trunk/boost/asio/detail/posix_fd_set_adapter.hpp (original)
+++ trunk/boost/asio/detail/posix_fd_set_adapter.hpp 2007-11-28 08:26:33 EST (Wed, 28 Nov 2007)
@@ -36,11 +36,16 @@
     FD_ZERO(&fd_set_);
   }
 
- void set(socket_type descriptor)
+ bool set(socket_type descriptor)
   {
- if (max_descriptor_ == invalid_socket || descriptor > max_descriptor_)
- max_descriptor_ = descriptor;
- FD_SET(descriptor, &fd_set_);
+ if (descriptor < FD_SETSIZE)
+ {
+ if (max_descriptor_ == invalid_socket || descriptor > max_descriptor_)
+ max_descriptor_ = descriptor;
+ FD_SET(descriptor, &fd_set_);
+ return true;
+ }
+ return false;
   }
 
   bool is_set(socket_type descriptor) const

Modified: trunk/boost/asio/detail/reactor_op_queue.hpp
==============================================================================
--- trunk/boost/asio/detail/reactor_op_queue.hpp (original)
+++ trunk/boost/asio/detail/reactor_op_queue.hpp 2007-11-28 08:26:33 EST (Wed, 28 Nov 2007)
@@ -174,8 +174,13 @@
     typename operation_map::iterator i = operations_.begin();
     while (i != operations_.end())
     {
- descriptors.set(i->first);
+ Descriptor descriptor = i->first;
       ++i;
+ if (!descriptors.set(descriptor))
+ {
+ boost::system::error_code ec(error::fd_set_failure);
+ dispatch_all_operations(descriptor, ec);
+ }
     }
   }
 

Modified: trunk/boost/asio/detail/win_fd_set_adapter.hpp
==============================================================================
--- trunk/boost/asio/detail/win_fd_set_adapter.hpp (original)
+++ trunk/boost/asio/detail/win_fd_set_adapter.hpp 2007-11-28 08:26:33 EST (Wed, 28 Nov 2007)
@@ -37,13 +37,17 @@
     fd_set_.fd_count = 0;
   }
 
- void set(socket_type descriptor)
+ bool set(socket_type descriptor)
   {
     for (u_int i = 0; i < fd_set_.fd_count; ++i)
       if (fd_set_.fd_array[i] == descriptor)
- return;
+ return true;
     if (fd_set_.fd_count < win_fd_set_size)
+ {
       fd_set_.fd_array[fd_set_.fd_count++] = descriptor;
+ return true;
+ }
+ return false;
   }
 
   bool is_set(socket_type descriptor) const

Modified: trunk/boost/asio/error.hpp
==============================================================================
--- trunk/boost/asio/error.hpp (original)
+++ trunk/boost/asio/error.hpp 2007-11-28 08:26:33 EST (Wed, 28 Nov 2007)
@@ -195,7 +195,10 @@
   eof,
 
   /// Element not found.
- not_found
+ not_found,
+
+ /// The descriptor cannot fit into the select system call's fd_set.
+ fd_set_failure
 };
 
 enum ssl_errors
@@ -301,6 +304,8 @@
       return "End of file";
     if (value == error::not_found)
       return "Element not found";
+ if (value == error::fd_set_failure)
+ return "The descriptor does not fit into the select call's fd_set";
     return "asio.misc error";
   }
 };


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