Imported Upstream version 1.64.0
[platform/upstream/boost.git] / boost / asio / detail / impl / win_event.ipp
1 //
2 // detail/win_event.ipp
3 // ~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 //
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)
9 //
10
11 #ifndef BOOST_ASIO_DETAIL_IMPL_WIN_EVENT_IPP
12 #define BOOST_ASIO_DETAIL_IMPL_WIN_EVENT_IPP
13
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17
18 #include <boost/asio/detail/config.hpp>
19
20 #if defined(BOOST_ASIO_WINDOWS)
21
22 #include <boost/asio/detail/throw_error.hpp>
23 #include <boost/asio/detail/win_event.hpp>
24 #include <boost/asio/error.hpp>
25
26 #include <boost/asio/detail/push_options.hpp>
27
28 namespace boost {
29 namespace asio {
30 namespace detail {
31
32 win_event::win_event()
33   : state_(0)
34 {
35 #if defined(BOOST_ASIO_WINDOWS_APP)
36   events_[0] = ::CreateEventExW(0, 0, CREATE_EVENT_MANUAL_RESET, 0);
37 #else // defined(BOOST_ASIO_WINDOWS_APP)
38   events_[0] = ::CreateEventW(0, true, false, 0);
39 #endif // defined(BOOST_ASIO_WINDOWS_APP)
40   if (!events_[0])
41   {
42     DWORD last_error = ::GetLastError();
43     boost::system::error_code ec(last_error,
44         boost::asio::error::get_system_category());
45     boost::asio::detail::throw_error(ec, "event");
46   }
47
48 #if defined(BOOST_ASIO_WINDOWS_APP)
49   events_[1] = ::CreateEventExW(0, 0, 0, 0);
50 #else // defined(BOOST_ASIO_WINDOWS_APP)
51   events_[1] = ::CreateEventW(0, false, false, 0);
52 #endif // defined(BOOST_ASIO_WINDOWS_APP)
53   if (!events_[1])
54   {
55     DWORD last_error = ::GetLastError();
56     ::CloseHandle(events_[0]);
57     boost::system::error_code ec(last_error,
58         boost::asio::error::get_system_category());
59     boost::asio::detail::throw_error(ec, "event");
60   }
61 }
62
63 win_event::~win_event()
64 {
65   ::CloseHandle(events_[0]);
66   ::CloseHandle(events_[1]);
67 }
68
69 } // namespace detail
70 } // namespace asio
71 } // namespace boost
72
73 #include <boost/asio/detail/pop_options.hpp>
74
75 #endif // defined(BOOST_ASIO_WINDOWS)
76
77 #endif // BOOST_ASIO_DETAIL_IMPL_WIN_EVENT_IPP