2
// stream_descriptor_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_POSIX_STREAM_DESCRIPTOR_SERVICE_HPP
12
#define ASIO_POSIX_STREAM_DESCRIPTOR_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/detail/push_options.hpp"
22
#include <boost/config.hpp>
23
#include "asio/detail/pop_options.hpp"
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_descriptor_service.hpp"
33
#if !defined(ASIO_DISABLE_POSIX_STREAM_DESCRIPTOR)
34
# if !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
35
# define ASIO_HAS_POSIX_STREAM_DESCRIPTOR 1
36
# endif // !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
37
#endif // !defined(ASIO_DISABLE_POSIX_STREAM_DESCRIPTOR)
39
#if defined(ASIO_HAS_POSIX_STREAM_DESCRIPTOR) \
40
|| defined(GENERATING_DOCUMENTATION)
45
/// Default service implementation for a stream descriptor.
46
class stream_descriptor_service
47
#if defined(GENERATING_DOCUMENTATION)
48
: public asio::io_service::service
50
: public asio::detail::service_base<stream_descriptor_service>
54
#if defined(GENERATING_DOCUMENTATION)
55
/// The unique service identifier.
56
static asio::io_service::id id;
60
// The type of the platform-specific implementation.
61
#if defined(ASIO_HAS_EPOLL)
62
typedef detail::reactive_descriptor_service<
63
detail::epoll_reactor<false> > service_impl_type;
64
#elif defined(ASIO_HAS_KQUEUE)
65
typedef detail::reactive_descriptor_service<
66
detail::kqueue_reactor<false> > service_impl_type;
67
#elif defined(ASIO_HAS_DEV_POLL)
68
typedef detail::reactive_descriptor_service<
69
detail::dev_poll_reactor<false> > service_impl_type;
71
typedef detail::reactive_descriptor_service<
72
detail::select_reactor<false> > service_impl_type;
76
/// The type of a stream descriptor implementation.
77
#if defined(GENERATING_DOCUMENTATION)
78
typedef implementation_defined implementation_type;
80
typedef service_impl_type::implementation_type implementation_type;
83
/// The native descriptor type.
84
#if defined(GENERATING_DOCUMENTATION)
85
typedef implementation_defined native_type;
87
typedef service_impl_type::native_type native_type;
90
/// Construct a new stream descriptor service for the specified io_service.
91
explicit stream_descriptor_service(asio::io_service& io_service)
92
: asio::detail::service_base<stream_descriptor_service>(io_service),
93
service_impl_(asio::use_service<service_impl_type>(io_service))
97
/// Destroy all user-defined descriptorr objects owned by the service.
98
void shutdown_service()
102
/// Construct a new stream descriptor implementation.
103
void construct(implementation_type& impl)
105
service_impl_.construct(impl);
108
/// Destroy a stream descriptor implementation.
109
void destroy(implementation_type& impl)
111
service_impl_.destroy(impl);
114
/// Assign an existing native descriptor to a stream descriptor.
115
asio::error_code assign(implementation_type& impl,
116
const native_type& native_descriptor, asio::error_code& ec)
118
return service_impl_.assign(impl, native_descriptor, ec);
121
/// Determine whether the descriptor is open.
122
bool is_open(const implementation_type& impl) const
124
return service_impl_.is_open(impl);
127
/// Close a stream descriptor implementation.
128
asio::error_code close(implementation_type& impl,
129
asio::error_code& ec)
131
return service_impl_.close(impl, ec);
134
/// Get the native descriptor implementation.
135
native_type native(implementation_type& impl)
137
return service_impl_.native(impl);
140
/// Cancel all asynchronous operations associated with the descriptor.
141
asio::error_code cancel(implementation_type& impl,
142
asio::error_code& ec)
144
return service_impl_.cancel(impl, ec);
147
/// Perform an IO control command on the descriptor.
148
template <typename IoControlCommand>
149
asio::error_code io_control(implementation_type& impl,
150
IoControlCommand& command, asio::error_code& ec)
152
return service_impl_.io_control(impl, command, ec);
155
/// Write the given data to the stream.
156
template <typename ConstBufferSequence>
157
std::size_t write_some(implementation_type& impl,
158
const ConstBufferSequence& buffers, asio::error_code& ec)
160
return service_impl_.write_some(impl, buffers, ec);
163
/// Start an asynchronous write.
164
template <typename ConstBufferSequence, typename WriteHandler>
165
void async_write_some(implementation_type& impl,
166
const ConstBufferSequence& buffers, WriteHandler descriptorr)
168
service_impl_.async_write_some(impl, buffers, descriptorr);
171
/// Read some data from the stream.
172
template <typename MutableBufferSequence>
173
std::size_t read_some(implementation_type& impl,
174
const MutableBufferSequence& buffers, asio::error_code& ec)
176
return service_impl_.read_some(impl, buffers, ec);
179
/// Start an asynchronous read.
180
template <typename MutableBufferSequence, typename ReadHandler>
181
void async_read_some(implementation_type& impl,
182
const MutableBufferSequence& buffers, ReadHandler descriptorr)
184
service_impl_.async_read_some(impl, buffers, descriptorr);
188
// The service that provides the platform-specific implementation.
189
service_impl_type& service_impl_;
195
#endif // defined(ASIO_HAS_POSIX_STREAM_DESCRIPTOR)
196
// || defined(GENERATING_DOCUMENTATION)
198
#include "asio/detail/pop_options.hpp"
200
#endif // ASIO_POSIX_STREAM_DESCRIPTOR_SERVICE_HPP