2
// stream_handle_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_WINDOWS_STREAM_HANDLE_SERVICE_HPP
12
#define ASIO_WINDOWS_STREAM_HANDLE_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/service_base.hpp"
28
#include "asio/detail/win_iocp_handle_service.hpp"
30
#if !defined(ASIO_DISABLE_WINDOWS_STREAM_HANDLE)
31
# if defined(ASIO_HAS_IOCP)
32
# define ASIO_HAS_WINDOWS_STREAM_HANDLE 1
33
# endif // defined(ASIO_HAS_IOCP)
34
#endif // !defined(ASIO_DISABLE_WINDOWS_STREAM_HANDLE)
36
#if defined(ASIO_HAS_WINDOWS_STREAM_HANDLE) \
37
|| defined(GENERATING_DOCUMENTATION)
42
/// Default service implementation for a stream handle.
43
class stream_handle_service
44
#if defined(GENERATING_DOCUMENTATION)
45
: public asio::io_service::service
47
: public asio::detail::service_base<stream_handle_service>
51
#if defined(GENERATING_DOCUMENTATION)
52
/// The unique service identifier.
53
static asio::io_service::id id;
57
// The type of the platform-specific implementation.
58
typedef detail::win_iocp_handle_service service_impl_type;
61
/// The type of a stream handle implementation.
62
#if defined(GENERATING_DOCUMENTATION)
63
typedef implementation_defined implementation_type;
65
typedef service_impl_type::implementation_type implementation_type;
68
/// The native handle type.
69
#if defined(GENERATING_DOCUMENTATION)
70
typedef implementation_defined native_type;
72
typedef service_impl_type::native_type native_type;
75
/// Construct a new stream handle service for the specified io_service.
76
explicit stream_handle_service(asio::io_service& io_service)
77
: asio::detail::service_base<stream_handle_service>(io_service),
78
service_impl_(asio::use_service<service_impl_type>(io_service))
82
/// Destroy all user-defined handler objects owned by the service.
83
void shutdown_service()
87
/// Construct a new stream handle implementation.
88
void construct(implementation_type& impl)
90
service_impl_.construct(impl);
93
/// Destroy a stream handle implementation.
94
void destroy(implementation_type& impl)
96
service_impl_.destroy(impl);
99
/// Assign an existing native handle to a stream handle.
100
asio::error_code assign(implementation_type& impl,
101
const native_type& native_handle, asio::error_code& ec)
103
return service_impl_.assign(impl, native_handle, ec);
106
/// Determine whether the handle is open.
107
bool is_open(const implementation_type& impl) const
109
return service_impl_.is_open(impl);
112
/// Close a stream handle implementation.
113
asio::error_code close(implementation_type& impl,
114
asio::error_code& ec)
116
return service_impl_.close(impl, ec);
119
/// Get the native handle implementation.
120
native_type native(implementation_type& impl)
122
return service_impl_.native(impl);
125
/// Cancel all asynchronous operations associated with the handle.
126
asio::error_code cancel(implementation_type& impl,
127
asio::error_code& ec)
129
return service_impl_.cancel(impl, ec);
132
/// Write the given data to the stream.
133
template <typename ConstBufferSequence>
134
std::size_t write_some(implementation_type& impl,
135
const ConstBufferSequence& buffers, asio::error_code& ec)
137
return service_impl_.write_some(impl, buffers, ec);
140
/// Start an asynchronous write.
141
template <typename ConstBufferSequence, typename WriteHandler>
142
void async_write_some(implementation_type& impl,
143
const ConstBufferSequence& buffers, WriteHandler handler)
145
service_impl_.async_write_some(impl, buffers, handler);
148
/// Read some data from the stream.
149
template <typename MutableBufferSequence>
150
std::size_t read_some(implementation_type& impl,
151
const MutableBufferSequence& buffers, asio::error_code& ec)
153
return service_impl_.read_some(impl, buffers, ec);
156
/// Start an asynchronous read.
157
template <typename MutableBufferSequence, typename ReadHandler>
158
void async_read_some(implementation_type& impl,
159
const MutableBufferSequence& buffers, ReadHandler handler)
161
service_impl_.async_read_some(impl, buffers, handler);
165
// The service that provides the platform-specific implementation.
166
service_impl_type& service_impl_;
169
} // namespace windows
172
#endif // defined(ASIO_HAS_WINDOWS_STREAM_HANDLE)
173
// || defined(GENERATING_DOCUMENTATION)
175
#include "asio/detail/pop_options.hpp"
177
#endif // ASIO_WINDOWS_STREAM_HANDLE_SERVICE_HPP