Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:42

0001 //
0002 // detail/posix_fd_set_adapter.hpp
0003 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 
0011 #ifndef BOOST_ASIO_DETAIL_POSIX_FD_SET_ADAPTER_HPP
0012 #define BOOST_ASIO_DETAIL_POSIX_FD_SET_ADAPTER_HPP
0013 
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 
0018 #include <boost/asio/detail/config.hpp>
0019 
0020 #if !defined(BOOST_ASIO_WINDOWS) \
0021   && !defined(__CYGWIN__) \
0022   && !defined(BOOST_ASIO_WINDOWS_RUNTIME)
0023 
0024 #include <cstring>
0025 #include <boost/asio/detail/noncopyable.hpp>
0026 #include <boost/asio/detail/reactor_op_queue.hpp>
0027 #include <boost/asio/detail/socket_types.hpp>
0028 
0029 #include <boost/asio/detail/push_options.hpp>
0030 
0031 namespace boost {
0032 namespace asio {
0033 namespace detail {
0034 
0035 // Adapts the FD_SET type to meet the Descriptor_Set concept's requirements.
0036 class posix_fd_set_adapter : noncopyable
0037 {
0038 public:
0039   posix_fd_set_adapter()
0040     : max_descriptor_(invalid_socket)
0041   {
0042     using namespace std; // Needed for memset on Solaris.
0043     FD_ZERO(&fd_set_);
0044   }
0045 
0046   void reset()
0047   {
0048     using namespace std; // Needed for memset on Solaris.
0049     FD_ZERO(&fd_set_);
0050   }
0051 
0052   bool set(socket_type descriptor)
0053   {
0054     if (descriptor < (socket_type)FD_SETSIZE)
0055     {
0056       if (max_descriptor_ == invalid_socket || descriptor > max_descriptor_)
0057         max_descriptor_ = descriptor;
0058       FD_SET(descriptor, &fd_set_);
0059       return true;
0060     }
0061     return false;
0062   }
0063 
0064   void set(reactor_op_queue<socket_type>& operations, op_queue<operation>& ops)
0065   {
0066     reactor_op_queue<socket_type>::iterator i = operations.begin();
0067     while (i != operations.end())
0068     {
0069       reactor_op_queue<socket_type>::iterator op_iter = i++;
0070       if (!set(op_iter->first))
0071       {
0072         boost::system::error_code ec(error::fd_set_failure);
0073         operations.cancel_operations(op_iter, ops, ec);
0074       }
0075     }
0076   }
0077 
0078   bool is_set(socket_type descriptor) const
0079   {
0080     return FD_ISSET(descriptor, &fd_set_) != 0;
0081   }
0082 
0083   operator fd_set*()
0084   {
0085     return &fd_set_;
0086   }
0087 
0088   socket_type max_descriptor() const
0089   {
0090     return max_descriptor_;
0091   }
0092 
0093   void perform(reactor_op_queue<socket_type>& operations,
0094       op_queue<operation>& ops) const
0095   {
0096     reactor_op_queue<socket_type>::iterator i = operations.begin();
0097     while (i != operations.end())
0098     {
0099       reactor_op_queue<socket_type>::iterator op_iter = i++;
0100       if (is_set(op_iter->first))
0101         operations.perform_operations(op_iter, ops);
0102     }
0103   }
0104 
0105 private:
0106   mutable fd_set fd_set_;
0107   socket_type max_descriptor_;
0108 };
0109 
0110 } // namespace detail
0111 } // namespace asio
0112 } // namespace boost
0113 
0114 #include <boost/asio/detail/pop_options.hpp>
0115 
0116 #endif // !defined(BOOST_ASIO_WINDOWS)
0117        // && !defined(__CYGWIN__)
0118        // && !defined(BOOST_ASIO_WINDOWS_RUNTIME)
0119 
0120 #endif // BOOST_ASIO_DETAIL_POSIX_FD_SET_ADAPTER_HPP