XEvent.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /**************************************************************************************************
  2. 版本所有(C), 2020-2022, 北京普达迪泰
  3. ***************************************************************************************************
  4. 文 件 名: XEvent.cpp
  5. 功能描述: 封闭网络套接字事件通信
  6. 版 本 号: 1.00初版
  7. 作 者: HYF
  8. 生成日期; 2021-12-20
  9. 最近修改:
  10. 函数列表:
  11. 修改历史:
  12. 1.日 期 :2021-12-20
  13. 作 者 : HYF
  14. 修改内容 : 创建文件
  15. **************************************************************************************************/
  16. #include "pch.h"
  17. #include "XEvent.h"
  18. CXEvent::CXEvent()
  19. : m_hEvent(CreateEvent(NULL, TRUE, FALSE, 0))
  20. {
  21. }
  22. CXEvent::CXEvent(
  23. LPSECURITY_ATTRIBUTES lpEventAttributes,
  24. bool bManualReset,
  25. bool bInitialState)
  26. : m_hEvent(CreateEvent(lpEventAttributes, bManualReset, bInitialState, 0))
  27. {
  28. }
  29. CXEvent::CXEvent(
  30. LPSECURITY_ATTRIBUTES lpEventAttributes,
  31. bool bManualReset,
  32. bool bInitialState,
  33. const TCHAR* pName)
  34. : m_hEvent(CreateEvent(lpEventAttributes, bManualReset, bInitialState, pName))
  35. {
  36. }
  37. CXEvent::~CXEvent()
  38. {
  39. ::CloseHandle(m_hEvent);
  40. }
  41. HANDLE CXEvent::GetEvent() const
  42. {
  43. return m_hEvent;
  44. }
  45. bool CXEvent::Wait() const
  46. {
  47. if (!Wait(INFINITE))
  48. {
  49. return false;
  50. }
  51. return true;
  52. }
  53. bool CXEvent::Wait(DWORD timeoutMillis) const
  54. {
  55. bool bRet = true;
  56. DWORD dwResult = ::WaitForSingleObject(m_hEvent, timeoutMillis);
  57. if (dwResult == WAIT_TIMEOUT)
  58. bRet = false;
  59. else if (dwResult == WAIT_OBJECT_0)
  60. bRet = true;
  61. return bRet;
  62. }
  63. void CXEvent::Reset()
  64. {
  65. if (!::ResetEvent(m_hEvent))
  66. {
  67. //***
  68. //CXLog::Write("CXEvent::Reset() failed", ::GetLastError());
  69. }
  70. }
  71. void CXEvent::Set()
  72. {
  73. if (!::SetEvent(m_hEvent))
  74. {
  75. ASSERT(NULL);
  76. //CXLog::Write("CXEvent::Set() failed", ::GetLastError());
  77. }
  78. }
  79. void CXEvent::Pulse()
  80. {
  81. if (!::PulseEvent(m_hEvent))
  82. {
  83. //CXLog::Write("CXEvent::Pulse() failed", ::GetLastError());
  84. }
  85. }