Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / asio / detail / winrt_ssocket_service_base.hpp @ 2486

History | View | Annotate | Download (12.1 kB)

1 2486 sjacqu01
//
2 2486 sjacqu01
// detail/winrt_ssocket_service_base.hpp
3 2486 sjacqu01
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 2486 sjacqu01
//
5 2486 sjacqu01
// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 2486 sjacqu01
//
7 2486 sjacqu01
// Distributed under the Boost Software License, Version 1.0. (See accompanying
8 2486 sjacqu01
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 2486 sjacqu01
//
10 2486 sjacqu01
11 2486 sjacqu01
#ifndef BOOST_ASIO_DETAIL_WINRT_SSOCKET_SERVICE_BASE_HPP
12 2486 sjacqu01
#define BOOST_ASIO_DETAIL_WINRT_SSOCKET_SERVICE_BASE_HPP
13 2486 sjacqu01
14 2486 sjacqu01
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 2486 sjacqu01
# pragma once
16 2486 sjacqu01
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 2486 sjacqu01
18 2486 sjacqu01
#include <boost/asio/detail/config.hpp>
19 2486 sjacqu01
20 2486 sjacqu01
#if defined(BOOST_ASIO_WINDOWS_RUNTIME)
21 2486 sjacqu01
22 2486 sjacqu01
#include <boost/asio/buffer.hpp>
23 2486 sjacqu01
#include <boost/asio/error.hpp>
24 2486 sjacqu01
#include <boost/asio/io_service.hpp>
25 2486 sjacqu01
#include <boost/asio/socket_base.hpp>
26 2486 sjacqu01
#include <boost/asio/detail/addressof.hpp>
27 2486 sjacqu01
#include <boost/asio/detail/buffer_sequence_adapter.hpp>
28 2486 sjacqu01
#include <boost/asio/detail/socket_types.hpp>
29 2486 sjacqu01
#include <boost/asio/detail/winrt_async_manager.hpp>
30 2486 sjacqu01
#include <boost/asio/detail/winrt_socket_recv_op.hpp>
31 2486 sjacqu01
#include <boost/asio/detail/winrt_socket_send_op.hpp>
32 2486 sjacqu01
33 2486 sjacqu01
#include <boost/asio/detail/push_options.hpp>
34 2486 sjacqu01
35 2486 sjacqu01
namespace boost {
36 2486 sjacqu01
namespace asio {
37 2486 sjacqu01
namespace detail {
38 2486 sjacqu01
39 2486 sjacqu01
class winrt_ssocket_service_base
40 2486 sjacqu01
{
41 2486 sjacqu01
public:
42 2486 sjacqu01
  // The native type of a socket.
43 2486 sjacqu01
  typedef Windows::Networking::Sockets::StreamSocket^ native_handle_type;
44 2486 sjacqu01
45 2486 sjacqu01
  // The implementation type of the socket.
46 2486 sjacqu01
  struct base_implementation_type
47 2486 sjacqu01
  {
48 2486 sjacqu01
    // Default constructor.
49 2486 sjacqu01
    base_implementation_type()
50 2486 sjacqu01
      : socket_(nullptr),
51 2486 sjacqu01
        next_(0),
52 2486 sjacqu01
        prev_(0)
53 2486 sjacqu01
    {
54 2486 sjacqu01
    }
55 2486 sjacqu01
56 2486 sjacqu01
    // The underlying native socket.
57 2486 sjacqu01
    native_handle_type socket_;
58 2486 sjacqu01
59 2486 sjacqu01
    // Pointers to adjacent socket implementations in linked list.
60 2486 sjacqu01
    base_implementation_type* next_;
61 2486 sjacqu01
    base_implementation_type* prev_;
62 2486 sjacqu01
  };
63 2486 sjacqu01
64 2486 sjacqu01
  // Constructor.
65 2486 sjacqu01
  BOOST_ASIO_DECL winrt_ssocket_service_base(
66 2486 sjacqu01
      boost::asio::io_service& io_service);
67 2486 sjacqu01
68 2486 sjacqu01
  // Destroy all user-defined handler objects owned by the service.
69 2486 sjacqu01
  BOOST_ASIO_DECL void shutdown_service();
70 2486 sjacqu01
71 2486 sjacqu01
  // Construct a new socket implementation.
72 2486 sjacqu01
  BOOST_ASIO_DECL void construct(base_implementation_type&);
73 2486 sjacqu01
74 2486 sjacqu01
  // Move-construct a new socket implementation.
75 2486 sjacqu01
  BOOST_ASIO_DECL void base_move_construct(base_implementation_type& impl,
76 2486 sjacqu01
      base_implementation_type& other_impl);
77 2486 sjacqu01
78 2486 sjacqu01
  // Move-assign from another socket implementation.
79 2486 sjacqu01
  BOOST_ASIO_DECL void base_move_assign(base_implementation_type& impl,
80 2486 sjacqu01
      winrt_ssocket_service_base& other_service,
81 2486 sjacqu01
      base_implementation_type& other_impl);
82 2486 sjacqu01
83 2486 sjacqu01
  // Destroy a socket implementation.
84 2486 sjacqu01
  BOOST_ASIO_DECL void destroy(base_implementation_type& impl);
85 2486 sjacqu01
86 2486 sjacqu01
  // Determine whether the socket is open.
87 2486 sjacqu01
  bool is_open(const base_implementation_type& impl) const
88 2486 sjacqu01
  {
89 2486 sjacqu01
    return impl.socket_ != nullptr;
90 2486 sjacqu01
  }
91 2486 sjacqu01
92 2486 sjacqu01
  // Destroy a socket implementation.
93 2486 sjacqu01
  BOOST_ASIO_DECL boost::system::error_code close(
94 2486 sjacqu01
      base_implementation_type& impl, boost::system::error_code& ec);
95 2486 sjacqu01
96 2486 sjacqu01
  // Get the native socket representation.
97 2486 sjacqu01
  native_handle_type native_handle(base_implementation_type& impl)
98 2486 sjacqu01
  {
99 2486 sjacqu01
    return impl.socket_;
100 2486 sjacqu01
  }
101 2486 sjacqu01
102 2486 sjacqu01
  // Cancel all operations associated with the socket.
103 2486 sjacqu01
  boost::system::error_code cancel(base_implementation_type&,
104 2486 sjacqu01
      boost::system::error_code& ec)
105 2486 sjacqu01
  {
106 2486 sjacqu01
    ec = boost::asio::error::operation_not_supported;
107 2486 sjacqu01
    return ec;
108 2486 sjacqu01
  }
109 2486 sjacqu01
110 2486 sjacqu01
  // Determine whether the socket is at the out-of-band data mark.
111 2486 sjacqu01
  bool at_mark(const base_implementation_type&,
112 2486 sjacqu01
      boost::system::error_code& ec) const
113 2486 sjacqu01
  {
114 2486 sjacqu01
    ec = boost::asio::error::operation_not_supported;
115 2486 sjacqu01
    return false;
116 2486 sjacqu01
  }
117 2486 sjacqu01
118 2486 sjacqu01
  // Determine the number of bytes available for reading.
119 2486 sjacqu01
  std::size_t available(const base_implementation_type&,
120 2486 sjacqu01
      boost::system::error_code& ec) const
121 2486 sjacqu01
  {
122 2486 sjacqu01
    ec = boost::asio::error::operation_not_supported;
123 2486 sjacqu01
    return 0;
124 2486 sjacqu01
  }
125 2486 sjacqu01
126 2486 sjacqu01
  // Perform an IO control command on the socket.
127 2486 sjacqu01
  template <typename IO_Control_Command>
128 2486 sjacqu01
  boost::system::error_code io_control(base_implementation_type&,
129 2486 sjacqu01
      IO_Control_Command&, boost::system::error_code& ec)
130 2486 sjacqu01
  {
131 2486 sjacqu01
    ec = boost::asio::error::operation_not_supported;
132 2486 sjacqu01
    return ec;
133 2486 sjacqu01
  }
134 2486 sjacqu01
135 2486 sjacqu01
  // Gets the non-blocking mode of the socket.
136 2486 sjacqu01
  bool non_blocking(const base_implementation_type&) const
137 2486 sjacqu01
  {
138 2486 sjacqu01
    return false;
139 2486 sjacqu01
  }
140 2486 sjacqu01
141 2486 sjacqu01
  // Sets the non-blocking mode of the socket.
142 2486 sjacqu01
  boost::system::error_code non_blocking(base_implementation_type&,
143 2486 sjacqu01
      bool, boost::system::error_code& ec)
144 2486 sjacqu01
  {
145 2486 sjacqu01
    ec = boost::asio::error::operation_not_supported;
146 2486 sjacqu01
    return ec;
147 2486 sjacqu01
  }
148 2486 sjacqu01
149 2486 sjacqu01
  // Gets the non-blocking mode of the native socket implementation.
150 2486 sjacqu01
  bool native_non_blocking(const base_implementation_type&) const
151 2486 sjacqu01
  {
152 2486 sjacqu01
    return false;
153 2486 sjacqu01
  }
154 2486 sjacqu01
155 2486 sjacqu01
  // Sets the non-blocking mode of the native socket implementation.
156 2486 sjacqu01
  boost::system::error_code native_non_blocking(base_implementation_type&,
157 2486 sjacqu01
      bool, boost::system::error_code& ec)
158 2486 sjacqu01
  {
159 2486 sjacqu01
    ec = boost::asio::error::operation_not_supported;
160 2486 sjacqu01
    return ec;
161 2486 sjacqu01
  }
162 2486 sjacqu01
163 2486 sjacqu01
  // Disable sends or receives on the socket.
164 2486 sjacqu01
  boost::system::error_code shutdown(base_implementation_type&,
165 2486 sjacqu01
      socket_base::shutdown_type, boost::system::error_code& ec)
166 2486 sjacqu01
  {
167 2486 sjacqu01
    ec = boost::asio::error::operation_not_supported;
168 2486 sjacqu01
    return ec;
169 2486 sjacqu01
  }
170 2486 sjacqu01
171 2486 sjacqu01
  // Send the given data to the peer.
172 2486 sjacqu01
  template <typename ConstBufferSequence>
173 2486 sjacqu01
  std::size_t send(base_implementation_type& impl,
174 2486 sjacqu01
      const ConstBufferSequence& buffers,
175 2486 sjacqu01
      socket_base::message_flags flags, boost::system::error_code& ec)
176 2486 sjacqu01
  {
177 2486 sjacqu01
    return do_send(impl,
178 2486 sjacqu01
        buffer_sequence_adapter<boost::asio::const_buffer,
179 2486 sjacqu01
          ConstBufferSequence>::first(buffers), flags, ec);
180 2486 sjacqu01
  }
181 2486 sjacqu01
182 2486 sjacqu01
  // Wait until data can be sent without blocking.
183 2486 sjacqu01
  std::size_t send(base_implementation_type&, const null_buffers&,
184 2486 sjacqu01
      socket_base::message_flags, boost::system::error_code& ec)
185 2486 sjacqu01
  {
186 2486 sjacqu01
    ec = boost::asio::error::operation_not_supported;
187 2486 sjacqu01
    return 0;
188 2486 sjacqu01
  }
189 2486 sjacqu01
190 2486 sjacqu01
  // Start an asynchronous send. The data being sent must be valid for the
191 2486 sjacqu01
  // lifetime of the asynchronous operation.
192 2486 sjacqu01
  template <typename ConstBufferSequence, typename Handler>
193 2486 sjacqu01
  void async_send(base_implementation_type& impl,
194 2486 sjacqu01
      const ConstBufferSequence& buffers,
195 2486 sjacqu01
      socket_base::message_flags flags, Handler& handler)
196 2486 sjacqu01
  {
197 2486 sjacqu01
    bool is_continuation =
198 2486 sjacqu01
      boost_asio_handler_cont_helpers::is_continuation(handler);
199 2486 sjacqu01
200 2486 sjacqu01
    // Allocate and construct an operation to wrap the handler.
201 2486 sjacqu01
    typedef winrt_socket_send_op<ConstBufferSequence, Handler> op;
202 2486 sjacqu01
    typename op::ptr p = { boost::asio::detail::addressof(handler),
203 2486 sjacqu01
      boost_asio_handler_alloc_helpers::allocate(
204 2486 sjacqu01
        sizeof(op), handler), 0 };
205 2486 sjacqu01
    p.p = new (p.v) op(buffers, handler);
206 2486 sjacqu01
207 2486 sjacqu01
    BOOST_ASIO_HANDLER_CREATION((p.p, "socket", &impl, "async_send"));
208 2486 sjacqu01
209 2486 sjacqu01
    start_send_op(impl,
210 2486 sjacqu01
        buffer_sequence_adapter<boost::asio::const_buffer,
211 2486 sjacqu01
          ConstBufferSequence>::first(buffers),
212 2486 sjacqu01
        flags, p.p, is_continuation);
213 2486 sjacqu01
    p.v = p.p = 0;
214 2486 sjacqu01
  }
215 2486 sjacqu01
216 2486 sjacqu01
  // Start an asynchronous wait until data can be sent without blocking.
217 2486 sjacqu01
  template <typename Handler>
218 2486 sjacqu01
  void async_send(base_implementation_type&, const null_buffers&,
219 2486 sjacqu01
      socket_base::message_flags, Handler& handler)
220 2486 sjacqu01
  {
221 2486 sjacqu01
    boost::system::error_code ec = boost::asio::error::operation_not_supported;
222 2486 sjacqu01
    const std::size_t bytes_transferred = 0;
223 2486 sjacqu01
    io_service_.get_io_service().post(
224 2486 sjacqu01
        detail::bind_handler(handler, ec, bytes_transferred));
225 2486 sjacqu01
  }
226 2486 sjacqu01
227 2486 sjacqu01
  // Receive some data from the peer. Returns the number of bytes received.
228 2486 sjacqu01
  template <typename MutableBufferSequence>
229 2486 sjacqu01
  std::size_t receive(base_implementation_type& impl,
230 2486 sjacqu01
      const MutableBufferSequence& buffers,
231 2486 sjacqu01
      socket_base::message_flags flags, boost::system::error_code& ec)
232 2486 sjacqu01
  {
233 2486 sjacqu01
    return do_receive(impl,
234 2486 sjacqu01
        buffer_sequence_adapter<boost::asio::mutable_buffer,
235 2486 sjacqu01
          MutableBufferSequence>::first(buffers), flags, ec);
236 2486 sjacqu01
  }
237 2486 sjacqu01
238 2486 sjacqu01
  // Wait until data can be received without blocking.
239 2486 sjacqu01
  std::size_t receive(base_implementation_type&, const null_buffers&,
240 2486 sjacqu01
      socket_base::message_flags, boost::system::error_code& ec)
241 2486 sjacqu01
  {
242 2486 sjacqu01
    ec = boost::asio::error::operation_not_supported;
243 2486 sjacqu01
    return 0;
244 2486 sjacqu01
  }
245 2486 sjacqu01
246 2486 sjacqu01
  // Start an asynchronous receive. The buffer for the data being received
247 2486 sjacqu01
  // must be valid for the lifetime of the asynchronous operation.
248 2486 sjacqu01
  template <typename MutableBufferSequence, typename Handler>
249 2486 sjacqu01
  void async_receive(base_implementation_type& impl,
250 2486 sjacqu01
      const MutableBufferSequence& buffers,
251 2486 sjacqu01
      socket_base::message_flags flags, Handler& handler)
252 2486 sjacqu01
  {
253 2486 sjacqu01
    bool is_continuation =
254 2486 sjacqu01
      boost_asio_handler_cont_helpers::is_continuation(handler);
255 2486 sjacqu01
256 2486 sjacqu01
    // Allocate and construct an operation to wrap the handler.
257 2486 sjacqu01
    typedef winrt_socket_recv_op<MutableBufferSequence, Handler> op;
258 2486 sjacqu01
    typename op::ptr p = { boost::asio::detail::addressof(handler),
259 2486 sjacqu01
      boost_asio_handler_alloc_helpers::allocate(
260 2486 sjacqu01
        sizeof(op), handler), 0 };
261 2486 sjacqu01
    p.p = new (p.v) op(buffers, handler);
262 2486 sjacqu01
263 2486 sjacqu01
    BOOST_ASIO_HANDLER_CREATION((p.p, "socket", &impl, "async_receive"));
264 2486 sjacqu01
265 2486 sjacqu01
    start_receive_op(impl,
266 2486 sjacqu01
        buffer_sequence_adapter<boost::asio::mutable_buffer,
267 2486 sjacqu01
          MutableBufferSequence>::first(buffers),
268 2486 sjacqu01
        flags, p.p, is_continuation);
269 2486 sjacqu01
    p.v = p.p = 0;
270 2486 sjacqu01
  }
271 2486 sjacqu01
272 2486 sjacqu01
  // Wait until data can be received without blocking.
273 2486 sjacqu01
  template <typename Handler>
274 2486 sjacqu01
  void async_receive(base_implementation_type&, const null_buffers&,
275 2486 sjacqu01
      socket_base::message_flags, Handler& handler)
276 2486 sjacqu01
  {
277 2486 sjacqu01
    boost::system::error_code ec = boost::asio::error::operation_not_supported;
278 2486 sjacqu01
    const std::size_t bytes_transferred = 0;
279 2486 sjacqu01
    io_service_.get_io_service().post(
280 2486 sjacqu01
        detail::bind_handler(handler, ec, bytes_transferred));
281 2486 sjacqu01
  }
282 2486 sjacqu01
283 2486 sjacqu01
protected:
284 2486 sjacqu01
  // Helper function to obtain endpoints associated with the connection.
285 2486 sjacqu01
  BOOST_ASIO_DECL std::size_t do_get_endpoint(
286 2486 sjacqu01
      const base_implementation_type& impl, bool local,
287 2486 sjacqu01
      void* addr, std::size_t addr_len, boost::system::error_code& ec) const;
288 2486 sjacqu01
289 2486 sjacqu01
  // Helper function to set a socket option.
290 2486 sjacqu01
  BOOST_ASIO_DECL boost::system::error_code do_set_option(
291 2486 sjacqu01
      base_implementation_type& impl,
292 2486 sjacqu01
      int level, int optname, const void* optval,
293 2486 sjacqu01
      std::size_t optlen, boost::system::error_code& ec);
294 2486 sjacqu01
295 2486 sjacqu01
  // Helper function to get a socket option.
296 2486 sjacqu01
  BOOST_ASIO_DECL void do_get_option(
297 2486 sjacqu01
      const base_implementation_type& impl,
298 2486 sjacqu01
      int level, int optname, void* optval,
299 2486 sjacqu01
      std::size_t* optlen, boost::system::error_code& ec) const;
300 2486 sjacqu01
301 2486 sjacqu01
  // Helper function to perform a synchronous connect.
302 2486 sjacqu01
  BOOST_ASIO_DECL boost::system::error_code do_connect(
303 2486 sjacqu01
      base_implementation_type& impl,
304 2486 sjacqu01
      const void* addr, boost::system::error_code& ec);
305 2486 sjacqu01
306 2486 sjacqu01
  // Helper function to start an asynchronous connect.
307 2486 sjacqu01
  BOOST_ASIO_DECL void start_connect_op(
308 2486 sjacqu01
      base_implementation_type& impl, const void* addr,
309 2486 sjacqu01
      winrt_async_op<void>* op, bool is_continuation);
310 2486 sjacqu01
311 2486 sjacqu01
  // Helper function to perform a synchronous send.
312 2486 sjacqu01
  BOOST_ASIO_DECL std::size_t do_send(
313 2486 sjacqu01
      base_implementation_type& impl, const boost::asio::const_buffer& data,
314 2486 sjacqu01
      socket_base::message_flags flags, boost::system::error_code& ec);
315 2486 sjacqu01
316 2486 sjacqu01
  // Helper function to start an asynchronous send.
317 2486 sjacqu01
  BOOST_ASIO_DECL void start_send_op(base_implementation_type& impl,
318 2486 sjacqu01
      const boost::asio::const_buffer& data, socket_base::message_flags flags,
319 2486 sjacqu01
      winrt_async_op<unsigned int>* op, bool is_continuation);
320 2486 sjacqu01
321 2486 sjacqu01
  // Helper function to perform a synchronous receive.
322 2486 sjacqu01
  BOOST_ASIO_DECL std::size_t do_receive(
323 2486 sjacqu01
      base_implementation_type& impl, const boost::asio::mutable_buffer& data,
324 2486 sjacqu01
      socket_base::message_flags flags, boost::system::error_code& ec);
325 2486 sjacqu01
326 2486 sjacqu01
  // Helper function to start an asynchronous receive.
327 2486 sjacqu01
  BOOST_ASIO_DECL void start_receive_op(base_implementation_type& impl,
328 2486 sjacqu01
      const boost::asio::mutable_buffer& data, socket_base::message_flags flags,
329 2486 sjacqu01
      winrt_async_op<Windows::Storage::Streams::IBuffer^>* op,
330 2486 sjacqu01
      bool is_continuation);
331 2486 sjacqu01
332 2486 sjacqu01
  // The io_service implementation used for delivering completions.
333 2486 sjacqu01
  io_service_impl& io_service_;
334 2486 sjacqu01
335 2486 sjacqu01
  // The manager that keeps track of outstanding operations.
336 2486 sjacqu01
  winrt_async_manager& async_manager_;
337 2486 sjacqu01
338 2486 sjacqu01
  // Mutex to protect access to the linked list of implementations.
339 2486 sjacqu01
  boost::asio::detail::mutex mutex_;
340 2486 sjacqu01
341 2486 sjacqu01
  // The head of a linked list of all implementations.
342 2486 sjacqu01
  base_implementation_type* impl_list_;
343 2486 sjacqu01
};
344 2486 sjacqu01
345 2486 sjacqu01
} // namespace detail
346 2486 sjacqu01
} // namespace asio
347 2486 sjacqu01
} // namespace boost
348 2486 sjacqu01
349 2486 sjacqu01
#include <boost/asio/detail/pop_options.hpp>
350 2486 sjacqu01
351 2486 sjacqu01
#if defined(BOOST_ASIO_HEADER_ONLY)
352 2486 sjacqu01
# include <boost/asio/detail/impl/winrt_ssocket_service_base.ipp>
353 2486 sjacqu01
#endif // defined(BOOST_ASIO_HEADER_ONLY)
354 2486 sjacqu01
355 2486 sjacqu01
#endif // defined(BOOST_ASIO_WINDOWS_RUNTIME)
356 2486 sjacqu01
357 2486 sjacqu01
#endif // BOOST_ASIO_DETAIL_WINRT_SSOCKET_SERVICE_BASE_HPP