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); } }
void onWrite(int iFd,void *pData) { cout<<"onWrite "<<iFd<<endl; SESession *pSession = (SESession*)pData; ::send(iFd,pSession->szBuf,pSession->iSize,0); oCEvent.delFdEvent(iFd,CEvent::EV_WRITE); //::close(iFd); delete pSession; }
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; }