annotate DEPENDENCIES/generic/include/boost/asio/socket_acceptor_service.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 //
Chris@16 2 // socket_acceptor_service.hpp
Chris@16 3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
Chris@16 4 //
Chris@101 5 // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
Chris@16 6 //
Chris@16 7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
Chris@16 8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 9 //
Chris@16 10
Chris@16 11 #ifndef BOOST_ASIO_SOCKET_ACCEPTOR_SERVICE_HPP
Chris@16 12 #define BOOST_ASIO_SOCKET_ACCEPTOR_SERVICE_HPP
Chris@16 13
Chris@16 14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
Chris@16 15 # pragma once
Chris@16 16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
Chris@16 17
Chris@16 18 #include <boost/asio/detail/config.hpp>
Chris@16 19 #include <boost/asio/basic_socket.hpp>
Chris@16 20 #include <boost/asio/detail/type_traits.hpp>
Chris@16 21 #include <boost/asio/error.hpp>
Chris@16 22 #include <boost/asio/io_service.hpp>
Chris@16 23
Chris@16 24 #if defined(BOOST_ASIO_WINDOWS_RUNTIME)
Chris@16 25 # include <boost/asio/detail/null_socket_service.hpp>
Chris@16 26 #elif defined(BOOST_ASIO_HAS_IOCP)
Chris@16 27 # include <boost/asio/detail/win_iocp_socket_service.hpp>
Chris@16 28 #else
Chris@16 29 # include <boost/asio/detail/reactive_socket_service.hpp>
Chris@16 30 #endif
Chris@16 31
Chris@16 32 #include <boost/asio/detail/push_options.hpp>
Chris@16 33
Chris@16 34 namespace boost {
Chris@16 35 namespace asio {
Chris@16 36
Chris@16 37 /// Default service implementation for a socket acceptor.
Chris@16 38 template <typename Protocol>
Chris@16 39 class socket_acceptor_service
Chris@16 40 #if defined(GENERATING_DOCUMENTATION)
Chris@16 41 : public boost::asio::io_service::service
Chris@16 42 #else
Chris@16 43 : public boost::asio::detail::service_base<socket_acceptor_service<Protocol> >
Chris@16 44 #endif
Chris@16 45 {
Chris@16 46 public:
Chris@16 47 #if defined(GENERATING_DOCUMENTATION)
Chris@16 48 /// The unique service identifier.
Chris@16 49 static boost::asio::io_service::id id;
Chris@16 50 #endif
Chris@16 51
Chris@16 52 /// The protocol type.
Chris@16 53 typedef Protocol protocol_type;
Chris@16 54
Chris@16 55 /// The endpoint type.
Chris@16 56 typedef typename protocol_type::endpoint endpoint_type;
Chris@16 57
Chris@16 58 private:
Chris@16 59 // The type of the platform-specific implementation.
Chris@16 60 #if defined(BOOST_ASIO_WINDOWS_RUNTIME)
Chris@16 61 typedef detail::null_socket_service<Protocol> service_impl_type;
Chris@16 62 #elif defined(BOOST_ASIO_HAS_IOCP)
Chris@16 63 typedef detail::win_iocp_socket_service<Protocol> service_impl_type;
Chris@16 64 #else
Chris@16 65 typedef detail::reactive_socket_service<Protocol> service_impl_type;
Chris@16 66 #endif
Chris@16 67
Chris@16 68 public:
Chris@16 69 /// The native type of the socket acceptor.
Chris@16 70 #if defined(GENERATING_DOCUMENTATION)
Chris@16 71 typedef implementation_defined implementation_type;
Chris@16 72 #else
Chris@16 73 typedef typename service_impl_type::implementation_type implementation_type;
Chris@16 74 #endif
Chris@16 75
Chris@16 76 /// (Deprecated: Use native_handle_type.) The native acceptor type.
Chris@16 77 #if defined(GENERATING_DOCUMENTATION)
Chris@16 78 typedef implementation_defined native_type;
Chris@16 79 #else
Chris@16 80 typedef typename service_impl_type::native_handle_type native_type;
Chris@16 81 #endif
Chris@16 82
Chris@16 83 /// The native acceptor type.
Chris@16 84 #if defined(GENERATING_DOCUMENTATION)
Chris@16 85 typedef implementation_defined native_handle_type;
Chris@16 86 #else
Chris@16 87 typedef typename service_impl_type::native_handle_type native_handle_type;
Chris@16 88 #endif
Chris@16 89
Chris@16 90 /// Construct a new socket acceptor service for the specified io_service.
Chris@16 91 explicit socket_acceptor_service(boost::asio::io_service& io_service)
Chris@16 92 : boost::asio::detail::service_base<
Chris@16 93 socket_acceptor_service<Protocol> >(io_service),
Chris@16 94 service_impl_(io_service)
Chris@16 95 {
Chris@16 96 }
Chris@16 97
Chris@16 98 /// Construct a new socket acceptor implementation.
Chris@16 99 void construct(implementation_type& impl)
Chris@16 100 {
Chris@16 101 service_impl_.construct(impl);
Chris@16 102 }
Chris@16 103
Chris@16 104 #if defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
Chris@16 105 /// Move-construct a new socket acceptor implementation.
Chris@16 106 void move_construct(implementation_type& impl,
Chris@16 107 implementation_type& other_impl)
Chris@16 108 {
Chris@16 109 service_impl_.move_construct(impl, other_impl);
Chris@16 110 }
Chris@16 111
Chris@16 112 /// Move-assign from another socket acceptor implementation.
Chris@16 113 void move_assign(implementation_type& impl,
Chris@16 114 socket_acceptor_service& other_service,
Chris@16 115 implementation_type& other_impl)
Chris@16 116 {
Chris@16 117 service_impl_.move_assign(impl, other_service.service_impl_, other_impl);
Chris@16 118 }
Chris@16 119
Chris@16 120 /// Move-construct a new socket acceptor implementation from another protocol
Chris@16 121 /// type.
Chris@16 122 template <typename Protocol1>
Chris@16 123 void converting_move_construct(implementation_type& impl,
Chris@16 124 typename socket_acceptor_service<
Chris@16 125 Protocol1>::implementation_type& other_impl,
Chris@16 126 typename enable_if<is_convertible<
Chris@16 127 Protocol1, Protocol>::value>::type* = 0)
Chris@16 128 {
Chris@16 129 service_impl_.template converting_move_construct<Protocol1>(
Chris@16 130 impl, other_impl);
Chris@16 131 }
Chris@16 132 #endif // defined(BOOST_ASIO_HAS_MOVE) || defined(GENERATING_DOCUMENTATION)
Chris@16 133
Chris@16 134 /// Destroy a socket acceptor implementation.
Chris@16 135 void destroy(implementation_type& impl)
Chris@16 136 {
Chris@16 137 service_impl_.destroy(impl);
Chris@16 138 }
Chris@16 139
Chris@16 140 /// Open a new socket acceptor implementation.
Chris@16 141 boost::system::error_code open(implementation_type& impl,
Chris@16 142 const protocol_type& protocol, boost::system::error_code& ec)
Chris@16 143 {
Chris@16 144 return service_impl_.open(impl, protocol, ec);
Chris@16 145 }
Chris@16 146
Chris@16 147 /// Assign an existing native acceptor to a socket acceptor.
Chris@16 148 boost::system::error_code assign(implementation_type& impl,
Chris@16 149 const protocol_type& protocol, const native_handle_type& native_acceptor,
Chris@16 150 boost::system::error_code& ec)
Chris@16 151 {
Chris@16 152 return service_impl_.assign(impl, protocol, native_acceptor, ec);
Chris@16 153 }
Chris@16 154
Chris@16 155 /// Determine whether the acceptor is open.
Chris@16 156 bool is_open(const implementation_type& impl) const
Chris@16 157 {
Chris@16 158 return service_impl_.is_open(impl);
Chris@16 159 }
Chris@16 160
Chris@16 161 /// Cancel all asynchronous operations associated with the acceptor.
Chris@16 162 boost::system::error_code cancel(implementation_type& impl,
Chris@16 163 boost::system::error_code& ec)
Chris@16 164 {
Chris@16 165 return service_impl_.cancel(impl, ec);
Chris@16 166 }
Chris@16 167
Chris@16 168 /// Bind the socket acceptor to the specified local endpoint.
Chris@16 169 boost::system::error_code bind(implementation_type& impl,
Chris@16 170 const endpoint_type& endpoint, boost::system::error_code& ec)
Chris@16 171 {
Chris@16 172 return service_impl_.bind(impl, endpoint, ec);
Chris@16 173 }
Chris@16 174
Chris@16 175 /// Place the socket acceptor into the state where it will listen for new
Chris@16 176 /// connections.
Chris@16 177 boost::system::error_code listen(implementation_type& impl, int backlog,
Chris@16 178 boost::system::error_code& ec)
Chris@16 179 {
Chris@16 180 return service_impl_.listen(impl, backlog, ec);
Chris@16 181 }
Chris@16 182
Chris@16 183 /// Close a socket acceptor implementation.
Chris@16 184 boost::system::error_code close(implementation_type& impl,
Chris@16 185 boost::system::error_code& ec)
Chris@16 186 {
Chris@16 187 return service_impl_.close(impl, ec);
Chris@16 188 }
Chris@16 189
Chris@16 190 /// (Deprecated: Use native_handle().) Get the native acceptor implementation.
Chris@16 191 native_type native(implementation_type& impl)
Chris@16 192 {
Chris@16 193 return service_impl_.native_handle(impl);
Chris@16 194 }
Chris@16 195
Chris@16 196 /// Get the native acceptor implementation.
Chris@16 197 native_handle_type native_handle(implementation_type& impl)
Chris@16 198 {
Chris@16 199 return service_impl_.native_handle(impl);
Chris@16 200 }
Chris@16 201
Chris@16 202 /// Set a socket option.
Chris@16 203 template <typename SettableSocketOption>
Chris@16 204 boost::system::error_code set_option(implementation_type& impl,
Chris@16 205 const SettableSocketOption& option, boost::system::error_code& ec)
Chris@16 206 {
Chris@16 207 return service_impl_.set_option(impl, option, ec);
Chris@16 208 }
Chris@16 209
Chris@16 210 /// Get a socket option.
Chris@16 211 template <typename GettableSocketOption>
Chris@16 212 boost::system::error_code get_option(const implementation_type& impl,
Chris@16 213 GettableSocketOption& option, boost::system::error_code& ec) const
Chris@16 214 {
Chris@16 215 return service_impl_.get_option(impl, option, ec);
Chris@16 216 }
Chris@16 217
Chris@16 218 /// Perform an IO control command on the socket.
Chris@16 219 template <typename IoControlCommand>
Chris@16 220 boost::system::error_code io_control(implementation_type& impl,
Chris@16 221 IoControlCommand& command, boost::system::error_code& ec)
Chris@16 222 {
Chris@16 223 return service_impl_.io_control(impl, command, ec);
Chris@16 224 }
Chris@16 225
Chris@16 226 /// Gets the non-blocking mode of the acceptor.
Chris@16 227 bool non_blocking(const implementation_type& impl) const
Chris@16 228 {
Chris@16 229 return service_impl_.non_blocking(impl);
Chris@16 230 }
Chris@16 231
Chris@16 232 /// Sets the non-blocking mode of the acceptor.
Chris@16 233 boost::system::error_code non_blocking(implementation_type& impl,
Chris@16 234 bool mode, boost::system::error_code& ec)
Chris@16 235 {
Chris@16 236 return service_impl_.non_blocking(impl, mode, ec);
Chris@16 237 }
Chris@16 238
Chris@16 239 /// Gets the non-blocking mode of the native acceptor implementation.
Chris@16 240 bool native_non_blocking(const implementation_type& impl) const
Chris@16 241 {
Chris@16 242 return service_impl_.native_non_blocking(impl);
Chris@16 243 }
Chris@16 244
Chris@16 245 /// Sets the non-blocking mode of the native acceptor implementation.
Chris@16 246 boost::system::error_code native_non_blocking(implementation_type& impl,
Chris@16 247 bool mode, boost::system::error_code& ec)
Chris@16 248 {
Chris@16 249 return service_impl_.native_non_blocking(impl, mode, ec);
Chris@16 250 }
Chris@16 251
Chris@16 252 /// Get the local endpoint.
Chris@16 253 endpoint_type local_endpoint(const implementation_type& impl,
Chris@16 254 boost::system::error_code& ec) const
Chris@16 255 {
Chris@16 256 return service_impl_.local_endpoint(impl, ec);
Chris@16 257 }
Chris@16 258
Chris@16 259 /// Accept a new connection.
Chris@16 260 template <typename Protocol1, typename SocketService>
Chris@16 261 boost::system::error_code accept(implementation_type& impl,
Chris@16 262 basic_socket<Protocol1, SocketService>& peer,
Chris@16 263 endpoint_type* peer_endpoint, boost::system::error_code& ec,
Chris@16 264 typename enable_if<is_convertible<Protocol, Protocol1>::value>::type* = 0)
Chris@16 265 {
Chris@16 266 return service_impl_.accept(impl, peer, peer_endpoint, ec);
Chris@16 267 }
Chris@16 268
Chris@16 269 /// Start an asynchronous accept.
Chris@16 270 template <typename Protocol1, typename SocketService, typename AcceptHandler>
Chris@16 271 BOOST_ASIO_INITFN_RESULT_TYPE(AcceptHandler,
Chris@16 272 void (boost::system::error_code))
Chris@16 273 async_accept(implementation_type& impl,
Chris@16 274 basic_socket<Protocol1, SocketService>& peer,
Chris@16 275 endpoint_type* peer_endpoint,
Chris@16 276 BOOST_ASIO_MOVE_ARG(AcceptHandler) handler,
Chris@16 277 typename enable_if<is_convertible<Protocol, Protocol1>::value>::type* = 0)
Chris@16 278 {
Chris@16 279 detail::async_result_init<
Chris@16 280 AcceptHandler, void (boost::system::error_code)> init(
Chris@16 281 BOOST_ASIO_MOVE_CAST(AcceptHandler)(handler));
Chris@16 282
Chris@16 283 service_impl_.async_accept(impl, peer, peer_endpoint, init.handler);
Chris@16 284
Chris@16 285 return init.result.get();
Chris@16 286 }
Chris@16 287
Chris@16 288 private:
Chris@16 289 // Destroy all user-defined handler objects owned by the service.
Chris@16 290 void shutdown_service()
Chris@16 291 {
Chris@16 292 service_impl_.shutdown_service();
Chris@16 293 }
Chris@16 294
Chris@16 295 // The platform-specific implementation.
Chris@16 296 service_impl_type service_impl_;
Chris@16 297 };
Chris@16 298
Chris@16 299 } // namespace asio
Chris@16 300 } // namespace boost
Chris@16 301
Chris@16 302 #include <boost/asio/detail/pop_options.hpp>
Chris@16 303
Chris@16 304 #endif // BOOST_ASIO_SOCKET_ACCEPTOR_SERVICE_HPP