| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- /**************************************************************************************************
- 版本所有(C), 2020-2022, 北京普达迪泰
- ***************************************************************************************************
- 文 件 名: XEvent.cpp
- 功能描述: 封闭网络套接字事件通信
- 版 本 号: 1.00初版
- 作 者: HYF
- 生成日期; 2021-12-20
- 最近修改:
- 函数列表:
- 修改历史:
- 1.日 期 :2021-12-20
- 作 者 : HYF
- 修改内容 : 创建文件
- **************************************************************************************************/
- #include "pch.h"
- #include "XEvent.h"
- CXEvent::CXEvent()
- : m_hEvent(CreateEvent(NULL, TRUE, FALSE, 0))
- {
- }
- CXEvent::CXEvent(
- LPSECURITY_ATTRIBUTES lpEventAttributes,
- bool bManualReset,
- bool bInitialState)
- : m_hEvent(CreateEvent(lpEventAttributes, bManualReset, bInitialState, 0))
- {
- }
- CXEvent::CXEvent(
- LPSECURITY_ATTRIBUTES lpEventAttributes,
- bool bManualReset,
- bool bInitialState,
- const TCHAR* pName)
- : m_hEvent(CreateEvent(lpEventAttributes, bManualReset, bInitialState, pName))
- {
- }
- CXEvent::~CXEvent()
- {
- ::CloseHandle(m_hEvent);
- }
- HANDLE CXEvent::GetEvent() const
- {
- return m_hEvent;
- }
- bool CXEvent::Wait() const
- {
- if (!Wait(INFINITE))
- {
- return false;
- }
- return true;
- }
- bool CXEvent::Wait(DWORD timeoutMillis) const
- {
- bool bRet = true;
- DWORD dwResult = ::WaitForSingleObject(m_hEvent, timeoutMillis);
- if (dwResult == WAIT_TIMEOUT)
- bRet = false;
- else if (dwResult == WAIT_OBJECT_0)
- bRet = true;
-
- return bRet;
- }
- void CXEvent::Reset()
- {
- if (!::ResetEvent(m_hEvent))
- {
- //***
- //CXLog::Write("CXEvent::Reset() failed", ::GetLastError());
- }
- }
- void CXEvent::Set()
- {
- if (!::SetEvent(m_hEvent))
- {
- ASSERT(NULL);
- //CXLog::Write("CXEvent::Set() failed", ::GetLastError());
- }
- }
- void CXEvent::Pulse()
- {
- if (!::PulseEvent(m_hEvent))
- {
- //CXLog::Write("CXEvent::Pulse() failed", ::GetLastError());
- }
- }
|