~ubuntu-branches/ubuntu/intrepid/miro/intrepid

« back to all changes in this revision

Viewing changes to portable/libtorrent/include/libtorrent/asio/detail/win_fd_set_adapter.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Christopher James Halse Rogers
  • Date: 2008-02-09 13:37:10 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080209133710-9rs90q6gckvp1b6i
Tags: 1.1.2-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// win_fd_set_adapter.hpp
 
3
// ~~~~~~~~~~~~~~~~~~~~~~
 
4
//
 
5
// Copyright (c) 2003-2007 Christopher M. Kohlhoff (chris at kohlhoff dot com)
 
6
//
 
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)
 
9
//
 
10
 
 
11
#ifndef ASIO_DETAIL_WIN_FD_SET_ADAPTER_HPP
 
12
#define ASIO_DETAIL_WIN_FD_SET_ADAPTER_HPP
 
13
 
 
14
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
 
15
# pragma once
 
16
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
 
17
 
 
18
#include "asio/detail/push_options.hpp"
 
19
 
 
20
#include "asio/detail/socket_types.hpp"
 
21
 
 
22
#if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
 
23
 
 
24
namespace asio {
 
25
namespace detail {
 
26
 
 
27
// Adapts the FD_SET type to meet the Descriptor_Set concept's requirements.
 
28
class win_fd_set_adapter
 
29
{
 
30
public:
 
31
  enum { win_fd_set_size = 1024 };
 
32
 
 
33
  win_fd_set_adapter()
 
34
    : max_descriptor_(invalid_socket)
 
35
  {
 
36
    fd_set_.fd_count = 0;
 
37
  }
 
38
 
 
39
  void set(socket_type descriptor)
 
40
  {
 
41
    for (u_int i = 0; i < fd_set_.fd_count; ++i)
 
42
      if (fd_set_.fd_array[i] == descriptor)
 
43
        return;
 
44
    if (fd_set_.fd_count < win_fd_set_size)
 
45
      fd_set_.fd_array[fd_set_.fd_count++] = descriptor;
 
46
  }
 
47
 
 
48
  bool is_set(socket_type descriptor) const
 
49
  {
 
50
    return !!__WSAFDIsSet(descriptor,
 
51
        const_cast<fd_set*>(reinterpret_cast<const fd_set*>(&fd_set_)));
 
52
  }
 
53
 
 
54
  operator fd_set*()
 
55
  {
 
56
    return reinterpret_cast<fd_set*>(&fd_set_);
 
57
  }
 
58
 
 
59
  socket_type max_descriptor() const
 
60
  {
 
61
    return max_descriptor_;
 
62
  }
 
63
 
 
64
private:
 
65
  // This structure is defined to be compatible with the Windows API fd_set
 
66
  // structure, but without being dependent on the value of FD_SETSIZE.
 
67
  struct win_fd_set
 
68
  {
 
69
    u_int fd_count;
 
70
    SOCKET fd_array[win_fd_set_size];
 
71
  };
 
72
 
 
73
  win_fd_set fd_set_;
 
74
  socket_type max_descriptor_;
 
75
};
 
76
 
 
77
} // namespace detail
 
78
} // namespace asio
 
79
 
 
80
#endif // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
 
81
 
 
82
#include "asio/detail/pop_options.hpp"
 
83
 
 
84
#endif // ASIO_DETAIL_WIN_FD_SET_ADAPTER_HPP