~ubuntu-branches/ubuntu/maverick/libtorrent-rasterbar/maverick

« back to all changes in this revision

Viewing changes to include/libtorrent/asio/posix/stream_descriptor_service.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Sauthier
  • Date: 2010-08-10 12:59:37 UTC
  • mfrom: (1.3.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20100810125937-jbcmmf17y8yo9hgz
Tags: 0.15.0-0ubuntu1
* New upstream version.
* debian/patches/100_fix_html_docs.patch: refreshed.
* debian/control: bump up standards-version to 3.9.1 (no changes).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//
2
 
// stream_descriptor_service.hpp
3
 
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
 
//
5
 
// Copyright (c) 2003-2008 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_POSIX_STREAM_DESCRIPTOR_SERVICE_HPP
12
 
#define ASIO_POSIX_STREAM_DESCRIPTOR_SERVICE_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/push_options.hpp"
21
 
#include <cstddef>
22
 
#include <boost/config.hpp>
23
 
#include "asio/detail/pop_options.hpp"
24
 
 
25
 
#include "asio/error.hpp"
26
 
#include "asio/io_service.hpp"
27
 
#include "asio/detail/epoll_reactor.hpp"
28
 
#include "asio/detail/kqueue_reactor.hpp"
29
 
#include "asio/detail/select_reactor.hpp"
30
 
#include "asio/detail/service_base.hpp"
31
 
#include "asio/detail/reactive_descriptor_service.hpp"
32
 
 
33
 
#if !defined(ASIO_DISABLE_POSIX_STREAM_DESCRIPTOR)
34
 
# if !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
35
 
#  define ASIO_HAS_POSIX_STREAM_DESCRIPTOR 1
36
 
# endif // !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
37
 
#endif // !defined(ASIO_DISABLE_POSIX_STREAM_DESCRIPTOR)
38
 
 
39
 
#if defined(ASIO_HAS_POSIX_STREAM_DESCRIPTOR) \
40
 
  || defined(GENERATING_DOCUMENTATION)
41
 
 
42
 
namespace asio {
43
 
namespace posix {
44
 
 
45
 
/// Default service implementation for a stream descriptor.
46
 
class stream_descriptor_service
47
 
#if defined(GENERATING_DOCUMENTATION)
48
 
  : public asio::io_service::service
49
 
#else
50
 
  : public asio::detail::service_base<stream_descriptor_service>
51
 
#endif
52
 
{
53
 
public:
54
 
#if defined(GENERATING_DOCUMENTATION)
55
 
  /// The unique service identifier.
56
 
  static asio::io_service::id id;
57
 
#endif
58
 
 
59
 
private:
60
 
  // The type of the platform-specific implementation.
61
 
#if defined(ASIO_HAS_EPOLL)
62
 
  typedef detail::reactive_descriptor_service<
63
 
      detail::epoll_reactor<false> > service_impl_type;
64
 
#elif defined(ASIO_HAS_KQUEUE)
65
 
  typedef detail::reactive_descriptor_service<
66
 
      detail::kqueue_reactor<false> > service_impl_type;
67
 
#elif defined(ASIO_HAS_DEV_POLL)
68
 
  typedef detail::reactive_descriptor_service<
69
 
      detail::dev_poll_reactor<false> > service_impl_type;
70
 
#else
71
 
  typedef detail::reactive_descriptor_service<
72
 
      detail::select_reactor<false> > service_impl_type;
73
 
#endif
74
 
 
75
 
public:
76
 
  /// The type of a stream descriptor implementation.
77
 
#if defined(GENERATING_DOCUMENTATION)
78
 
  typedef implementation_defined implementation_type;
79
 
#else
80
 
  typedef service_impl_type::implementation_type implementation_type;
81
 
#endif
82
 
 
83
 
  /// The native descriptor type.
84
 
#if defined(GENERATING_DOCUMENTATION)
85
 
  typedef implementation_defined native_type;
86
 
#else
87
 
  typedef service_impl_type::native_type native_type;
88
 
#endif
89
 
 
90
 
  /// Construct a new stream descriptor service for the specified io_service.
91
 
  explicit stream_descriptor_service(asio::io_service& io_service)
92
 
    : asio::detail::service_base<stream_descriptor_service>(io_service),
93
 
      service_impl_(asio::use_service<service_impl_type>(io_service))
94
 
  {
95
 
  }
96
 
 
97
 
  /// Destroy all user-defined descriptorr objects owned by the service.
98
 
  void shutdown_service()
99
 
  {
100
 
  }
101
 
 
102
 
  /// Construct a new stream descriptor implementation.
103
 
  void construct(implementation_type& impl)
104
 
  {
105
 
    service_impl_.construct(impl);
106
 
  }
107
 
 
108
 
  /// Destroy a stream descriptor implementation.
109
 
  void destroy(implementation_type& impl)
110
 
  {
111
 
    service_impl_.destroy(impl);
112
 
  }
113
 
 
114
 
  /// Assign an existing native descriptor to a stream descriptor.
115
 
  asio::error_code assign(implementation_type& impl,
116
 
      const native_type& native_descriptor, asio::error_code& ec)
117
 
  {
118
 
    return service_impl_.assign(impl, native_descriptor, ec);
119
 
  }
120
 
 
121
 
  /// Determine whether the descriptor is open.
122
 
  bool is_open(const implementation_type& impl) const
123
 
  {
124
 
    return service_impl_.is_open(impl);
125
 
  }
126
 
 
127
 
  /// Close a stream descriptor implementation.
128
 
  asio::error_code close(implementation_type& impl,
129
 
      asio::error_code& ec)
130
 
  {
131
 
    return service_impl_.close(impl, ec);
132
 
  }
133
 
 
134
 
  /// Get the native descriptor implementation.
135
 
  native_type native(implementation_type& impl)
136
 
  {
137
 
    return service_impl_.native(impl);
138
 
  }
139
 
 
140
 
  /// Cancel all asynchronous operations associated with the descriptor.
141
 
  asio::error_code cancel(implementation_type& impl,
142
 
      asio::error_code& ec)
143
 
  {
144
 
    return service_impl_.cancel(impl, ec);
145
 
  }
146
 
 
147
 
  /// Perform an IO control command on the descriptor.
148
 
  template <typename IoControlCommand>
149
 
  asio::error_code io_control(implementation_type& impl,
150
 
      IoControlCommand& command, asio::error_code& ec)
151
 
  {
152
 
    return service_impl_.io_control(impl, command, ec);
153
 
  }
154
 
 
155
 
  /// Write the given data to the stream.
156
 
  template <typename ConstBufferSequence>
157
 
  std::size_t write_some(implementation_type& impl,
158
 
      const ConstBufferSequence& buffers, asio::error_code& ec)
159
 
  {
160
 
    return service_impl_.write_some(impl, buffers, ec);
161
 
  }
162
 
 
163
 
  /// Start an asynchronous write.
164
 
  template <typename ConstBufferSequence, typename WriteHandler>
165
 
  void async_write_some(implementation_type& impl,
166
 
      const ConstBufferSequence& buffers, WriteHandler descriptorr)
167
 
  {
168
 
    service_impl_.async_write_some(impl, buffers, descriptorr);
169
 
  }
170
 
 
171
 
  /// Read some data from the stream.
172
 
  template <typename MutableBufferSequence>
173
 
  std::size_t read_some(implementation_type& impl,
174
 
      const MutableBufferSequence& buffers, asio::error_code& ec)
175
 
  {
176
 
    return service_impl_.read_some(impl, buffers, ec);
177
 
  }
178
 
 
179
 
  /// Start an asynchronous read.
180
 
  template <typename MutableBufferSequence, typename ReadHandler>
181
 
  void async_read_some(implementation_type& impl,
182
 
      const MutableBufferSequence& buffers, ReadHandler descriptorr)
183
 
  {
184
 
    service_impl_.async_read_some(impl, buffers, descriptorr);
185
 
  }
186
 
 
187
 
private:
188
 
  // The service that provides the platform-specific implementation.
189
 
  service_impl_type& service_impl_;
190
 
};
191
 
 
192
 
} // namespace posix
193
 
} // namespace asio
194
 
 
195
 
#endif // defined(ASIO_HAS_POSIX_STREAM_DESCRIPTOR)
196
 
       //   || defined(GENERATING_DOCUMENTATION)
197
 
 
198
 
#include "asio/detail/pop_options.hpp"
199
 
 
200
 
#endif // ASIO_POSIX_STREAM_DESCRIPTOR_SERVICE_HPP