Skip to content

Commit 51bba37

Browse files
committed
Initial port to Windows Runtime.
This change adds limited support for using Asio with the Windows Runtime. It requires that the language extensions be enabled. Due to the restricted facilities exposed by the Windows Runtime API, the port comes with the following caveats: * The core facilities such as the io_service, strand, buffers, composed operations, timers, etc., should all work as normal. * For sockets, only client-side TCP is supported. * Explicit binding of a client-side TCP socket is not supported. * The cancel() function is not supported for sockets. Asynchronous operations may only be cancelled by closing the socket. * Operations that use null_buffers are not supported. * Only tcp::no_delay and socket_base::keep_alive options are supported. * Resolvers do not support service names, only numbers. I.e. you must use "80" rather than "http". * Most resolver query flags have no effect.
1 parent a482f2d commit 51bba37

File tree

97 files changed

+4865
-283
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+4865
-283
lines changed

asio/include/Makefile.am

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ nobase_include_HEADERS = \
6969
asio/detail/handler_tracking.hpp \
7070
asio/detail/handler_type_requirements.hpp \
7171
asio/detail/hash_map.hpp \
72+
asio/detail/impl/buffer_sequence_adapter.ipp \
7273
asio/detail/impl/descriptor_ops.ipp \
7374
asio/detail/impl/dev_poll_reactor.hpp \
7475
asio/detail/impl/dev_poll_reactor.ipp \
@@ -109,6 +110,9 @@ nobase_include_HEADERS = \
109110
asio/detail/impl/win_iocp_socket_service_base.ipp \
110111
asio/detail/impl/win_mutex.ipp \
111112
asio/detail/impl/win_object_handle_service.ipp \
113+
asio/detail/impl/winrt_ssocket_service_base.ipp \
114+
asio/detail/impl/winrt_timer_scheduler.hpp \
115+
asio/detail/impl/winrt_timer_scheduler.ipp \
112116
asio/detail/impl/winsock_init.ipp \
113117
asio/detail/impl/win_static_mutex.ipp \
114118
asio/detail/impl/win_thread.ipp \
@@ -124,7 +128,9 @@ nobase_include_HEADERS = \
124128
asio/detail/null_event.hpp \
125129
asio/detail/null_fenced_block.hpp \
126130
asio/detail/null_mutex.hpp \
131+
asio/detail/null_reactor.hpp \
127132
asio/detail/null_signal_blocker.hpp \
133+
asio/detail/null_socket_service.hpp \
128134
asio/detail/null_static_mutex.hpp \
129135
asio/detail/null_thread.hpp \
130136
asio/detail/null_tss_ptr.hpp \
@@ -181,6 +187,10 @@ nobase_include_HEADERS = \
181187
asio/detail/socket_types.hpp \
182188
asio/detail/solaris_fenced_block.hpp \
183189
asio/detail/static_mutex.hpp \
190+
asio/detail/std_event.hpp \
191+
asio/detail/std_mutex.hpp \
192+
asio/detail/std_static_mutex.hpp \
193+
asio/detail/std_thread.hpp \
184194
asio/detail/strand_service.hpp \
185195
asio/detail/task_io_service.hpp \
186196
asio/detail/task_io_service_operation.hpp \
@@ -224,6 +234,17 @@ nobase_include_HEADERS = \
224234
asio/detail/win_iocp_thread_info.hpp \
225235
asio/detail/win_mutex.hpp \
226236
asio/detail/win_object_handle_service.hpp \
237+
asio/detail/winrt_async_manager.hpp \
238+
asio/detail/winrt_async_op.hpp \
239+
asio/detail/winrt_resolve_op.hpp \
240+
asio/detail/winrt_resolver_service.hpp \
241+
asio/detail/winrt_socket_connect_op.hpp \
242+
asio/detail/winrt_socket_recv_op.hpp \
243+
asio/detail/winrt_socket_send_op.hpp \
244+
asio/detail/winrt_ssocket_service_base.hpp \
245+
asio/detail/winrt_ssocket_service.hpp \
246+
asio/detail/winrt_timer_scheduler.hpp \
247+
asio/detail/winrt_utils.hpp \
227248
asio/detail/winsock_init.hpp \
228249
asio/detail/win_static_mutex.hpp \
229250
asio/detail/win_thread.hpp \

asio/include/asio/datagram_socket_service.hpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
#include "asio/error.hpp"
2323
#include "asio/io_service.hpp"
2424

