本文整理汇总了C++中CEvent::addFdEvent方法的典型用法代码示例。如果您正苦于以下问题:C++ CEvent::addFdEvent方法的具体用法?C++ CEvent::addFdEvent怎么用?C++ CEvent::addFdEvent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CEvent
的用法示例。
在下文中一共展示了CEvent::addFdEvent方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onRead
void onRead(int iFd,void *pData)
{
cout<<"onRead "<<iFd<<endl;
SESession *pSession=new SESession();
pSession->iSize=::read(iFd,pSession->szBuf,MAXLINE);
if (pSession->iSize > 0)
{
pSession->szBuf[pSession->iSize]='\0';
cout<<pSession->szBuf<<endl;
oCEvent.addFdEvent(iFd,CEvent::EV_WRITE,onWrite,pSession);
}
else if(pSession->iSize == 0)
{
delete pSession;
oCEvent.delFdEvent(iFd,CEvent::EV_WRITE|CEvent::EV_READ);
lce::close(iFd);
cout<<"onClose "<<iFd<<endl;
}
else
{
delete pSession;
oCEvent.delFdEvent(iFd,CEvent::EV_WRITE|CEvent::EV_READ);
lce::close(iFd);
}
}
示例2: onAccept
void onAccept(int iFd,void *pData)
{
cout<<"onAccept"<<endl;
struct sockaddr_in stClientAddr;
int iAddrLen = sizeof(struct sockaddr_in);
int iClientSock = accept(iFd, (struct sockaddr *) &stClientAddr,(socklen_t *)&iAddrLen);
if (iClientSock < 0)
{
cout<<"accept error"<<endl;
return;
}
cout<<"client fd:"<<iClientSock<<endl;
lce::setNBlock(iClientSock);
oCEvent.addFdEvent(iClientSock,CEvent::EV_READ,onRead,NULL);
}
示例3: onConnect
void onConnect(int iFd,void *pData)
{
oCEvent.delFdEvent(iFd,CEvent::EV_READ|CEvent::EV_WRITE);
int err = 0;
socklen_t errlen = sizeof(err);
if(getsockopt(iFd, SOL_SOCKET, SO_ERROR, &err, &errlen) < 0)
{
cout<<"fail1"<<endl;
return;
}
if(err == 0)
{
cout<<"onConnect"<<endl;
}
else
{
cout<<"onConnectFail"<<endl;
}
oCEvent.addFdEvent(iFd,CEvent::EV_READ,onRead,NULL);
cout<<"onConnect"<<endl;
}
示例4: main
int main()
{
int iSrvSock = 0;
iSrvSock= lce::createTcpSock();
if(iSrvSock < 0)
{
cout<<"onConnect"<<endl;
printf("error=%d,msg=%s",errno,strerror(errno));
return 0;
}
lce::setReUseAddr(iSrvSock);
lce::setNBlock(iSrvSock);
if(lce::bind(iSrvSock,"127.0.0.1",3000) < 0)
{
printf("bind error=%d,msg=%s",errno,strerror(errno));
return 0;
}
lce::listen(iSrvSock);
int iRet = oCEvent.init();
if(iRet < 0)
{
printf("msg=%s",oCEvent.getErrorMsg());
return 0;
}
oCEvent.addTimer(0,2000,onTimer,NULL);
if(oCEvent.addFdEvent(iSrvSock,CEvent::EV_READ,onAccept,NULL)!=0)
{
printf("xxxxxxxxxxxxx1");
}
oCEvent.run();
return 0;
}