fix doc example typo
[boost.git] / boost / asio / socket_acceptor_service.hpp
blobba78746fc28c1e7464ea6de2e1c5c5ded95a3db6
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 //
11 #ifndef BOOST_ASIO_SOCKET_ACCEPTOR_SERVICE_HPP
12 #define BOOST_ASIO_SOCKET_ACCEPTOR_SERVICE_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/push_options.hpp>
20 #include <boost/asio/basic_socket.hpp>
21 #include <boost/asio/error.hpp>
22 #include <boost/asio/io_service.hpp>
23 #include <boost/asio/detail/epoll_reactor.hpp>
24 #include <boost/asio/detail/kqueue_reactor.hpp>
25 #include <boost/asio/detail/select_reactor.hpp>
26 #include <boost/asio/detail/service_base.hpp>
27 #include <boost/asio/detail/reactive_socket_service.hpp>
28 #include <boost/asio/detail/win_iocp_socket_service.hpp>
30 namespace boost {
31 namespace asio {
33 /// Default service implementation for a socket acceptor.
34 template <typename Protocol>
35 class socket_acceptor_service
36 #if defined(GENERATING_DOCUMENTATION)
37 : public boost::asio::io_service::service
38 #else
39 : public boost::asio::detail::service_base<socket_acceptor_service<Protocol> >
40 #endif
42 public:
43 #if defined(GENERATING_DOCUMENTATION)
44 /// The unique service identifier.
45 static boost::asio::io_service::id id;
46 #endif
48 /// The protocol type.
49 typedef Protocol protocol_type;
51 /// The endpoint type.
52 typedef typename protocol_type::endpoint endpoint_type;
54 private:
55 // The type of the platform-specific implementation.
56 #if defined(BOOST_ASIO_HAS_IOCP)
57 typedef detail::win_iocp_socket_service<Protocol> service_impl_type;
58 #elif defined(BOOST_ASIO_HAS_EPOLL)
59 typedef detail::reactive_socket_service<
60 Protocol, detail::epoll_reactor<false> > service_impl_type;
61 #elif defined(BOOST_ASIO_HAS_KQUEUE)
62 typedef detail::reactive_socket_service<
63 Protocol, detail::kqueue_reactor<false> > service_impl_type;
64 #elif defined(BOOST_ASIO_HAS_DEV_POLL)
65 typedef detail::reactive_socket_service<
66 Protocol, detail::dev_poll_reactor<false> > service_impl_type;
67 #else
68 typedef detail::reactive_socket_service<
69 Protocol, detail::select_reactor<false> > service_impl_type;
70 #endif
72 public:
73 /// The native type of the socket acceptor.
74 #if defined(GENERATING_DOCUMENTATION)
75 typedef implementation_defined implementation_type;
76 #else
77 typedef typename service_impl_type::implementation_type implementation_type;
78 #endif
80 /// The native acceptor type.
81 #if defined(GENERATING_DOCUMENTATION)
82 typedef implementation_defined native_type;
83 #else
84 typedef typename service_impl_type::native_type native_type;
85 #endif
87 /// Construct a new socket acceptor service for the specified io_service.
88 explicit socket_acceptor_service(boost::asio::io_service& io_service)
89 : boost::asio::detail::service_base<
90 socket_acceptor_service<Protocol> >(io_service),
91 service_impl_(boost::asio::use_service<service_impl_type>(io_service))
95 /// Destroy all user-defined handler objects owned by the service.
96 void shutdown_service()
100 /// Construct a new socket acceptor implementation.
101 void construct(implementation_type& impl)
103 service_impl_.construct(impl);
106 /// Destroy a socket acceptor implementation.
107 void destroy(implementation_type& impl)
109 service_impl_.destroy(impl);
112 /// Open a new socket acceptor implementation.
113 boost::system::error_code open(implementation_type& impl,
114 const protocol_type& protocol, boost::system::error_code& ec)
116 return service_impl_.open(impl, protocol, ec);
119 /// Assign an existing native acceptor to a socket acceptor.
120 boost::system::error_code assign(implementation_type& impl,
121 const protocol_type& protocol, const native_type& native_acceptor,
122 boost::system::error_code& ec)
124 return service_impl_.assign(impl, protocol, native_acceptor, ec);
127 /// Determine whether the acceptor is open.
128 bool is_open(const implementation_type& impl) const
130 return service_impl_.is_open(impl);
133 /// Cancel all asynchronous operations associated with the acceptor.
134 boost::system::error_code cancel(implementation_type& impl,
135 boost::system::error_code& ec)
137 return service_impl_.cancel(impl, ec);
140 /// Bind the socket acceptor to the specified local endpoint.
141 boost::system::error_code bind(implementation_type& impl,
142 const endpoint_type& endpoint, boost::system::error_code& ec)
144 return service_impl_.bind(impl, endpoint, ec);
147 /// Place the socket acceptor into the state where it will listen for new
148 /// connections.
149 boost::system::error_code listen(implementation_type& impl, int backlog,
150 boost::system::error_code& ec)
152 return service_impl_.listen(impl, backlog, ec);
155 /// Close a socket acceptor implementation.
156 boost::system::error_code close(implementation_type& impl,
157 boost::system::error_code& ec)
159 return service_impl_.close(impl, ec);
162 /// Get the native acceptor implementation.
163 native_type native(implementation_type& impl)
165 return service_impl_.native(impl);
168 /// Set a socket option.
169 template <typename SettableSocketOption>
170 boost::system::error_code set_option(implementation_type& impl,
171 const SettableSocketOption& option, boost::system::error_code& ec)
173 return service_impl_.set_option(impl, option, ec);
176 /// Get a socket option.
177 template <typename GettableSocketOption>
178 boost::system::error_code get_option(const implementation_type& impl,
179 GettableSocketOption& option, boost::system::error_code& ec) const
181 return service_impl_.get_option(impl, option, ec);
184 /// Perform an IO control command on the socket.
185 template <typename IoControlCommand>
186 boost::system::error_code io_control(implementation_type& impl,
187 IoControlCommand& command, boost::system::error_code& ec)
189 return service_impl_.io_control(impl, command, ec);
192 /// Get the local endpoint.
193 endpoint_type local_endpoint(const implementation_type& impl,
194 boost::system::error_code& ec) const
196 return service_impl_.local_endpoint(impl, ec);
199 /// Accept a new connection.
200 template <typename SocketService>
201 boost::system::error_code accept(implementation_type& impl,
202 basic_socket<protocol_type, SocketService>& peer,
203 endpoint_type* peer_endpoint, boost::system::error_code& ec)
205 return service_impl_.accept(impl, peer, peer_endpoint, ec);
208 /// Start an asynchronous accept.
209 template <typename SocketService, typename AcceptHandler>
210 void async_accept(implementation_type& impl,
211 basic_socket<protocol_type, SocketService>& peer,
212 endpoint_type* peer_endpoint, AcceptHandler handler)
214 service_impl_.async_accept(impl, peer, peer_endpoint, handler);
217 private:
218 // The service that provides the platform-specific implementation.
219 service_impl_type& service_impl_;
222 } // namespace asio
223 } // namespace boost
225 #include <boost/asio/detail/pop_options.hpp>
227 #endif // BOOST_ASIO_SOCKET_ACCEPTOR_SERVICE_HPP