2 // detail/posix_fd_set_adapter.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef BOOST_ASIO_DETAIL_POSIX_FD_SET_ADAPTER_HPP
12 #define BOOST_ASIO_DETAIL_POSIX_FD_SET_ADAPTER_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
20 #if !defined(BOOST_ASIO_WINDOWS) \
21 && !defined(__CYGWIN__) \
22 && !defined(BOOST_ASIO_WINDOWS_RUNTIME)
25 #include <boost/asio/detail/noncopyable.hpp>
26 #include <boost/asio/detail/reactor_op_queue.hpp>
27 #include <boost/asio/detail/socket_types.hpp>
29 #include <boost/asio/detail/push_options.hpp>
35 // Adapts the FD_SET type to meet the Descriptor_Set concept's requirements.
36 class posix_fd_set_adapter : noncopyable
39 posix_fd_set_adapter()
40 : max_descriptor_(invalid_socket)
42 using namespace std; // Needed for memset on Solaris.
48 using namespace std; // Needed for memset on Solaris.
52 bool set(socket_type descriptor)
54 if (descriptor < (socket_type)FD_SETSIZE)
56 if (max_descriptor_ == invalid_socket || descriptor > max_descriptor_)
57 max_descriptor_ = descriptor;
58 FD_SET(descriptor, &fd_set_);
64 void set(reactor_op_queue<socket_type>& operations, op_queue<operation>& ops)
66 reactor_op_queue<socket_type>::iterator i = operations.begin();
67 while (i != operations.end())
69 reactor_op_queue<socket_type>::iterator op_iter = i++;
70 if (!set(op_iter->first))
72 boost::system::error_code ec(error::fd_set_failure);
73 operations.cancel_operations(op_iter, ops, ec);
78 bool is_set(socket_type descriptor) const
80 return FD_ISSET(descriptor, &fd_set_) != 0;
88 socket_type max_descriptor() const
90 return max_descriptor_;
93 void perform(reactor_op_queue<socket_type>& operations,
94 op_queue<operation>& ops) const
96 reactor_op_queue<socket_type>::iterator i = operations.begin();
97 while (i != operations.end())
99 reactor_op_queue<socket_type>::iterator op_iter = i++;
100 if (is_set(op_iter->first))
101 operations.perform_operations(op_iter, ops);
106 mutable fd_set fd_set_;
107 socket_type max_descriptor_;
110 } // namespace detail
114 #include <boost/asio/detail/pop_options.hpp>
116 #endif // !defined(BOOST_ASIO_WINDOWS)
117 // && !defined(__CYGWIN__)
118 // && !defined(BOOST_ASIO_WINDOWS_RUNTIME)
120 #endif // BOOST_ASIO_DETAIL_POSIX_FD_SET_ADAPTER_HPP