25-
#if defined(ASIO_HAS_IOCP)
25+
#if defined(ASIO_WINDOWS_RUNTIME)
26+
# include "asio/detail/null_socket_service.hpp"
27+
#elif defined(ASIO_HAS_IOCP)
2628
# include "asio/detail/win_iocp_socket_service.hpp"
2729
#else
2830
# include "asio/detail/reactive_socket_service.hpp"
@@ -55,7 +57,9 @@ class datagram_socket_service
5557

5658
private:
5759
// The type of the platform-specific implementation.
58-
#if defined(ASIO_HAS_IOCP)
60+
#if defined(ASIO_WINDOWS_RUNTIME)
61+
typedef detail::null_socket_service<Protocol> service_impl_type;
62+
#elif defined(ASIO_HAS_IOCP)
5963
typedef detail::win_iocp_socket_service<Protocol> service_impl_type;
6064
#else
6165
typedef detail::reactive_socket_service<Protocol> service_impl_type;
@@ -137,7 +141,7 @@ class datagram_socket_service
137141
asio::error_code open(implementation_type& impl,
138142
const protocol_type& protocol, asio::error_code& ec)
139143
{
140-
if (protocol.type() == SOCK_DGRAM)
144+
if (protocol.type() == ASIO_OS_DEF(SOCK_DGRAM))
141145
service_impl_.open(impl, protocol, ec);
142146
else
143147
ec = asio::error::invalid_argument;

asio/include/asio/detail/buffer_sequence_adapter.hpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,23 @@ namespace detail {
2828
class buffer_sequence_adapter_base
2929
{
3030
protected:
31-
#if defined(ASIO_WINDOWS) || defined(__CYGWIN__)
31+
#if defined(ASIO_WINDOWS_RUNTIME)
32+
// The maximum number of buffers to support in a single operation.
33+
enum { max_buffers = 1 };
34+
35+
typedef Windows::Storage::Streams::IBuffer^ native_buffer_type;
36+
37+
ASIO_DECL static void init_native_buffer(
38+
native_buffer_type& buf,
39+
const asio::mutable_buffer& buffer);
40+
41+
ASIO_DECL static void init_native_buffer(
42+
native_buffer_type& buf,
43+
const asio::const_buffer& buffer);
44+
#elif defined(ASIO_WINDOWS) || defined(__CYGWIN__)
45+
// The maximum number of buffers to support in a single operation.
46+
enum { max_buffers = 64 < max_iov_len ? 64 : max_iov_len };
47+
3248
typedef WSABUF native_buffer_type;
3349

3450
static void init_native_buffer(WSABUF& buf,
@@ -45,6 +61,9 @@ class buffer_sequence_adapter_base
4561
buf.len = static_cast<ULONG>(asio::buffer_size(buffer));
4662
}
4763
#else // defined(ASIO_WINDOWS) || defined(__CYGWIN__)
64+
// The maximum number of buffers to support in a single operation.
65+
enum { max_buffers = 64 < max_iov_len ? 64 : max_iov_len };
66+
4867
typedef iovec native_buffer_type;
4968

5069
static void init_iov_base(void*& base, void* addr)
@@ -145,9 +164,6 @@ class buffer_sequence_adapter
145164
}
146165

147166
private:
148-
// The maximum number of buffers to support in a single operation.
149-
enum { max_buffers = 64 < max_iov_len ? 64 : max_iov_len };
150-
151167
native_buffer_type buffers_[max_buffers];
152168
std::size_t count_;
153169
std::size_t total_buffer_size_;
@@ -360,4 +376,8 @@ class buffer_sequence_adapter<Buffer, std::array<Elem, 2> >
360376

361377
#include "asio/detail/pop_options.hpp"
362378

379+
#if defined(ASIO_HEADER_ONLY)
380+
# include "asio/detail/impl/buffer_sequence_adapter.ipp"
381+
#endif // defined(ASIO_HEADER_ONLY)
382+
363383
#endif // ASIO_DETAIL_BUFFER_SEQUENCE_ADAPTER_HPP

asio/include/asio/detail/config.hpp

Lines changed: 93 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -382,13 +382,66 @@
382382
# endif // !defined(ASIO_DISABLE_CSTDINT)
383383
#endif // !defined(ASIO_HAS_CSTDINT)
384384

385-
// Windows target.
385+
// Standard library support for the thread class.
386+
#if !defined(ASIO_HAS_STD_THREAD)
387+
# if !defined(ASIO_DISABLE_STD_THREAD)
388+
# if defined(ASIO_HAS_CLANG_LIBCXX)
389+
# define ASIO_HAS_STD_THREAD 1
390+
# endif // defined(ASIO_HAS_CLANG_LIBCXX)
391+
# if defined(__GNUC__)
392+
# if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)) || (__GNUC__ > 4)
393+
# if defined(__GXX_EXPERIMENTAL_CXX0X__)
394+
# define ASIO_HAS_STD_THREAD 1
395+
# endif // defined(__GXX_EXPERIMENTAL_CXX0X__)
396+
# endif // ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)) || (__GNUC__ > 4)
397+
# endif // defined(__GNUC__)
398+
# if defined(ASIO_MSVC)
399+
# if (_MSC_VER >= 1700)
400+
# define ASIO_HAS_STD_THREAD 1
401+
# endif // (_MSC_VER >= 1700)
402+
# endif // defined(ASIO_MSVC)
403+
# endif // !defined(ASIO_DISABLE_STD_THREAD)
404+
#endif // !defined(ASIO_HAS_STD_THREAD)
405+
406+
// Standard library support for the mutex and condition variable classes.
407+
#if !defined(ASIO_HAS_STD_MUTEX_AND_CONDVAR)
408+
# if !defined(ASIO_DISABLE_STD_MUTEX_AND_CONDVAR)
409+
# if defined(ASIO_HAS_CLANG_LIBCXX)
410+
# define ASIO_HAS_STD_MUTEX_AND_CONDVAR 1
411+
# endif // defined(ASIO_HAS_CLANG_LIBCXX)
412+
# if defined(__GNUC__)
413+
# if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)) || (__GNUC__ > 4)
414+
# if defined(__GXX_EXPERIMENTAL_CXX0X__)
415+
# define ASIO_HAS_STD_MUTEX_AND_CONDVAR 1
416+
# endif // defined(__GXX_EXPERIMENTAL_CXX0X__)
417+
# endif // ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)) || (__GNUC__ > 4)
418+
# endif // defined(__GNUC__)
419+
# if defined(ASIO_MSVC)
420+
# if (_MSC_VER >= 1700)
421+
# define ASIO_HAS_STD_MUTEX_AND_CONDVAR 1
422+
# endif // (_MSC_VER >= 1700)
423+
# endif // defined(ASIO_MSVC)
424+
# endif // !defined(ASIO_DISABLE_STD_MUTEX_AND_CONDVAR)
425+
#endif // !defined(ASIO_HAS_STD_MUTEX_AND_CONDVAR)
426+
427+
// WinRT target.
428+
#if !defined(ASIO_WINDOWS_RUNTIME)
429+
# if defined(WINAPI_FAMILY)
430+
# if ((WINAPI_FAMILY & WINAPI_PARTITION_APP) != 0)
431+
# define ASIO_WINDOWS_RUNTIME 1
432+
# endif // ((WINAPI_FAMILY & WINAPI_PARTITION_APP) != 0)
433+
# endif // defined(WINAPI_FAMILY)
434+
#endif // !defined(ASIO_WINDOWS_RUNTIME)
435+
436+
// Windows target. Excludes WinRT.
386437
#if !defined(ASIO_WINDOWS)
387-
# if defined(ASIO_HAS_BOOST_CONFIG) && defined(BOOST_WINDOWS)
388-
# define ASIO_WINDOWS 1
389-
# elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
390-
# define ASIO_WINDOWS 1
391-
# endif // defined(ASIO_HAS_BOOST_CONFIG) && defined(BOOST_WINDOWS)
438+
# if !defined(ASIO_WINDOWS_RUNTIME)
439+
# if defined(ASIO_HAS_BOOST_CONFIG) && defined(BOOST_WINDOWS)
440+
# define ASIO_WINDOWS 1
441+
# elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
442+
# define ASIO_WINDOWS 1
443+
# endif // defined(ASIO_HAS_BOOST_CONFIG) && defined(BOOST_WINDOWS)
444+
# endif // !defined(ASIO_WINDOWS_RUNTIME)
392445
#endif // !defined(ASIO_WINDOWS)
393446

394447
// Windows: target OS version.
@@ -516,14 +569,18 @@
516569
// Serial ports.
517570
#if !defined(ASIO_HAS_SERIAL_PORT)
518571
# if defined(ASIO_HAS_IOCP) \
519-
|| !defined(ASIO_WINDOWS) && !defined(__CYGWIN__)
572+
|| !defined(ASIO_WINDOWS) \
573+
&& !defined(ASIO_WINDOWS_RUNTIME) \
574+
&& !defined(__CYGWIN__)
520575
# if !defined(__SYMBIAN32__)
521576
# if !defined(ASIO_DISABLE_SERIAL_PORT)
522577
# define ASIO_HAS_SERIAL_PORT 1
523578
# endif // !defined(ASIO_DISABLE_SERIAL_PORT)
524579
# endif // !defined(__SYMBIAN32__)
525580
# endif // defined(ASIO_HAS_IOCP)
526-
// || !defined(ASIO_WINDOWS) && !defined(__CYGWIN__)
581+
// || !defined(ASIO_WINDOWS)
582+
// && !defined(ASIO_WINDOWS_RUNTIME)
583+
// && !defined(__CYGWIN__)
527584
#endif // !defined(ASIO_HAS_SERIAL_PORT)
528585

529586
// Windows: stream handles.
@@ -567,27 +624,39 @@
567624
// POSIX: stream-oriented file descriptors.
568625
#if !defined(ASIO_HAS_POSIX_STREAM_DESCRIPTOR)
569626
# if !defined(ASIO_DISABLE_POSIX_STREAM_DESCRIPTOR)
570-
# if !defined(ASIO_WINDOWS) && !defined(__CYGWIN__)
627+
# if !defined(ASIO_WINDOWS) \
628+
&& !defined(ASIO_WINDOWS_RUNTIME) \
629+
&& !defined(__CYGWIN__)
571630
# define ASIO_HAS_POSIX_STREAM_DESCRIPTOR 1
572-
# endif // !defined(ASIO_WINDOWS) && !defined(__CYGWIN__)
631+
# endif // !defined(ASIO_WINDOWS)
632+
// && !defined(ASIO_WINDOWS_RUNTIME)
633+
// && !defined(__CYGWIN__)
573634
# endif // !defined(ASIO_DISABLE_POSIX_STREAM_DESCRIPTOR)
574635
#endif // !defined(ASIO_HAS_POSIX_STREAM_DESCRIPTOR)
575636

576637
// UNIX domain sockets.
577638
#if !defined(ASIO_HAS_LOCAL_SOCKETS)
578639
# if !defined(ASIO_DISABLE_LOCAL_SOCKETS)
579-
# if !defined(ASIO_WINDOWS) && !defined(__CYGWIN__)
640+
# if !defined(ASIO_WINDOWS) \
641+
&& !defined(ASIO_WINDOWS_RUNTIME) \
642+
&& !defined(__CYGWIN__)
580643
# define ASIO_HAS_LOCAL_SOCKETS 1
581-
# endif // !defined(ASIO_WINDOWS) && !defined(__CYGWIN__)
644+
# endif // !defined(ASIO_WINDOWS)
645+
// && !defined(ASIO_WINDOWS_RUNTIME)
646+
// && !defined(__CYGWIN__)
582647
# endif // !defined(ASIO_DISABLE_LOCAL_SOCKETS)
583648
#endif // !defined(ASIO_HAS_LOCAL_SOCKETS)
584649

585650
// Can use sigaction() instead of signal().
586651
#if !defined(ASIO_HAS_SIGACTION)
587652
# if !defined(ASIO_DISABLE_SIGACTION)
588-
# if !defined(ASIO_WINDOWS) && !defined(__CYGWIN__)
653+
# if !defined(ASIO_WINDOWS) \
654+
&& !defined(ASIO_WINDOWS_RUNTIME) \
655+
&& !defined(__CYGWIN__)
589656
# define ASIO_HAS_SIGACTION 1
590-
# endif // !defined(ASIO_WINDOWS) && !defined(__CYGWIN__)
657+
# endif // !defined(ASIO_WINDOWS)
658+
// && !defined(ASIO_WINDOWS_RUNTIME)
659+
// && !defined(__CYGWIN__)
591660
# endif // !defined(ASIO_DISABLE_SIGACTION)
592661
#endif // !defined(ASIO_HAS_SIGACTION)
593662

@@ -765,13 +834,23 @@
765834
# if ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3)
766835
# if !defined(__INTEL_COMPILER) && !defined(__ICL)
767836
# define ASIO_HAS_THREAD_KEYWORD_EXTENSION 1
837+
# define ASIO_THREAD_KEYWORD __thread
768838
# elif defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 1100)
769839
# define ASIO_HAS_THREAD_KEYWORD_EXTENSION 1
770840
# endif // defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 1100)
771841
# endif // ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3)
772842
# endif // defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
773843
# endif // defined(__linux__)
844+
# if defined(ASIO_MSVC) && defined(WINAPI_FAMILY)
845+
# if (_MSC_VER >= 1700)
846+
# define ASIO_HAS_THREAD_KEYWORD_EXTENSION 1
847+
# define ASIO_THREAD_KEYWORD __declspec(thread)
848+
# endif // (_MSC_VER >= 1700)
849+
# endif // defined(ASIO_MSVC) && defined(WINAPI_FAMILY)
774850
#endif // !defined(ASIO_DISABLE_THREAD_KEYWORD_EXTENSION)
851+
#if !defined(ASIO_THREAD_KEYWORD)
852+
# define ASIO_THREAD_KEYWORD __thread
853+
#endif // !defined(ASIO_THREAD_KEYWORD)
775854

776855
// Support for POSIX ssize_t typedef.
777856
#if !defined(ASIO_DISABLE_SSIZE_T)

asio/include/asio/detail/deadline_timer_service.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
#include "asio/detail/wait_handler.hpp"
3131
#include "asio/detail/wait_op.hpp"
3232

33+
#if defined(ASIO_WINDOWS_RUNTIME)
34+
# include <chrono>
35+
# include <thread>
36+
#endif // defined(ASIO_WINDOWS_RUNTIME)
37+
3338
#include "asio/detail/push_options.hpp"
3439

3540
namespace asio {
@@ -194,10 +199,17 @@ class deadline_timer_service
194199
template <typename Duration>
195200
void do_wait(const Duration& timeout, asio::error_code& ec)
196201
{
202+
#if defined(ASIO_WINDOWS_RUNTIME)
203+
std::this_thread::sleep_for(
204+
std::chrono::seconds(timeout.total_seconds())
205+
+ std::chrono::microseconds(timeout.total_microseconds()));
206+
ec = asio::error_code();
207+
#else // defined(ASIO_WINDOWS_RUNTIME)
197208
::timeval tv;
198209
tv.tv_sec = timeout.total_seconds();
199210
tv.tv_usec = timeout.total_microseconds() % 1000000;
200211
socket_ops::select(0, 0, 0, 0, &tv, ec);
212+
#endif // defined(ASIO_WINDOWS_RUNTIME)
201213
}
202214

203215
// The queue of timers.

asio/include/asio/detail/descriptor_ops.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717

1818
#include "asio/detail/config.hpp"
1919

20-
#if !defined(ASIO_WINDOWS) && !defined(__CYGWIN__)
20+
#if !defined(ASIO_WINDOWS) \
21+
&& !defined(ASIO_WINDOWS_RUNTIME) \
22+
&& !defined(__CYGWIN__)
2123

2224
#include <cstddef>
2325
#include "asio/error_code.hpp"
@@ -108,6 +110,8 @@ ASIO_DECL int poll_write(int d,
108110
# include "asio/detail/impl/descriptor_ops.ipp"
109111
#endif // defined(ASIO_HEADER_ONLY)
110112

111-
#endif // !defined(ASIO_WINDOWS) && !defined(__CYGWIN__)
113+
#endif // !defined(ASIO_WINDOWS)
114+
// && !defined(ASIO_WINDOWS_RUNTIME)
115+
// && !defined(__CYGWIN__)
112116

113117
#endif // ASIO_DETAIL_DESCRIPTOR_OPS_HPP

asio/include/asio/detail/event.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
# include "asio/detail/win_event.hpp"
2424
#elif defined(ASIO_HAS_PTHREADS)
2525
# include "asio/detail/posix_event.hpp"
26+
#elif defined(ASIO_HAS_STD_MUTEX_AND_CONDVAR)
27+
# include "asio/detail/std_event.hpp"
2628
#else
27-
# error Only Windows and POSIX are supported!
29+
# error Only Windows, POSIX and std::condition_variable are supported!
2830
#endif
2931

3032
namespace asio {
@@ -36,6 +38,8 @@ typedef null_event event;
3638
typedef win_event event;
3739
#elif defined(ASIO_HAS_PTHREADS)
3840
typedef posix_event event;
41+
#elif defined(ASIO_HAS_STD_MUTEX_AND_CONDVAR)
42+
typedef std_event event;
3943
#endif
4044

4145
} // namespace detail

asio/include/asio/detail/fd_set_adapter.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
1717

1818
#include "asio/detail/config.hpp"
19+
20+
#if !defined(ASIO_WINDOWS_RUNTIME)
21+
1922
#include "asio/detail/posix_fd_set_adapter.hpp"
2023
#include "asio/detail/win_fd_set_adapter.hpp"
2124

@@ -31,4 +34,6 @@ typedef posix_fd_set_adapter fd_set_adapter;
3134
} // namespace detail
3235
} // namespace asio
3336

37+
#endif // !defined(ASIO_WINDOWS_RUNTIME)
38+
3439
#endif // ASIO_DETAIL_FD_SET_ADAPTER_HPP

0 commit comments

Comments
 (0)