libevent C++面向对象的封装
作者:方振涛
对event_base操作的封装如下:
class TEventContext
{
public:
static void InitLib()
{
WORD wVersionRequested;
WSADATA wsaData;
wVersionRequested = MAKEWORD(2, 2);
WSAStartup(wVersionRequested, &wsaData);
}
public:
TEventContext(event_base* evbase=NULL):m_evBase(evbase){}
~TEventContext(){
if (m_evBase)
{
event_base_free(m_evBase);
}
}
bool Init()
{
if(m_evBase)
return false;
m_evBase=event_base_new();
return m_evBase!=NULL;
}
bool ReInit()
{
return event_reinit(m_evBase)==0;
}
bool Dispatch()//进入事件处理循环
{
return event_base_dispatch(m_evBase)==0;
}
const char*GetMethod()
{
return event_base_get_method(m_evBase);
}
int GetFeatures(){return event_base_get_features(m_evBase);}
enum
{
FLoopOnce=EVLOOP_ONCE,
FLoopNonBlock=EVLO