1// 2// detail/win_event.ipp 3// ~~~~~~~~~~~~~~~~~~~~ 4// 5// Copyright (c) 2003-2019 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 ASIO_DETAIL_IMPL_WIN_EVENT_IPP 12#define 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 "asio/detail/config.hpp" 19 20#if defined(ASIO_WINDOWS) 21 22#include "asio/detail/throw_error.hpp" 23#include "asio/detail/win_event.hpp" 24#include "asio/error.hpp" 25 26#include "asio/detail/push_options.hpp" 27 28namespace asio { 29namespace detail { 30 31win_event::win_event() 32 : state_(0) 33{ 34#if defined(ASIO_WINDOWS_APP) 35 events_[0] = ::CreateEventExW(0, 0, 36 CREATE_EVENT_MANUAL_RESET, EVENT_ALL_ACCESS); 37#else // defined(ASIO_WINDOWS_APP) 38 events_[0] = ::CreateEventW(0, true, false, 0); 39#endif // defined(ASIO_WINDOWS_APP) 40 if (!events_[0]) 41 { 42 DWORD last_error = ::GetLastError(); 43 asio::error_code ec(last_error, 44 asio::error::get_system_category()); 45 asio::detail::throw_error(ec, "event"); 46 } 47 48#if defined(ASIO_WINDOWS_APP) 49 events_[1] = ::CreateEventExW(0, 0, 0, EVENT_ALL_ACCESS); 50#else // defined(ASIO_WINDOWS_APP) 51 events_[1] = ::CreateEventW(0, false, false, 0); 52#endif // defined(ASIO_WINDOWS_APP) 53 if (!events_[1]) 54 { 55 DWORD last_error = ::GetLastError(); 56 ::CloseHandle(events_[0]); 57 asio::error_code ec(last_error, 58 asio::error::get_system_category()); 59 asio::detail::throw_error(ec, "event"); 60 } 61} 62 63win_event::~win_event() 64{ 65 ::CloseHandle(events_[0]); 66 ::CloseHandle(events_[1]); 67} 68 69} // namespace detail 70} // namespace asio 71 72#include "asio/detail/pop_options.hpp" 73 74#endif // defined(ASIO_WINDOWS) 75 76#endif // ASIO_DETAIL_IMPL_WIN_EVENT_IPP 77