win_event.ipp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // detail/win_event.ipp
  3. // ~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2015 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. #ifndef ASIO_DETAIL_IMPL_WIN_EVENT_IPP
  11. #define ASIO_DETAIL_IMPL_WIN_EVENT_IPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/config.hpp"
  16. #if defined(ASIO_WINDOWS)
  17. #include "asio/detail/throw_error.hpp"
  18. #include "asio/detail/win_event.hpp"
  19. #include "asio/error.hpp"
  20. #include "asio/detail/push_options.hpp"
  21. namespace asio {
  22. namespace detail {
  23. win_event::win_event()
  24. : state_(0)
  25. {
  26. events_[0] = ::CreateEvent(0, true, false, 0);
  27. if (!events_[0])
  28. {
  29. DWORD last_error = ::GetLastError();
  30. asio::error_code ec(last_error,
  31. asio::error::get_system_category());
  32. asio::detail::throw_error(ec, "event");
  33. }
  34. events_[1] = ::CreateEvent(0, false, false, 0);
  35. if (!events_[1])
  36. {
  37. DWORD last_error = ::GetLastError();
  38. ::CloseHandle(events_[0]);
  39. asio::error_code ec(last_error,
  40. asio::error::get_system_category());
  41. asio::detail::throw_error(ec, "event");
  42. }
  43. }
  44. win_event::~win_event()
  45. {
  46. ::CloseHandle(events_[0]);
  47. ::CloseHandle(events_[1]);
  48. }
  49. } // namespace detail
  50. } // namespace asio
  51. #include "asio/detail/pop_options.hpp"
  52. #endif // defined(ASIO_WINDOWS)
  53. #endif // ASIO_DETAIL_IMPL_WIN_EVENT_IPP