~ubuntu-branches/ubuntu/trusty/miro/trusty

« back to all changes in this revision

Viewing changes to portable/libtorrent/include/libtorrent/asio/raw_socket_service.hpp

  • Committer: Daniel Hahler
  • Date: 2010-04-13 18:51:35 UTC
  • mfrom: (1.2.10 upstream)
  • Revision ID: ubuntu-launchpad@thequod.de-20100413185135-xi24v1diqg8w406x
Merging shared upstream rev into target branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//
2
 
// raw_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_RAW_SOCKET_SERVICE_HPP
12
 
#define ASIO_RAW_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/reactive_socket_service.hpp"
32
 
#include "asio/detail/win_iocp_socket_service.hpp"
33
 
 
34
 
namespace asio {
35
 
 
36
 
/// Default service implementation for a raw socket.
37
 
template <typename Protocol>
38
 
class raw_socket_service
39
 
#if defined(GENERATING_DOCUMENTATION)
40
 
  : public asio::io_service::service
41
 
#else
42
 
  : public asio::detail::service_base<raw_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 raw socket.
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 raw socket service for the specified io_service.
91
 
  explicit raw_socket_service(asio::io_service& io_service)
92
 
    : asio::detail::service_base<
93
 
        raw_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 raw socket implementation.
104
 
  void construct(implementation_type& impl)
105
 
  {
106
 
    service_impl_.construct(impl);
107
 
  }
108
 
 
109
 
  /// Destroy a raw socket implementation.
110
 
  void destroy(implementation_type& impl)
111
 
  {
112
 
    service_impl_.destroy(impl);
113
 
  }
114
 
 
115
 
  // Open a new raw socket implementation.
116
 
  asio::error_code open(implementation_type& impl,
117
 
      const protocol_type& protocol, asio::error_code& ec)
118
 
  {
119
 
    if (protocol.type() == SOCK_RAW)
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 raw 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 raw 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 raw 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 raw 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, const ConstBufferSequence& buffers,
253
 
      socket_base::message_flags flags, WriteHandler handler)
254
 
  {
255
 
    service_impl_.async_send(impl, buffers, flags, handler);
256
 
  }
257
 
 
258
 
  /// Send raw data to the specified endpoint.
259
 
  template <typename ConstBufferSequence>
260
 
  std::size_t send_to(implementation_type& impl,
261
 
      const ConstBufferSequence& buffers, const endpoint_type& destination,
262
 
      socket_base::message_flags flags, asio::error_code& ec)
263
 
  {
264
 
    return service_impl_.send_to(impl, buffers, destination, flags, ec);
265
 
  }
266
 
 
267
 
  /// Start an asynchronous send.
268
 
  template <typename ConstBufferSequence, typename WriteHandler>
269
 
  void async_send_to(implementation_type& impl,
270
 
      const ConstBufferSequence& buffers, const endpoint_type& destination,
271
 
      socket_base::message_flags flags, WriteHandler handler)
272
 
  {
273
 
    service_impl_.async_send_to(impl, buffers, destination, flags, handler);
274
 
  }
275
 
 
276
 
  /// Receive some data from the peer.
277
 
  template <typename MutableBufferSequence>
278
 
  std::size_t receive(implementation_type& impl,
279
 
      const MutableBufferSequence& buffers,
280
 
      socket_base::message_flags flags, asio::error_code& ec)
281
 
  {
282
 
    return service_impl_.receive(impl, buffers, flags, ec);
283
 
  }
284
 
 
285
 
  /// Start an asynchronous receive.
286
 
  template <typename MutableBufferSequence, typename ReadHandler>
287
 
  void async_receive(implementation_type& impl,
288
 
      const MutableBufferSequence& buffers,
289
 
      socket_base::message_flags flags, ReadHandler handler)
290
 
  {
291
 
    service_impl_.async_receive(impl, buffers, flags, handler);
292
 
  }
293
 
 
294
 
  /// Receive raw data with the endpoint of the sender.
295
 
  template <typename MutableBufferSequence>
296
 
  std::size_t receive_from(implementation_type& impl,
297
 
      const MutableBufferSequence& buffers, endpoint_type& sender_endpoint,
298
 
      socket_base::message_flags flags, asio::error_code& ec)
299
 
  {
300
 
    return service_impl_.receive_from(impl, buffers, sender_endpoint, flags,
301
 
        ec);
302
 
  }
303
 
 
304
 
  /// Start an asynchronous receive that will get the endpoint of the sender.
305
 
  template <typename MutableBufferSequence, typename ReadHandler>
306
 
  void async_receive_from(implementation_type& impl,
307
 
      const MutableBufferSequence& buffers, endpoint_type& sender_endpoint,
308
 
      socket_base::message_flags flags, ReadHandler handler)
309
 
  {
310
 
    service_impl_.async_receive_from(impl, buffers, sender_endpoint, flags,
311
 
        handler);
312
 
  }
313
 
 
314
 
private:
315
 
  // The service that provides the platform-specific implementation.
316
 
  service_impl_type& service_impl_;
317
 
};
318
 
 
319
 
} // namespace asio
320
 
 
321
 
#include "asio/detail/pop_options.hpp"
322
 
 
323
 
#endif // ASIO_RAW_SOCKET_SERVICE_HPP