11 #ifndef ASIO_DETAIL_WIN_FD_SET_ADAPTER_HPP 12 #define ASIO_DETAIL_WIN_FD_SET_ADAPTER_HPP 14 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 20 #if defined(ASIO_WINDOWS) || defined(__CYGWIN__) 32 class win_fd_set_adapter : noncopyable
35 enum { default_fd_set_size = 1024 };
38 : capacity_(default_fd_set_size),
41 fd_set_ =
static_cast<win_fd_set*
>(::operator
new(
42 sizeof(win_fd_set) -
sizeof(SOCKET)
43 +
sizeof(SOCKET) * (capacity_)));
44 fd_set_->fd_count = 0;
49 ::operator
delete(fd_set_);
54 fd_set_->fd_count = 0;
60 for (u_int i = 0; i < fd_set_->fd_count; ++i)
61 if (fd_set_->fd_array[i] == descriptor)
64 reserve(fd_set_->fd_count + 1);
65 fd_set_->fd_array[fd_set_->fd_count++] = descriptor;
69 void set(reactor_op_queue<socket_type>& operations, op_queue<operation>&)
72 while (i != operations.end())
75 reserve(fd_set_->fd_count + 1);
76 fd_set_->fd_array[fd_set_->fd_count++] = op_iter->first;
82 return !!__WSAFDIsSet(descriptor,
83 const_cast<fd_set*>(reinterpret_cast<const fd_set*>(fd_set_)));
88 return reinterpret_cast<fd_set*
>(fd_set_);
93 return max_descriptor_;
96 void perform(reactor_op_queue<socket_type>& operations,
97 op_queue<operation>& ops)
const 99 for (u_int i = 0; i < fd_set_->fd_count; ++i)
100 operations.perform_operations(fd_set_->fd_array[i], ops);
115 void reserve(u_int n)
120 u_int new_capacity = capacity_ + capacity_ / 2;
121 if (new_capacity < n)
124 win_fd_set* new_fd_set =
static_cast<win_fd_set*
>(::operator
new(
125 sizeof(win_fd_set) -
sizeof(SOCKET)
126 +
sizeof(SOCKET) * (new_capacity)));
128 new_fd_set->fd_count = fd_set_->fd_count;
129 for (u_int i = 0; i < fd_set_->fd_count; ++i)
130 new_fd_set->fd_array[i] = fd_set_->fd_array[i];
132 ::
operator delete(fd_set_);
133 fd_set_ = new_fd_set;
134 capacity_ = new_capacity;
147 #endif // defined(ASIO_WINDOWS) || defined(__CYGWIN__) 149 #endif // ASIO_DETAIL_WIN_FD_SET_ADAPTER_HPP
hash_map< key_type, mapped_type >::iterator iterator