win_fd_set_adapter.hpp
Go to the documentation of this file.
00001 //
00002 // win_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_WIN_FD_SET_ADAPTER_HPP
00012 #define ASIO_DETAIL_WIN_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 win_fd_set_adapter
00029 {
00030 public:
00031   enum { win_fd_set_size = 1024 };
00032 
00033   win_fd_set_adapter()
00034     : max_descriptor_(invalid_socket)
00035   {
00036     fd_set_.fd_count = 0;
00037   }
00038 
00039   bool set(socket_type descriptor)
00040   {
00041     for (u_int i = 0; i < fd_set_.fd_count; ++i)
00042       if (fd_set_.fd_array[i] == descriptor)
00043         return true;
00044     if (fd_set_.fd_count < win_fd_set_size)
00045     {
00046       fd_set_.fd_array[fd_set_.fd_count++] = descriptor;
00047       return true;
00048     }
00049     return false;
00050   }
00051 
00052   bool is_set(socket_type descriptor) const
00053   {
00054     return !!__WSAFDIsSet(descriptor,
00055         const_cast<fd_set*>(reinterpret_cast<const fd_set*>(&fd_set_)));
00056   }
00057 
00058   operator fd_set*()
00059   {
00060     return reinterpret_cast<fd_set*>(&fd_set_);
00061   }
00062 
00063   socket_type max_descriptor() const
00064   {
00065     return max_descriptor_;
00066   }
00067 
00068 private:
00069   // This structure is defined to be compatible with the Windows API fd_set
00070   // structure, but without being dependent on the value of FD_SETSIZE.
00071   struct win_fd_set
00072   {
00073     u_int fd_count;
00074     SOCKET fd_array[win_fd_set_size];
00075   };
00076 
00077   win_fd_set fd_set_;
00078   socket_type max_descriptor_;
00079 };
00080 
00081 } // namespace detail
00082 } // namespace asio
00083 
00084 #endif // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
00085 
00086 #include "asio/detail/pop_options.hpp"
00087 
00088 #endif // ASIO_DETAIL_WIN_FD_SET_ADAPTER_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


Castor
Author(s): Carpe Noctem
autogenerated on Fri Nov 8 2013 11:05:39