void onTimer(uint32_t dwTimerId,void *pData) { cout<<"onTimer"<<endl; oCEvent.addMessage(1,onMessage,NULL); oCEvent.addMessage(1,onMessage,NULL); oCEvent.addTimer(dwTimerId,2000,onTimer,NULL); /* int iFd=lce::createTcpSock(); cout<<"fd="<<iFd<<endl; lce::setNBlock(iFd); int iRet=lce::connect(iFd,"127.0.0.1",80); if(iRet != -1) { cout<<"connect"<<endl; } else { if (errno == EINPROGRESS) { cout<<"add event"<<endl; oCEvent.addFdEvent(iFd,CEvent::EV_WRITE,onConnect,NULL); } } */ }
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; }