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

« back to all changes in this revision

Viewing changes to include/libtorrent/asio/stream_socket_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_socket_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_STREAM_SOCKET_SERVICE_HPP
12
 
#define ASIO_STREAM_SOCKET_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/win_iocp_socket_service.hpp"
32
 
#include "asio/detail/reactive_socket_service.hpp"
33
 
 
34
 
namespace asio {
35
 
 
36
 
/// Default service implementation for a stream socket.
37
 
template <typename Protocol>
38
 
class stream_socket_service
39
 
#if defined(GENERATING_DOCUMENTATION)
40
 
  : public asio::io_service::service
41
 
#else
42
 
  : public asio::detail::service_base<stream_socket_service<Protocol> >
43
 
#endif
44
 
{
45
 
public:
46
 
#if defined(GENERATING_DOCUMENTATION)
47
 
  /// The unique service identifier.
48
 
  static asio::io_service::id id;
49
 
#endif
50
 
 
51
 
  /// The protocol type.
52
 
  typedef Protocol protocol_type;
53
 
 
54
 
  /// The endpoint type.
55
 
  typedef typename Protocol::endpoint endpoint_type;
56
 
 
57
 
private:
58
 
  // The type of the platform-specific implementation.
59
 
#if defined(ASIO_HAS_IOCP)
60
 
  typedef detail::win_iocp_socket_service<Protocol> service_impl_type;
61
 
#elif defined(ASIO_HAS_EPOLL)
62
 
  typedef detail::reactive_socket_service<
63
 
      Protocol, detail::epoll_reactor<false> > service_impl_type;
64
 
#elif defined(ASIO_HAS_KQUEUE)
65
 
  typedef detail::reactive_socket_service<
66
 
      Protocol, detail::kqueue_reactor<false> > service_impl_type;
67
 
#elif defined(ASIO_HAS_DEV_POLL)
68
 
  typedef detail::reactive_socket_service<
69
 
      Protocol, detail::dev_poll_reactor<false> > service_impl_type;
70
 
#else
71
 
  typedef detail::reactive_socket_service<
72
 
      Protocol, detail::select_reactor<false> > service_impl_type;
73
 
#endif
74
 
 
75
 
public:
76
 
  /// The type of a stream socket implementation.
77
 
#if defined(GENERATING_DOCUMENTATION)
78
 
  typedef implementation_defined implementation_type;
79
 
#else
80
 
  typedef typename service_impl_type::implementation_type implementation_type;
81
 
#endif
82
 
 
83
 
  /// The native socket type.
84
 
#if defined(GENERATING_DOCUMENTATION)
85
 
  typedef implementation_defined native_type;
86
 
#else
87
 
  typedef typename service_impl_type::native_type native_type;
88
 
#endif
89
 
 
90
 
  /// Construct a new stream socket service for the specified io_service.
91
 
  explicit stream_socket_service(asio::io_service& io_service)
92
 
    : asio::detail::service_base<
93
 
        stream_socket_service<Protocol> >(io_service),
94
 
      service_impl_(asio::use_service<service_impl_type>(io_service))
95
 
  {
96
 
  }
97
 
 
98
 
  /// Destroy all user-defined handler objects owned by the service.
99
 
  void shutdown_service()
100
 
  {
101
 
  }
102
 
 
103
 
  /// Construct a new stream socket implementation.
104
 
  void construct(implementation_type& impl)
105
 
  {
106
 
    service_impl_.construct(impl);
107
 
  }
108
 
 
109
 
  /// Destroy a stream socket implementation.
110
 
  void destroy(implementation_type& impl)
111
 
  {
112
 
    service_impl_.destroy(impl);
113
 
  }
114
 
 
115
 
  /// Open a stream socket.
116
 
  asio::error_code open(implementation_type& impl,
117
 
      const protocol_type& protocol, asio::error_code& ec)
118
 
  {
119
 
    if (protocol.type() == SOCK_STREAM)
120
 
      service_impl_.open(impl, protocol, ec);
121
 
    else
122
 
      ec = asio::error::invalid_argument;
123
 
    return ec;
124
 
  }
125
 
 
126
 
  /// Assign an existing native socket to a stream socket.
127
 
  asio::error_code assign(implementation_type& impl,
128
 
      const protocol_type& protocol, const native_type& native_socket,
129
 
      asio::error_code& ec)
130
 
  {
131
 
    return service_impl_.assign(impl, protocol, native_socket, ec);
132
 
  }
133
 
 
134
 
  /// Determine whether the socket is open.
135
 
  bool is_open(const implementation_type& impl) const
136
 
  {
137
 
    return service_impl_.is_open(impl);
138
 
  }
139
 
 
140
 
  /// Close a stream socket implementation.
141
 
  asio::error_code close(implementation_type& impl,
142
 
      asio::error_code& ec)
143
 
  {
144
 
    return service_impl_.close(impl, ec);
145
 
  }
146
 
 
147
 
  /// Get the native socket implementation.
148
 
  native_type native(implementation_type& impl)
149
 
  {
150
 
    return service_impl_.native(impl);
151
 
  }
152
 
 
153
 
  /// Cancel all asynchronous operations associated with the socket.
154
 
  asio::error_code cancel(implementation_type& impl,
155
 
      asio::error_code& ec)
156
 
  {
157
 
    return service_impl_.cancel(impl, ec);
158
 
  }
159
 
 
160
 
  /// Determine whether the socket is at the out-of-band data mark.
161
 
  bool at_mark(const implementation_type& impl,
162
 
      asio::error_code& ec) const
163
 
  {
164
 
    return service_impl_.at_mark(impl, ec);
165
 
  }
166
 
 
167
 
  /// Determine the number of bytes available for reading.
168
 
  std::size_t available(const implementation_type& impl,
169
 
      asio::error_code& ec) const
170
 
  {
171
 
    return service_impl_.available(impl, ec);
172
 
  }
173
 
 
174
 
  /// Bind the stream socket to the specified local endpoint.
175
 
  asio::error_code bind(implementation_type& impl,
176
 
      const endpoint_type& endpoint, asio::error_code& ec)
177
 
  {
178
 
    return service_impl_.bind(impl, endpoint, ec);
179
 
  }
180
 
 
181
 
  /// Connect the stream socket to the specified endpoint.
182
 
  asio::error_code connect(implementation_type& impl,
183
 
      const endpoint_type& peer_endpoint, asio::error_code& ec)
184
 
  {
185
 
    return service_impl_.connect(impl, peer_endpoint, ec);
186
 
  }
187
 
 
188
 
  /// Start an asynchronous connect.
189
 
  template <typename ConnectHandler>
190
 
  void async_connect(implementation_type& impl,
191
 
      const endpoint_type& peer_endpoint, ConnectHandler handler)
192
 
  {
193
 
    service_impl_.async_connect(impl, peer_endpoint, handler);
194
 
  }
195
 
 
196
 
  /// Set a socket option.
197
 
  template <typename SettableSocketOption>
198
 
  asio::error_code set_option(implementation_type& impl,
199
 
      const SettableSocketOption& option, asio::error_code& ec)
200
 
  {
201
 
    return service_impl_.set_option(impl, option, ec);
202
 
  }
203
 
 
204
 
  /// Get a socket option.
205
 
  template <typename GettableSocketOption>
206
 
  asio::error_code get_option(const implementation_type& impl,
207
 
      GettableSocketOption& option, asio::error_code& ec) const
208
 
  {
209
 
    return service_impl_.get_option(impl, option, ec);
210
 
  }
211
 
 
212
 
  /// Perform an IO control command on the socket.
213
 
  template <typename IoControlCommand>
214
 
  asio::error_code io_control(implementation_type& impl,
215
 
      IoControlCommand& command, asio::error_code& ec)
216
 
  {
217
 
    return service_impl_.io_control(impl, command, ec);
218
 
  }
219
 
 
220
 
  /// Get the local endpoint.
221
 
  endpoint_type local_endpoint(const implementation_type& impl,
222
 
      asio::error_code& ec) const
223
 
  {
224
 
    return service_impl_.local_endpoint(impl, ec);
225
 
  }
226
 
 
227
 
  /// Get the remote endpoint.
228
 
  endpoint_type remote_endpoint(const implementation_type& impl,
229
 
      asio::error_code& ec) const
230
 
  {
231
 
    return service_impl_.remote_endpoint(impl, ec);
232
 
  }
233
 
 
234
 
  /// Disable sends or receives on the socket.
235
 
  asio::error_code shutdown(implementation_type& impl,
236
 
      socket_base::shutdown_type what, asio::error_code& ec)
237
 
  {
238
 
    return service_impl_.shutdown(impl, what, ec);
239
 
  }
240
 
 
241
 
  /// Send the given data to the peer.
242
 
  template <typename ConstBufferSequence>
243
 
  std::size_t send(implementation_type& impl,
244
 
      const ConstBufferSequence& buffers,
245
 
      socket_base::message_flags flags, asio::error_code& ec)
246
 
  {
247
 
    return service_impl_.send(impl, buffers, flags, ec);
248
 
  }
249
 
 
250
 
  /// Start an asynchronous send.
251
 
  template <typename ConstBufferSequence, typename WriteHandler>
252
 
  void async_send(implementation_type& impl,
253
 
      const ConstBufferSequence& buffers,
254
 
      socket_base::message_flags flags, WriteHandler handler)
255
 
  {
256
 
    service_impl_.async_send(impl, buffers, flags, handler);
257
 
  }
258
 
 
259
 
  /// Receive some data from the peer.
260
 
  template <typename MutableBufferSequence>
261
 
  std::size_t receive(implementation_type& impl,
262
 
      const MutableBufferSequence& buffers,
263
 
      socket_base::message_flags flags, asio::error_code& ec)
264
 
  {
265
 
    return service_impl_.receive(impl, buffers, flags, ec);
266
 
  }
267
 
 
268
 
  /// Start an asynchronous receive.
269
 
  template <typename MutableBufferSequence, typename ReadHandler>
270
 
  void async_receive(implementation_type& impl,
271
 
      const MutableBufferSequence& buffers,
272
 
      socket_base::message_flags flags, ReadHandler handler)
273
 
  {
274
 
    service_impl_.async_receive(impl, buffers, flags, handler);
275
 
  }
276
 
 
277
 
private:
278
 
  // The service that provides the platform-specific implementation.
279
 
  service_impl_type& service_impl_;
280
 
};
281
 
 
282
 
} // namespace asio
283
 
 
284
 
#include "asio/detail/pop_options.hpp"
285
 
 
286
 
#endif // ASIO_STREAM_SOCKET_SERVICE_HPP