2
// socket_acceptor_service.hpp
3
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
// Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
11
#ifndef ASIO_SOCKET_ACCEPTOR_SERVICE_HPP
12
#define ASIO_SOCKET_ACCEPTOR_SERVICE_HPP
14
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
16
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18
#include "asio/detail/push_options.hpp"
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"
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
38
: public asio::detail::service_base<socket_acceptor_service<Protocol> >
42
#if defined(GENERATING_DOCUMENTATION)
43
/// The unique service identifier.
44
static asio::io_service::id id;
47
/// The protocol type.
48
typedef Protocol protocol_type;
50
/// The endpoint type.
51
typedef typename protocol_type::endpoint endpoint_type;
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;
67
typedef detail::reactive_socket_service<
68
Protocol, detail::select_reactor<false> > service_impl_type;
72
/// The native type of the socket acceptor.
73
#if defined(GENERATING_DOCUMENTATION)
74
typedef implementation_defined implementation_type;
76
typedef typename service_impl_type::implementation_type implementation_type;
79
/// The native acceptor type.
80
#if defined(GENERATING_DOCUMENTATION)
81
typedef implementation_defined native_type;
83
typedef typename service_impl_type::native_type native_type;
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))
94
/// Destroy all user-defined handler objects owned by the service.
95
void shutdown_service()
99
/// Construct a new socket acceptor implementation.
100
void construct(implementation_type& impl)
102
service_impl_.construct(impl);
105
/// Destroy a socket acceptor implementation.
106
void destroy(implementation_type& impl)
108
service_impl_.destroy(impl);
111
/// Open a new socket acceptor implementation.
112
asio::error_code open(implementation_type& impl,
113
const protocol_type& protocol, asio::error_code& ec)
115
return service_impl_.open(impl, protocol, ec);
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)
123
return service_impl_.assign(impl, protocol, native_acceptor, ec);
126
/// Determine whether the acceptor is open.
127
bool is_open(const implementation_type& impl) const
129
return service_impl_.is_open(impl);
132
/// Cancel all asynchronous operations associated with the acceptor.
133
asio::error_code cancel(implementation_type& impl,
134
asio::error_code& ec)
136
return service_impl_.cancel(impl, ec);
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)
143
return service_impl_.bind(impl, endpoint, ec);
146
/// Place the socket acceptor into the state where it will listen for new
148
asio::error_code listen(implementation_type& impl, int backlog,
149
asio::error_code& ec)
151
return service_impl_.listen(impl, backlog, ec);
154
/// Close a socket acceptor implementation.
155
asio::error_code close(implementation_type& impl,
156
asio::error_code& ec)
158
return service_impl_.close(impl, ec);
161
/// Get the native acceptor implementation.
162
native_type native(implementation_type& impl)
164
return service_impl_.native(impl);
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)
172
return service_impl_.set_option(impl, option, ec);
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
180
return service_impl_.get_option(impl, option, ec);
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)
188
return service_impl_.io_control(impl, command, ec);
191
/// Get the local endpoint.
192
endpoint_type local_endpoint(const implementation_type& impl,
193
asio::error_code& ec) const
195
return service_impl_.local_endpoint(impl, ec);
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)
204
return service_impl_.accept(impl, peer, peer_endpoint, ec);
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)
213
service_impl_.async_accept(impl, peer, peer_endpoint, handler);
217
// The service that provides the platform-specific implementation.
218
service_impl_type& service_impl_;
223
#include "asio/detail/pop_options.hpp"
225
#endif // ASIO_SOCKET_ACCEPTOR_SERVICE_HPP