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