File indexing completed on 2025-01-18 09:28:42
0001
0002
0003
0004
0005
0006
0007
0008
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
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
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;
0043 FD_ZERO(&fd_set_);
0044 }
0045
0046 void reset()
0047 {
0048 using namespace std;
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 }
0111 }
0112 }
0113
0114 #include <boost/asio/detail/pop_options.hpp>
0115
0116 #endif
0117
0118
0119
0120 #endif