本文整理汇总了C++中CTcpSocket::OnPostClose方法的典型用法代码示例。如果您正苦于以下问题:C++ CTcpSocket::OnPostClose方法的具体用法?C++ CTcpSocket::OnPostClose怎么用?C++ CTcpSocket::OnPostClose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CTcpSocket
的用法示例。
在下文中一共展示了CTcpSocket::OnPostClose方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Run
void CIOServer::Run()
{
epoll_event events[10000];
int retCount = 0;
bool bRuning = true;
unsigned int timerTime = GetTimeMillisecond();
while (true)
{
retCount = epoll_wait(m_epoll, events, 10000, 1000);
if (retCount == -1)
{
if (errno != EINTR)
{
LCD("ERR: epoll_wait err! errno=" <<strerror(errno));
break;
}
continue;
}
//check timer
{
unsigned int curTime = GetTimeMillisecond();
if (curTime - timerTime > 1000)
{
timerTime = curTime;
m_cb->OnTimer();
}
if (retCount == 0) continue;//timeout
}
for (int i=0; i<retCount; i++)
{
int eventflag = events[i].events;
tagRegister * pReg = (tagRegister *)events[i].data.ptr;
//tagHandle type
if (pReg->_type == tagRegister::REG_THREAD)
{
char buf[1000];
while (recv(pReg->_socket, buf, 1000, 0) > 0){}
MsgVct msgs;
m_msglock.Lock();
msgs = m_msgs;
m_msgs.clear();
m_msglock.UnLock();
for (MsgVct::iterator iter = msgs.begin(); iter != msgs.end(); ++iter)
{
if (iter->first == PCK_EPOLL_EXIT)
{
LCD("INFO: epoll recv exit event");
bRuning = false;
continue;
}
else if (iter->first == PCK_ACCEPT_CLOSE)
{
CTcpAccept * p = (CTcpAccept *) iter->second;
p->OnPostClose();
}
else if (iter->first == PCK_SOCKET_CLOSE)
{
CTcpSocket *p = (CTcpSocket*)iter->second;
p->OnPostClose();
}
else if (iter->first == PCK_USER_DATA)
{
m_cb->OnMsg(iter->second);
}
}
}
else if (pReg->_type == tagRegister::REG_ACCEPT)
{
CTcpAccept *pKey = (CTcpAccept *) pReg->_ptr;
if (eventflag & EPOLLIN)
{
pKey->OnEPOLLMessage(true);
}
if (eventflag & EPOLLERR || eventflag & EPOLLHUP)
{
pKey->OnEPOLLMessage(false);
}
}
else
{
if (pReg->_type != tagRegister::REG_RECV
&& pReg->_type != tagRegister::REG_SEND
&& pReg->_type != tagRegister::REG_CONNECT)
{
LCE("check register event type failed !! type=" << pReg->_type);
continue;
}
CTcpSocket *pKey = (CTcpSocket *) pReg->_ptr;
pKey->OnEPOLLMessage(pReg->_type, eventflag);
}
}
if (!bRuning)
{
break;
//.........这里部分代码省略.........