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

« back to all changes in this revision

Viewing changes to include/libtorrent/asio/socket_acceptor_service.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Cristian Greco
  • Date: 2008-07-02 10:46:21 UTC
  • Revision ID: james.westby@ubuntu.com-20080702104621-jzx3pfke9lkcxfxn
Tags: upstream-0.13.1
ImportĀ upstreamĀ versionĀ 0.13.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// socket_acceptor_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_SOCKET_ACCEPTOR_SERVICE_HPP
 
12
#define ASIO_SOCKET_ACCEPTOR_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/basic_socket.hpp"
 
21
#include "asio/error.hpp"
 
22
#include "asio/io_service.hpp"
 
23
#include "asio/detail/epoll_reactor.hpp"
 
24
#include "asio/detail/kqueue_reactor.hpp"
 
25
#include "asio/detail/select_reactor.hpp"
 
26
#include "asio/detail/service_base.hpp"
 
27
#include "asio/detail/reactive_socket_service.hpp"
 
28
#include "asio/detail/win_iocp_socket_service.hpp"
 
29
 
 
30
namespace asio {
 
31
 
 
32
/// Default service implementation for a socket acceptor.
 
33
template <typename Protocol>
 
34
class socket_acceptor_service
 
35
#if defined(GENERATING_DOCUMENTATION)
 
36
  : public asio::io_service::service
 
37
#else
 
38
  : public asio::detail::service_base<socket_acceptor_service<Protocol> >
 
39
#endif
 
40
{
 
41
public:
 
42
#if defined(GENERATING_DOCUMENTATION)
 
43
  /// The unique service identifier.
 
44
  static asio::io_service::id id;
 
45
#endif
 
46
 
 
47
  /// The protocol type.
 
48
  typedef Protocol protocol_type;
 
49
 
 
50
  /// The endpoint type.
 
51
  typedef typename protocol_type::endpoint endpoint_type;
 
52
 
 
53
private:
 
54
  // The type of the platform-specific implementation.
 
55
#if defined(ASIO_HAS_IOCP)
 
56
  typedef detail::win_iocp_socket_service<Protocol> service_impl_type;
 
57
#elif defined(ASIO_HAS_EPOLL)
 
58
  typedef detail::reactive_socket_service<
 
59
      Protocol, detail::epoll_reactor<false> > service_impl_type;
 
60
#elif defined(ASIO_HAS_KQUEUE)
 
61
  typedef detail::reactive_socket_service<
 
62
      Protocol, detail::kqueue_reactor<false> > service_impl_type;
 
63
#elif defined(ASIO_HAS_DEV_POLL)
 
64
  typedef detail::reactive_socket_service<
 
65
      Protocol, detail::dev_poll_reactor<false> > service_impl_type;
 
66
#else
 
67
  typedef detail::reactive_socket_service<
 
68
      Protocol, detail::select_reactor<false> > service_impl_type;
 
69
#endif
 
70
 
 
71
public:
 
72
  /// The native type of the socket acceptor.
 
73
#if defined(GENERATING_DOCUMENTATION)
 
74
  typedef implementation_defined implementation_type;
 
75
#else
 
76
  typedef typename service_impl_type::implementation_type implementation_type;
 
77
#endif
 
78
 
 
79
  /// The native acceptor type.
 
80
#if defined(GENERATING_DOCUMENTATION)
 
81
  typedef implementation_defined native_type;
 
82
#else
 
83
  typedef typename service_impl_type::native_type native_type;
 
84
#endif
 
85
 
 
86
  /// Construct a new socket acceptor service for the specified io_service.
 
87
  explicit socket_acceptor_service(asio::io_service& io_service)
 
88
    : asio::detail::service_base<
 
89
        socket_acceptor_service<Protocol> >(io_service),
 
90
      service_impl_(asio::use_service<service_impl_type>(io_service))
 
91
  {
 
92
  }
 
93
 
 
94
  /// Destroy all user-defined handler objects owned by the service.
 
95
  void shutdown_service()
 
96
  {
 
97
  }
 
98
 
 
99
  /// Construct a new socket acceptor implementation.
 
100
  void construct(implementation_type& impl)
 
101
  {
 
102
    service_impl_.construct(impl);
 
103
  }
 
104
 
 
105
  /// Destroy a socket acceptor implementation.
 
106
  void destroy(implementation_type& impl)
 
107
  {
 
108
    service_impl_.destroy(impl);
 
109
  }
 
110
 
 
111
  /// Open a new socket acceptor implementation.
 
112
  asio::error_code open(implementation_type& impl,
 
113
      const protocol_type& protocol, asio::error_code& ec)
 
114
  {
 
115
    return service_impl_.open(impl, protocol, ec);
 
116
  }
 
117
 
 
118
  /// Assign an existing native acceptor to a socket acceptor.
 
119
  asio::error_code assign(implementation_type& impl,
 
120
      const protocol_type& protocol, const native_type& native_acceptor,
 
121
      asio::error_code& ec)
 
122
  {
 
123
    return service_impl_.assign(impl, protocol, native_acceptor, ec);
 
124
  }
 
125
 
 
126
  /// Determine whether the acceptor is open.
 
127
  bool is_open(const implementation_type& impl) const
 
128
  {
 
129
    return service_impl_.is_open(impl);
 
130
  }
 
131
 
 
132
  /// Cancel all asynchronous operations associated with the acceptor.
 
133
  asio::error_code cancel(implementation_type& impl,
 
134
      asio::error_code& ec)
 
135
  {
 
136
    return service_impl_.cancel(impl, ec);
 
137
  }
 
138
 
 
139
  /// Bind the socket acceptor to the specified local endpoint.
 
140
  asio::error_code bind(implementation_type& impl,
 
141
      const endpoint_type& endpoint, asio::error_code& ec)
 
142
  {
 
143
    return service_impl_.bind(impl, endpoint, ec);
 
144
  }
 
145
 
 
146
  /// Place the socket acceptor into the state where it will listen for new
 
147
  /// connections.
 
148
  asio::error_code listen(implementation_type& impl, int backlog,
 
149
      asio::error_code& ec)
 
150
  {
 
151
    return service_impl_.listen(impl, backlog, ec);
 
152
  }
 
153
 
 
154
  /// Close a socket acceptor implementation.
 
155
  asio::error_code close(implementation_type& impl,
 
156
      asio::error_code& ec)
 
157
  {
 
158
    return service_impl_.close(impl, ec);
 
159
  }
 
160
 
 
161
  /// Get the native acceptor implementation.
 
162
  native_type native(implementation_type& impl)
 
163
  {
 
164
    return service_impl_.native(impl);
 
165
  }
 
166
 
 
167
  /// Set a socket option.
 
168
  template <typename SettableSocketOption>
 
169
  asio::error_code set_option(implementation_type& impl,
 
170
      const SettableSocketOption& option, asio::error_code& ec)
 
171
  {
 
172
    return service_impl_.set_option(impl, option, ec);
 
173
  }
 
174
 
 
175
  /// Get a socket option.
 
176
  template <typename GettableSocketOption>
 
177
  asio::error_code get_option(const implementation_type& impl,
 
178
      GettableSocketOption& option, asio::error_code& ec) const
 
179
  {
 
180
    return service_impl_.get_option(impl, option, ec);
 
181
  }
 
182
 
 
183
  /// Perform an IO control command on the socket.
 
184
  template <typename IoControlCommand>
 
185
  asio::error_code io_control(implementation_type& impl,
 
186
      IoControlCommand& command, asio::error_code& ec)
 
187
  {
 
188
    return service_impl_.io_control(impl, command, ec);
 
189
  }
 
190
 
 
191
  /// Get the local endpoint.
 
192
  endpoint_type local_endpoint(const implementation_type& impl,
 
193
      asio::error_code& ec) const
 
194
  {
 
195
    return service_impl_.local_endpoint(impl, ec);
 
196
  }
 
197
 
 
198
  /// Accept a new connection.
 
199
  template <typename SocketService>
 
200
  asio::error_code accept(implementation_type& impl,
 
201
      basic_socket<protocol_type, SocketService>& peer,
 
202
      endpoint_type* peer_endpoint, asio::error_code& ec)
 
203
  {
 
204
    return service_impl_.accept(impl, peer, peer_endpoint, ec);
 
205
  }
 
206
 
 
207
  /// Start an asynchronous accept.
 
208
  template <typename SocketService, typename AcceptHandler>
 
209
  void async_accept(implementation_type& impl,
 
210
      basic_socket<protocol_type, SocketService>& peer,
 
211
      endpoint_type* peer_endpoint, AcceptHandler handler)
 
212
  {
 
213
    service_impl_.async_accept(impl, peer, peer_endpoint, handler);
 
214
  }
 
215
 
 
216
private:
 
217
  // The service that provides the platform-specific implementation.
 
218
  service_impl_type& service_impl_;
 
219
};
 
220
 
 
221
} // namespace asio
 
222
 
 
223
#include "asio/detail/pop_options.hpp"
 
224
 
 
225
#endif // ASIO_SOCKET_ACCEPTOR_SERVICE_HPP