00001 // 00002 // posix_fd_set_adapter.hpp 00003 // ~~~~~~~~~~~~~~~~~~~~~~~~ 00004 // 00005 // Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com) 00006 // 00007 // Distributed under the Boost Software License, Version 1.0. (See accompanying 00008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 00009 // 00010 00011 #ifndef ASIO_DETAIL_POSIX_FD_SET_ADAPTER_HPP 00012 #define ASIO_DETAIL_POSIX_FD_SET_ADAPTER_HPP 00013 00014 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 00015 # pragma once 00016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 00017 00018 #include "asio/detail/push_options.hpp" 00019 00020 #include "asio/detail/socket_types.hpp" 00021 00022 #if !defined(BOOST_WINDOWS) && !defined(__CYGWIN__) 00023 00024 namespace asio { 00025 namespace detail { 00026 00027 // Adapts the FD_SET type to meet the Descriptor_Set concept's requirements. 00028 class posix_fd_set_adapter 00029 { 00030 public: 00031 posix_fd_set_adapter() 00032 : max_descriptor_(invalid_socket) 00033 { 00034 using namespace std; // Needed for memset on Solaris. 00035 FD_ZERO(&fd_set_); 00036 } 00037 00038 bool set(socket_type descriptor) 00039 { 00040 if (descriptor < (socket_type)FD_SETSIZE) 00041 { 00042 if (max_descriptor_ == invalid_socket || descriptor > max_descriptor_) 00043 max_descriptor_ = descriptor; 00044 FD_SET(descriptor, &fd_set_); 00045 return true; 00046 } 00047 return false; 00048 } 00049 00050 bool is_set(socket_type descriptor) const 00051 { 00052 return FD_ISSET(descriptor, &fd_set_) != 0; 00053 } 00054 00055 operator fd_set*() 00056 { 00057 return &fd_set_; 00058 } 00059 00060 socket_type max_descriptor() const 00061 { 00062 return max_descriptor_; 00063 } 00064 00065 private: 00066 mutable fd_set fd_set_; 00067 socket_type max_descriptor_; 00068 }; 00069 00070 } // namespace detail 00071 } // namespace asio 00072 00073 #endif // !defined(BOOST_WINDOWS) && !defined(__CYGWIN__) 00074 00075 #include "asio/detail/pop_options.hpp" 00076 00077 #endif // ASIO_DETAIL_POSIX_FD_SET_ADAPTER_HPP