⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 event.cpp

📁 Socketlib: 一个轻量级的C++ 封装Socket C API 网络编程框架。 它简化了Socket异步事件分派、进程间Socket通信的并发OO网络应用和服务的开发。 目前
💻 CPP
字号:
//**********************************************************************
//
// Copyright (C) 2005-2007 Zhang bao yuan(bolidezhang@gmail.com).
// All rights reserved.
//
// This copy of Socketlib is licensed to you under the terms described 
// in the LICENSE.txt file included in this distribution.
//
//**********************************************************************

#include "event.h"
namespace SYNC
{

inline CEvent::CEvent(void)
	: m_hEvent(NULL)
{
}

inline CEvent::CEvent(BOOL bManualReset, BOOL bInitialState)
	: m_hEvent(NULL)

{
	Create(NULL, bManualReset, bInitialState, NULL);
};

inline CEvent::CEvent(LPSECURITY_ATTRIBUTES pSecurity, BOOL bManualReset, BOOL bInitialState, LPCTSTR pszName)
	: m_hEvent(NULL)
{
	Create(pSecurity, bManualReset, bInitialState, pszName);
};

inline CEvent::~CEvent(void)
{
	Clear();
}

inline bool CEvent::Create( LPSECURITY_ATTRIBUTES pSecurity, BOOL bManualReset, BOOL bInitialState, LPCTSTR pszName)
{
	Clear();
	m_hEvent = ::CreateEvent(pSecurity, bManualReset, bInitialState, pszName);
	return (m_hEvent != NULL);
};

inline bool CEvent::Open( DWORD dwAccess, BOOL bInheritHandle, LPCTSTR pszName)
{
	HANDLE hEvent = ::OpenEvent(dwAccess, bInheritHandle, pszName);
	if (hEvent == NULL)
		return false;

	if (hEvent != m_hEvent)
	{
		Clear();
		m_hEvent = hEvent;
	}
	return true;
};

inline bool CEvent::Pulse()
{
	return (::PulseEvent(m_hEvent));
};

inline bool CEvent::Reset()
{
	return (::ResetEvent(m_hEvent));
};

inline bool CEvent::Signal()
{
	return (::SetEvent(m_hEvent));
};

inline bool CEvent::Clear()
{
	if (m_hEvent != NULL)
	{
		CloseHandle(m_hEvent);
		m_hEvent = NULL;
	}
	return true;
};

inline DWORD CEvent::Wait(DWORD nTimeOut)
{
	return WaitForSingleObject(m_hEvent, nTimeOut);
};

inline bool CEvent::Lock(DWORD nTimeOut)
{
	DWORD hRet = Wait(nTimeOut);
	if (WAIT_OBJECT_0 == hRet)
		return true;
	return false;
};

inline bool CEvent::Lock()
{
	DWORD hRet = Wait(INFINITE);
	if (WAIT_OBJECT_0 == hRet)
		return true;
	return false;
};

inline bool CEvent::UnLock()
{
	return Signal();
};

inline bool CEvent::TryLock()
{
	return false;
};

HANDLE CEvent::GetHandle() const
{
	return m_hEvent;
}

};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -