Statistics
| Revision:

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

History | View | Annotate | Download (16.8 kB)

1 2486 sjacqu01
//
2 2486 sjacqu01
// detail/impl/winrt_ssocket_service_base.ipp
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_IMPL_WINRT_SSOCKET_SERVICE_BASE_IPP
12 2486 sjacqu01
#define BOOST_ASIO_DETAIL_IMPL_WINRT_SSOCKET_SERVICE_BASE_IPP
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 <cstring>
23 2486 sjacqu01
#include <boost/asio/detail/winrt_ssocket_service_base.hpp>
24 2486 sjacqu01
#include <boost/asio/detail/winrt_async_op.hpp>
25 2486 sjacqu01
#include <boost/asio/detail/winrt_utils.hpp>
26 2486 sjacqu01
27 2486 sjacqu01
#include <boost/asio/detail/push_options.hpp>
28 2486 sjacqu01
29 2486 sjacqu01
namespace boost {
30 2486 sjacqu01
namespace asio {
31 2486 sjacqu01
namespace detail {
32 2486 sjacqu01
33 2486 sjacqu01
winrt_ssocket_service_base::winrt_ssocket_service_base(
34 2486 sjacqu01
    boost::asio::io_service& io_service)
35 2486 sjacqu01
  : io_service_(use_service<io_service_impl>(io_service)),
36 2486 sjacqu01
    async_manager_(use_service<winrt_async_manager>(io_service)),
37 2486 sjacqu01
    mutex_(),
38 2486 sjacqu01
    impl_list_(0)
39 2486 sjacqu01
{
40 2486 sjacqu01
}
41 2486 sjacqu01
42 2486 sjacqu01
void winrt_ssocket_service_base::shutdown_service()
43 2486 sjacqu01
{
44 2486 sjacqu01
  // Close all implementations, causing all operations to complete.
45 2486 sjacqu01
  boost::asio::detail::mutex::scoped_lock lock(mutex_);
46 2486 sjacqu01
  base_implementation_type* impl = impl_list_;
47 2486 sjacqu01
  while (impl)
48 2486 sjacqu01
  {
49 2486 sjacqu01
    boost::system::error_code ignored_ec;
50 2486 sjacqu01
    close(*impl, ignored_ec);
51 2486 sjacqu01
    impl = impl->next_;
52 2486 sjacqu01
  }
53 2486 sjacqu01
}
54 2486 sjacqu01
55 2486 sjacqu01
void winrt_ssocket_service_base::construct(
56 2486 sjacqu01
    winrt_ssocket_service_base::base_implementation_type& impl)
57 2486 sjacqu01
{
58 2486 sjacqu01
  // Insert implementation into linked list of all implementations.
59 2486 sjacqu01
  boost::asio::detail::mutex::scoped_lock lock(mutex_);
60 2486 sjacqu01
  impl.next_ = impl_list_;
61 2486 sjacqu01
  impl.prev_ = 0;
62 2486 sjacqu01
  if (impl_list_)
63 2486 sjacqu01
    impl_list_->prev_ = &impl;
64 2486 sjacqu01
  impl_list_ = &impl;
65 2486 sjacqu01
}
66 2486 sjacqu01
67 2486 sjacqu01
void winrt_ssocket_service_base::base_move_construct(
68 2486 sjacqu01
    winrt_ssocket_service_base::base_implementation_type& impl,
69 2486 sjacqu01
    winrt_ssocket_service_base::base_implementation_type& other_impl)
70 2486 sjacqu01
{
71 2486 sjacqu01
  impl.socket_ = other_impl.socket_;
72 2486 sjacqu01
  other_impl.socket_ = nullptr;
73 2486 sjacqu01
74 2486 sjacqu01
  // Insert implementation into linked list of all implementations.
75 2486 sjacqu01
  boost::asio::detail::mutex::scoped_lock lock(mutex_);
76 2486 sjacqu01
  impl.next_ = impl_list_;
77 2486 sjacqu01
  impl.prev_ = 0;
78 2486 sjacqu01
  if (impl_list_)
79 2486 sjacqu01
    impl_list_->prev_ = &impl;
80 2486 sjacqu01
  impl_list_ = &impl;
81 2486 sjacqu01
}
82 2486 sjacqu01
83 2486 sjacqu01
void winrt_ssocket_service_base::base_move_assign(
84 2486 sjacqu01
    winrt_ssocket_service_base::base_implementation_type& impl,
85 2486 sjacqu01
    winrt_ssocket_service_base& other_service,
86 2486 sjacqu01
    winrt_ssocket_service_base::base_implementation_type& other_impl)
87 2486 sjacqu01
{
88 2486 sjacqu01
  boost::system::error_code ignored_ec;
89 2486 sjacqu01
  close(impl, ignored_ec);
90 2486 sjacqu01
91 2486 sjacqu01
  if (this != &other_service)
92 2486 sjacqu01
  {
93 2486 sjacqu01
    // Remove implementation from linked list of all implementations.
94 2486 sjacqu01
    boost::asio::detail::mutex::scoped_lock lock(mutex_);
95 2486 sjacqu01
    if (impl_list_ == &impl)
96 2486 sjacqu01
      impl_list_ = impl.next_;
97 2486 sjacqu01
    if (impl.prev_)
98 2486 sjacqu01
      impl.prev_->next_ = impl.next_;
99 2486 sjacqu01
    if (impl.next_)
100 2486 sjacqu01
      impl.next_->prev_= impl.prev_;
101 2486 sjacqu01
    impl.next_ = 0;
102 2486 sjacqu01
    impl.prev_ = 0;
103 2486 sjacqu01
  }
104 2486 sjacqu01
105 2486 sjacqu01
  impl.socket_ = other_impl.socket_;
106 2486 sjacqu01
  other_impl.socket_ = nullptr;
107 2486 sjacqu01
108 2486 sjacqu01
  if (this != &other_service)
109 2486 sjacqu01
  {
110 2486 sjacqu01
    // Insert implementation into linked list of all implementations.
111 2486 sjacqu01
    boost::asio::detail::mutex::scoped_lock lock(other_service.mutex_);
112 2486 sjacqu01
    impl.next_ = other_service.impl_list_;
113 2486 sjacqu01
    impl.prev_ = 0;
114 2486 sjacqu01
    if (other_service.impl_list_)
115 2486 sjacqu01
      other_service.impl_list_->prev_ = &impl;
116 2486 sjacqu01
    other_service.impl_list_ = &impl;
117 2486 sjacqu01
  }
118 2486 sjacqu01
}
119 2486 sjacqu01
120 2486 sjacqu01
void winrt_ssocket_service_base::destroy(
121 2486 sjacqu01
    winrt_ssocket_service_base::base_implementation_type& impl)
122 2486 sjacqu01
{
123 2486 sjacqu01
  boost::system::error_code ignored_ec;
124 2486 sjacqu01
  close(impl, ignored_ec);
125 2486 sjacqu01
126 2486 sjacqu01
  // Remove implementation from linked list of all implementations.
127 2486 sjacqu01
  boost::asio::detail::mutex::scoped_lock lock(mutex_);
128 2486 sjacqu01
  if (impl_list_ == &impl)
129 2486 sjacqu01
    impl_list_ = impl.next_;
130 2486 sjacqu01
  if (impl.prev_)
131 2486 sjacqu01
    impl.prev_->next_ = impl.next_;
132 2486 sjacqu01
  if (impl.next_)
133 2486 sjacqu01
    impl.next_->prev_= impl.prev_;
134 2486 sjacqu01
  impl.next_ = 0;
135 2486 sjacqu01
  impl.prev_ = 0;
136 2486 sjacqu01
}
137 2486 sjacqu01
138 2486 sjacqu01
boost::system::error_code winrt_ssocket_service_base::close(
139 2486 sjacqu01
    winrt_ssocket_service_base::base_implementation_type& impl,
140 2486 sjacqu01
    boost::system::error_code& ec)
141 2486 sjacqu01
{
142 2486 sjacqu01
  if (impl.socket_)
143 2486 sjacqu01
  {
144 2486 sjacqu01
    delete impl.socket_;
145 2486 sjacqu01
    impl.socket_ = nullptr;
146 2486 sjacqu01
  }
147 2486 sjacqu01
148 2486 sjacqu01
  ec = boost::system::error_code();
149 2486 sjacqu01
  return ec;
150 2486 sjacqu01
}
151 2486 sjacqu01
152 2486 sjacqu01
std::size_t winrt_ssocket_service_base::do_get_endpoint(
153 2486 sjacqu01
    const base_implementation_type& impl, bool local,
154 2486 sjacqu01
    void* addr, std::size_t addr_len, boost::system::error_code& ec) const
155 2486 sjacqu01
{
156 2486 sjacqu01
  if (!is_open(impl))
157 2486 sjacqu01
  {
158 2486 sjacqu01
    ec = boost::asio::error::bad_descriptor;
159 2486 sjacqu01
    return addr_len;
160 2486 sjacqu01
  }
161 2486 sjacqu01
162 2486 sjacqu01
  try
163 2486 sjacqu01
  {
164 2486 sjacqu01
    std::string addr_string = winrt_utils::string(local
165 2486 sjacqu01
        ? impl.socket_->Information->LocalAddress->CanonicalName
166 2486 sjacqu01
        : impl.socket_->Information->RemoteAddress->CanonicalName);
167 2486 sjacqu01
    unsigned short port = winrt_utils::integer(local
168 2486 sjacqu01
        ? impl.socket_->Information->LocalPort
169 2486 sjacqu01
        : impl.socket_->Information->RemotePort);
170 2486 sjacqu01
    unsigned long scope = 0;
171 2486 sjacqu01
172 2486 sjacqu01
    switch (reinterpret_cast<const socket_addr_type*>(addr)->sa_family)
173 2486 sjacqu01
    {
174 2486 sjacqu01
    case BOOST_ASIO_OS_DEF(AF_INET):
175 2486 sjacqu01
      if (addr_len < sizeof(sockaddr_in4_type))
176 2486 sjacqu01
      {
177 2486 sjacqu01
        ec = boost::asio::error::invalid_argument;
178 2486 sjacqu01
        return addr_len;
179 2486 sjacqu01
      }
180 2486 sjacqu01
      else
181 2486 sjacqu01
      {
182 2486 sjacqu01
        socket_ops::inet_pton(BOOST_ASIO_OS_DEF(AF_INET), addr_string.c_str(),
183 2486 sjacqu01
            &reinterpret_cast<sockaddr_in4_type*>(addr)->sin_addr, &scope, ec);
184 2486 sjacqu01
        reinterpret_cast<sockaddr_in4_type*>(addr)->sin_port
185 2486 sjacqu01
          = socket_ops::host_to_network_short(port);
186 2486 sjacqu01
        ec = boost::system::error_code();
187 2486 sjacqu01
        return sizeof(sockaddr_in4_type);
188 2486 sjacqu01
      }
189 2486 sjacqu01
    case BOOST_ASIO_OS_DEF(AF_INET6):
190 2486 sjacqu01
      if (addr_len < sizeof(sockaddr_in6_type))
191 2486 sjacqu01
      {
192 2486 sjacqu01
        ec = boost::asio::error::invalid_argument;
193 2486 sjacqu01
        return addr_len;
194 2486 sjacqu01
      }
195 2486 sjacqu01
      else
196 2486 sjacqu01
      {
197 2486 sjacqu01
        socket_ops::inet_pton(BOOST_ASIO_OS_DEF(AF_INET6), addr_string.c_str(),
198 2486 sjacqu01
            &reinterpret_cast<sockaddr_in6_type*>(addr)->sin6_addr, &scope, ec);
199 2486 sjacqu01
        reinterpret_cast<sockaddr_in6_type*>(addr)->sin6_port
200 2486 sjacqu01
          = socket_ops::host_to_network_short(port);
201 2486 sjacqu01
        ec = boost::system::error_code();
202 2486 sjacqu01
        return sizeof(sockaddr_in6_type);
203 2486 sjacqu01
      }
204 2486 sjacqu01
    default:
205 2486 sjacqu01
      ec = boost::asio::error::address_family_not_supported;
206 2486 sjacqu01
      return addr_len;
207 2486 sjacqu01
    }
208 2486 sjacqu01
  }
209 2486 sjacqu01
  catch (Platform::Exception^ e)
210 2486 sjacqu01
  {
211 2486 sjacqu01
    ec = boost::system::error_code(e->HResult,
212 2486 sjacqu01
        boost::system::system_category());
213 2486 sjacqu01
    return addr_len;
214 2486 sjacqu01
  }
215 2486 sjacqu01
}
216 2486 sjacqu01
217 2486 sjacqu01
boost::system::error_code winrt_ssocket_service_base::do_set_option(
218 2486 sjacqu01
    winrt_ssocket_service_base::base_implementation_type& impl,
219 2486 sjacqu01
    int level, int optname, const void* optval,
220 2486 sjacqu01
    std::size_t optlen, boost::system::error_code& ec)
221 2486 sjacqu01
{
222 2486 sjacqu01
  if (!is_open(impl))
223 2486 sjacqu01
  {
224 2486 sjacqu01
    ec = boost::asio::error::bad_descriptor;
225 2486 sjacqu01
    return ec;
226 2486 sjacqu01
  }
227 2486 sjacqu01
228 2486 sjacqu01
  try
229 2486 sjacqu01
  {
230 2486 sjacqu01
    if (level == BOOST_ASIO_OS_DEF(SOL_SOCKET)
231 2486 sjacqu01
        && optname == BOOST_ASIO_OS_DEF(SO_KEEPALIVE))
232 2486 sjacqu01
    {
233 2486 sjacqu01
      if (optlen == sizeof(int))
234 2486 sjacqu01
      {
235 2486 sjacqu01
        int value = 0;
236 2486 sjacqu01
        std::memcpy(&value, optval, optlen);
237 2486 sjacqu01
        impl.socket_->Control->KeepAlive = !!value;
238 2486 sjacqu01
        ec = boost::system::error_code();
239 2486 sjacqu01
      }
240 2486 sjacqu01
      else
241 2486 sjacqu01
      {
242 2486 sjacqu01
        ec = boost::asio::error::invalid_argument;
243 2486 sjacqu01
      }
244 2486 sjacqu01
    }
245 2486 sjacqu01
    else if (level == BOOST_ASIO_OS_DEF(IPPROTO_TCP)
246 2486 sjacqu01
        && optname == BOOST_ASIO_OS_DEF(TCP_NODELAY))
247 2486 sjacqu01
    {
248 2486 sjacqu01
      if (optlen == sizeof(int))
249 2486 sjacqu01
      {
250 2486 sjacqu01
        int value = 0;
251 2486 sjacqu01
        std::memcpy(&value, optval, optlen);
252 2486 sjacqu01
        impl.socket_->Control->NoDelay = !!value;
253 2486 sjacqu01
        ec = boost::system::error_code();
254 2486 sjacqu01
      }
255 2486 sjacqu01
      else
256 2486 sjacqu01
      {
257 2486 sjacqu01
        ec = boost::asio::error::invalid_argument;
258 2486 sjacqu01
      }
259 2486 sjacqu01
    }
260 2486 sjacqu01
    else
261 2486 sjacqu01
    {
262 2486 sjacqu01
      ec = boost::asio::error::invalid_argument;
263 2486 sjacqu01
    }
264 2486 sjacqu01
  }
265 2486 sjacqu01
  catch (Platform::Exception^ e)
266 2486 sjacqu01
  {
267 2486 sjacqu01
    ec = boost::system::error_code(e->HResult,
268 2486 sjacqu01
        boost::system::system_category());
269 2486 sjacqu01
  }
270 2486 sjacqu01
271 2486 sjacqu01
  return ec;
272 2486 sjacqu01
}
273 2486 sjacqu01
274 2486 sjacqu01
void winrt_ssocket_service_base::do_get_option(
275 2486 sjacqu01
    const winrt_ssocket_service_base::base_implementation_type& impl,
276 2486 sjacqu01
    int level, int optname, void* optval,
277 2486 sjacqu01
    std::size_t* optlen, boost::system::error_code& ec) const
278 2486 sjacqu01
{
279 2486 sjacqu01
  if (!is_open(impl))
280 2486 sjacqu01
  {
281 2486 sjacqu01
    ec = boost::asio::error::bad_descriptor;
282 2486 sjacqu01
    return;
283 2486 sjacqu01
  }
284 2486 sjacqu01
285 2486 sjacqu01
  try
286 2486 sjacqu01
  {
287 2486 sjacqu01
    if (level == BOOST_ASIO_OS_DEF(SOL_SOCKET)
288 2486 sjacqu01
        && optname == BOOST_ASIO_OS_DEF(SO_KEEPALIVE))
289 2486 sjacqu01
    {
290 2486 sjacqu01
      if (*optlen >= sizeof(int))
291 2486 sjacqu01
      {
292 2486 sjacqu01
        int value = impl.socket_->Control->KeepAlive ? 1 : 0;
293 2486 sjacqu01
        std::memcpy(optval, &value, sizeof(int));
294 2486 sjacqu01
        *optlen = sizeof(int);
295 2486 sjacqu01
        ec = boost::system::error_code();
296 2486 sjacqu01
      }
297 2486 sjacqu01
      else
298 2486 sjacqu01
      {
299 2486 sjacqu01
        ec = boost::asio::error::invalid_argument;
300 2486 sjacqu01
      }
301 2486 sjacqu01
    }
302 2486 sjacqu01
    else if (level == BOOST_ASIO_OS_DEF(IPPROTO_TCP)
303 2486 sjacqu01
        && optname == BOOST_ASIO_OS_DEF(TCP_NODELAY))
304 2486 sjacqu01
    {
305 2486 sjacqu01
      if (*optlen >= sizeof(int))
306 2486 sjacqu01
      {
307 2486 sjacqu01
        int value = impl.socket_->Control->NoDelay ? 1 : 0;
308 2486 sjacqu01
        std::memcpy(optval, &value, sizeof(int));
309 2486 sjacqu01
        *optlen = sizeof(int);
310 2486 sjacqu01
        ec = boost::system::error_code();
311 2486 sjacqu01
      }
312 2486 sjacqu01
      else
313 2486 sjacqu01
      {
314 2486 sjacqu01
        ec = boost::asio::error::invalid_argument;
315 2486 sjacqu01
      }
316 2486 sjacqu01
    }
317 2486 sjacqu01
    else
318 2486 sjacqu01
    {
319 2486 sjacqu01
      ec = boost::asio::error::invalid_argument;
320 2486 sjacqu01
    }
321 2486 sjacqu01
  }
322 2486 sjacqu01
  catch (Platform::Exception^ e)
323 2486 sjacqu01
  {
324 2486 sjacqu01
    ec = boost::system::error_code(e->HResult,
325 2486 sjacqu01
        boost::system::system_category());
326 2486 sjacqu01
  }
327 2486 sjacqu01
}
328 2486 sjacqu01
329 2486 sjacqu01
boost::system::error_code winrt_ssocket_service_base::do_connect(
330 2486 sjacqu01
    winrt_ssocket_service_base::base_implementation_type& impl,
331 2486 sjacqu01
    const void* addr, boost::system::error_code& ec)
332 2486 sjacqu01
{
333 2486 sjacqu01
  if (!is_open(impl))
334 2486 sjacqu01
  {
335 2486 sjacqu01
    ec = boost::asio::error::bad_descriptor;
336 2486 sjacqu01
    return ec;
337 2486 sjacqu01
  }
338 2486 sjacqu01
339 2486 sjacqu01
  char addr_string[max_addr_v6_str_len];
340 2486 sjacqu01
  unsigned short port;
341 2486 sjacqu01
  switch (reinterpret_cast<const socket_addr_type*>(addr)->sa_family)
342 2486 sjacqu01
  {
343 2486 sjacqu01
  case BOOST_ASIO_OS_DEF(AF_INET):
344 2486 sjacqu01
    socket_ops::inet_ntop(BOOST_ASIO_OS_DEF(AF_INET),
345 2486 sjacqu01
        &reinterpret_cast<const sockaddr_in4_type*>(addr)->sin_addr,
346 2486 sjacqu01
        addr_string, sizeof(addr_string), 0, ec);
347 2486 sjacqu01
    port = socket_ops::network_to_host_short(
348 2486 sjacqu01
        reinterpret_cast<const sockaddr_in4_type*>(addr)->sin_port);
349 2486 sjacqu01
    break;
350 2486 sjacqu01
  case BOOST_ASIO_OS_DEF(AF_INET6):
351 2486 sjacqu01
    socket_ops::inet_ntop(BOOST_ASIO_OS_DEF(AF_INET6),
352 2486 sjacqu01
        &reinterpret_cast<const sockaddr_in6_type*>(addr)->sin6_addr,
353 2486 sjacqu01
        addr_string, sizeof(addr_string), 0, ec);
354 2486 sjacqu01
    port = socket_ops::network_to_host_short(
355 2486 sjacqu01
        reinterpret_cast<const sockaddr_in6_type*>(addr)->sin6_port);
356 2486 sjacqu01
    break;
357 2486 sjacqu01
  default:
358 2486 sjacqu01
    ec = boost::asio::error::address_family_not_supported;
359 2486 sjacqu01
    return ec;
360 2486 sjacqu01
  }
361 2486 sjacqu01
362 2486 sjacqu01
  if (!ec) try
363 2486 sjacqu01
  {
364 2486 sjacqu01
    async_manager_.sync(impl.socket_->ConnectAsync(
365 2486 sjacqu01
          ref new Windows::Networking::HostName(
366 2486 sjacqu01
            winrt_utils::string(addr_string)),
367 2486 sjacqu01
          winrt_utils::string(port)), ec);
368 2486 sjacqu01
  }
369 2486 sjacqu01
  catch (Platform::Exception^ e)
370 2486 sjacqu01
  {
371 2486 sjacqu01
    ec = boost::system::error_code(e->HResult,
372 2486 sjacqu01
        boost::system::system_category());
373 2486 sjacqu01
  }
374 2486 sjacqu01
375 2486 sjacqu01
  return ec;
376 2486 sjacqu01
}
377 2486 sjacqu01
378 2486 sjacqu01
void winrt_ssocket_service_base::start_connect_op(
379 2486 sjacqu01
    winrt_ssocket_service_base::base_implementation_type& impl,
380 2486 sjacqu01
    const void* addr, winrt_async_op<void>* op, bool is_continuation)
381 2486 sjacqu01
{
382 2486 sjacqu01
  if (!is_open(impl))
383 2486 sjacqu01
  {
384 2486 sjacqu01
    op->ec_ = boost::asio::error::bad_descriptor;
385 2486 sjacqu01
    io_service_.post_immediate_completion(op, is_continuation);
386 2486 sjacqu01
    return;
387 2486 sjacqu01
  }
388 2486 sjacqu01
389 2486 sjacqu01
  char addr_string[max_addr_v6_str_len];
390 2486 sjacqu01
  unsigned short port = 0;
391 2486 sjacqu01
  switch (reinterpret_cast<const socket_addr_type*>(addr)->sa_family)
392 2486 sjacqu01
  {
393 2486 sjacqu01
  case BOOST_ASIO_OS_DEF(AF_INET):
394 2486 sjacqu01
    socket_ops::inet_ntop(BOOST_ASIO_OS_DEF(AF_INET),
395 2486 sjacqu01
        &reinterpret_cast<const sockaddr_in4_type*>(addr)->sin_addr,
396 2486 sjacqu01
        addr_string, sizeof(addr_string), 0, op->ec_);
397 2486 sjacqu01
    port = socket_ops::network_to_host_short(
398 2486 sjacqu01
        reinterpret_cast<const sockaddr_in4_type*>(addr)->sin_port);
399 2486 sjacqu01
    break;
400 2486 sjacqu01
  case BOOST_ASIO_OS_DEF(AF_INET6):
401 2486 sjacqu01
    socket_ops::inet_ntop(BOOST_ASIO_OS_DEF(AF_INET6),
402 2486 sjacqu01
        &reinterpret_cast<const sockaddr_in6_type*>(addr)->sin6_addr,
403 2486 sjacqu01
        addr_string, sizeof(addr_string), 0, op->ec_);
404 2486 sjacqu01
    port = socket_ops::network_to_host_short(
405 2486 sjacqu01
        reinterpret_cast<const sockaddr_in6_type*>(addr)->sin6_port);
406 2486 sjacqu01
    break;
407 2486 sjacqu01
  default:
408 2486 sjacqu01
    op->ec_ = boost::asio::error::address_family_not_supported;
409 2486 sjacqu01
    break;
410 2486 sjacqu01
  }
411 2486 sjacqu01
412 2486 sjacqu01
  if (op->ec_)
413 2486 sjacqu01
  {
414 2486 sjacqu01
    io_service_.post_immediate_completion(op, is_continuation);
415 2486 sjacqu01
    return;
416 2486 sjacqu01
  }
417 2486 sjacqu01
418 2486 sjacqu01
  try
419 2486 sjacqu01
  {
420 2486 sjacqu01
    async_manager_.async(impl.socket_->ConnectAsync(
421 2486 sjacqu01
          ref new Windows::Networking::HostName(
422 2486 sjacqu01
            winrt_utils::string(addr_string)),
423 2486 sjacqu01
          winrt_utils::string(port)), op);
424 2486 sjacqu01
  }
425 2486 sjacqu01
  catch (Platform::Exception^ e)
426 2486 sjacqu01
  {
427 2486 sjacqu01
    op->ec_ = boost::system::error_code(
428 2486 sjacqu01
        e->HResult, boost::system::system_category());
429 2486 sjacqu01
    io_service_.post_immediate_completion(op, is_continuation);
430 2486 sjacqu01
  }
431 2486 sjacqu01
}
432 2486 sjacqu01
433 2486 sjacqu01
std::size_t winrt_ssocket_service_base::do_send(
434 2486 sjacqu01
    winrt_ssocket_service_base::base_implementation_type& impl,
435 2486 sjacqu01
    const boost::asio::const_buffer& data,
436 2486 sjacqu01
    socket_base::message_flags flags, boost::system::error_code& ec)
437 2486 sjacqu01
{
438 2486 sjacqu01
  if (flags)
439 2486 sjacqu01
  {
440 2486 sjacqu01
    ec = boost::asio::error::operation_not_supported;
441 2486 sjacqu01
    return 0;
442 2486 sjacqu01
  }
443 2486 sjacqu01
444 2486 sjacqu01
  if (!is_open(impl))
445 2486 sjacqu01
  {
446 2486 sjacqu01
    ec = boost::asio::error::bad_descriptor;
447 2486 sjacqu01
    return 0;
448 2486 sjacqu01
  }
449 2486 sjacqu01
450 2486 sjacqu01
  try
451 2486 sjacqu01
  {
452 2486 sjacqu01
    buffer_sequence_adapter<boost::asio::const_buffer,
453 2486 sjacqu01
      boost::asio::const_buffers_1> bufs(boost::asio::buffer(data));
454 2486 sjacqu01
455 2486 sjacqu01
    if (bufs.all_empty())
456 2486 sjacqu01
    {
457 2486 sjacqu01
      ec = boost::system::error_code();
458 2486 sjacqu01
      return 0;
459 2486 sjacqu01
    }
460 2486 sjacqu01
461 2486 sjacqu01
    return async_manager_.sync(
462 2486 sjacqu01
        impl.socket_->OutputStream->WriteAsync(bufs.buffers()[0]), ec);
463 2486 sjacqu01
  }
464 2486 sjacqu01
  catch (Platform::Exception^ e)
465 2486 sjacqu01
  {
466 2486 sjacqu01
    ec = boost::system::error_code(e->HResult,
467 2486 sjacqu01
        boost::system::system_category());
468 2486 sjacqu01
    return 0;
469 2486 sjacqu01
  }
470 2486 sjacqu01
}
471 2486 sjacqu01
472 2486 sjacqu01
void winrt_ssocket_service_base::start_send_op(
473 2486 sjacqu01
      winrt_ssocket_service_base::base_implementation_type& impl,
474 2486 sjacqu01
      const boost::asio::const_buffer& data, socket_base::message_flags flags,
475 2486 sjacqu01
      winrt_async_op<unsigned int>* op, bool is_continuation)
476 2486 sjacqu01
{
477 2486 sjacqu01
  if (flags)
478 2486 sjacqu01
  {
479 2486 sjacqu01
    op->ec_ = boost::asio::error::operation_not_supported;
480 2486 sjacqu01
    io_service_.post_immediate_completion(op, is_continuation);
481 2486 sjacqu01
    return;
482 2486 sjacqu01
  }
483 2486 sjacqu01
484 2486 sjacqu01
  if (!is_open(impl))
485 2486 sjacqu01
  {
486 2486 sjacqu01
    op->ec_ = boost::asio::error::bad_descriptor;
487 2486 sjacqu01
    io_service_.post_immediate_completion(op, is_continuation);
488 2486 sjacqu01
    return;
489 2486 sjacqu01
  }
490 2486 sjacqu01
491 2486 sjacqu01
  try
492 2486 sjacqu01
  {
493 2486 sjacqu01
    buffer_sequence_adapter<boost::asio::const_buffer,
494 2486 sjacqu01
        boost::asio::const_buffers_1> bufs(boost::asio::buffer(data));
495 2486 sjacqu01
496 2486 sjacqu01
    if (bufs.all_empty())
497 2486 sjacqu01
    {
498 2486 sjacqu01
      io_service_.post_immediate_completion(op, is_continuation);
499 2486 sjacqu01
      return;
500 2486 sjacqu01
    }
501 2486 sjacqu01
502 2486 sjacqu01
    async_manager_.async(
503 2486 sjacqu01
        impl.socket_->OutputStream->WriteAsync(bufs.buffers()[0]), op);
504 2486 sjacqu01
  }
505 2486 sjacqu01
  catch (Platform::Exception^ e)
506 2486 sjacqu01
  {
507 2486 sjacqu01
    op->ec_ = boost::system::error_code(e->HResult,
508 2486 sjacqu01
        boost::system::system_category());
509 2486 sjacqu01
    io_service_.post_immediate_completion(op, is_continuation);
510 2486 sjacqu01
  }
511 2486 sjacqu01
}
512 2486 sjacqu01
513 2486 sjacqu01
std::size_t winrt_ssocket_service_base::do_receive(
514 2486 sjacqu01
    winrt_ssocket_service_base::base_implementation_type& impl,
515 2486 sjacqu01
    const boost::asio::mutable_buffer& data,
516 2486 sjacqu01
    socket_base::message_flags flags, boost::system::error_code& ec)
517 2486 sjacqu01
{
518 2486 sjacqu01
  if (flags)
519 2486 sjacqu01
  {
520 2486 sjacqu01
    ec = boost::asio::error::operation_not_supported;
521 2486 sjacqu01
    return 0;
522 2486 sjacqu01
  }
523 2486 sjacqu01
524 2486 sjacqu01
  if (!is_open(impl))
525 2486 sjacqu01
  {
526 2486 sjacqu01
    ec = boost::asio::error::bad_descriptor;
527 2486 sjacqu01
    return 0;
528 2486 sjacqu01
  }
529 2486 sjacqu01
530 2486 sjacqu01
  try
531 2486 sjacqu01
  {
532 2486 sjacqu01
    buffer_sequence_adapter<boost::asio::mutable_buffer,
533 2486 sjacqu01
        boost::asio::mutable_buffers_1> bufs(boost::asio::buffer(data));
534 2486 sjacqu01
535 2486 sjacqu01
    if (bufs.all_empty())
536 2486 sjacqu01
    {
537 2486 sjacqu01
      ec = boost::system::error_code();
538 2486 sjacqu01
      return 0;
539 2486 sjacqu01
    }
540 2486 sjacqu01
541 2486 sjacqu01
    async_manager_.sync(
542 2486 sjacqu01
        impl.socket_->InputStream->ReadAsync(
543 2486 sjacqu01
          bufs.buffers()[0], bufs.buffers()[0]->Capacity,
544 2486 sjacqu01
          Windows::Storage::Streams::InputStreamOptions::Partial), ec);
545 2486 sjacqu01
546 2486 sjacqu01
    std::size_t bytes_transferred = bufs.buffers()[0]->Length;
547 2486 sjacqu01
    if (bytes_transferred == 0 && !ec)
548 2486 sjacqu01
    {
549 2486 sjacqu01
      ec = boost::asio::error::eof;
550 2486 sjacqu01
    }
551 2486 sjacqu01
552 2486 sjacqu01
    return bytes_transferred;
553 2486 sjacqu01
  }
554 2486 sjacqu01
  catch (Platform::Exception^ e)
555 2486 sjacqu01
  {
556 2486 sjacqu01
    ec = boost::system::error_code(e->HResult,
557 2486 sjacqu01
        boost::system::system_category());
558 2486 sjacqu01
    return 0;
559 2486 sjacqu01
  }
560 2486 sjacqu01
}
561 2486 sjacqu01
562 2486 sjacqu01
void winrt_ssocket_service_base::start_receive_op(
563 2486 sjacqu01
      winrt_ssocket_service_base::base_implementation_type& impl,
564 2486 sjacqu01
      const boost::asio::mutable_buffer& data, socket_base::message_flags flags,
565 2486 sjacqu01
      winrt_async_op<Windows::Storage::Streams::IBuffer^>* op,
566 2486 sjacqu01
      bool is_continuation)
567 2486 sjacqu01
{
568 2486 sjacqu01
  if (flags)
569 2486 sjacqu01
  {
570 2486 sjacqu01
    op->ec_ = boost::asio::error::operation_not_supported;
571 2486 sjacqu01
    io_service_.post_immediate_completion(op, is_continuation);
572 2486 sjacqu01
    return;
573 2486 sjacqu01
  }
574 2486 sjacqu01
575 2486 sjacqu01
  if (!is_open(impl))
576 2486 sjacqu01
  {
577 2486 sjacqu01
    op->ec_ = boost::asio::error::bad_descriptor;
578 2486 sjacqu01
    io_service_.post_immediate_completion(op, is_continuation);
579 2486 sjacqu01
    return;
580 2486 sjacqu01
  }
581 2486 sjacqu01
582 2486 sjacqu01
  try
583 2486 sjacqu01
  {
584 2486 sjacqu01
    buffer_sequence_adapter<boost::asio::mutable_buffer,
585 2486 sjacqu01
        boost::asio::mutable_buffers_1> bufs(boost::asio::buffer(data));
586 2486 sjacqu01
587 2486 sjacqu01
    if (bufs.all_empty())
588 2486 sjacqu01
    {
589 2486 sjacqu01
      io_service_.post_immediate_completion(op, is_continuation);
590 2486 sjacqu01
      return;
591 2486 sjacqu01
    }
592 2486 sjacqu01
593 2486 sjacqu01
    async_manager_.async(
594 2486 sjacqu01
        impl.socket_->InputStream->ReadAsync(
595 2486 sjacqu01
          bufs.buffers()[0], bufs.buffers()[0]->Capacity,
596 2486 sjacqu01
          Windows::Storage::Streams::InputStreamOptions::Partial), op);
597 2486 sjacqu01
  }
598 2486 sjacqu01
  catch (Platform::Exception^ e)
599 2486 sjacqu01
  {
600 2486 sjacqu01
    op->ec_ = boost::system::error_code(e->HResult,
601 2486 sjacqu01
        boost::system::system_category());
602 2486 sjacqu01
    io_service_.post_immediate_completion(op, is_continuation);
603 2486 sjacqu01
  }
604 2486 sjacqu01
}
605 2486 sjacqu01
606 2486 sjacqu01
} // namespace detail
607 2486 sjacqu01
} // namespace asio
608 2486 sjacqu01
} // namespace boost
609 2486 sjacqu01
610 2486 sjacqu01
#include <boost/asio/detail/pop_options.hpp>
611 2486 sjacqu01
612 2486 sjacqu01
#endif // defined(BOOST_ASIO_WINDOWS_RUNTIME)
613 2486 sjacqu01
614 2486 sjacqu01
#endif // BOOST_ASIO_DETAIL_IMPL_WINRT_SSOCKET_SERVICE_BASE_IPP