本文整理汇总了C++中CSession::sendToSocket方法的典型用法代码示例。如果您正苦于以下问题:C++ CSession::sendToSocket方法的具体用法?C++ CSession::sendToSocket怎么用?C++ CSession::sendToSocket使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CSession
的用法示例。
在下文中一共展示了CSession::sendToSocket方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
void *threadRoutine(void *args)
{
CSendThread *threadself = (CSendThread *)args;
CServerBase *svr = threadself->getServerPtr();
struct epoll_event epEvent[30];
cout << "CSendThread start threadRoutine" << endl;
//bool isRecvEvent = true;
while (true)
{
//cout << "CSendThread infinity loop epollfd:"<< svr->getIoEpollfd() << endl;
int32 evCount = epoll_wait(svr->getSendEpollfd(),epEvent, 30, -1);//100ms wait timeout infinite wait just one event to one sockfd
if (evCount > 0)
{
for (int i = 0; i < evCount; i++)
{
CSession *session = (CSession *)epEvent[i].data.ptr;
int32 oplen = 0;
if (epEvent[i].events & EPOLLOUT) // send msg to client
{
oplen = session->sendToSocket();
//isRecvEvent = false;
if (oplen > 0) // normal
{
//session->modEpollEvent(svr->getSendEpollfd(), isRecvEvent);//single thread do not need epolloneshoot
}
else if (oplen == -1)// socket error wait to free session
{
session->delEpollEvent(svr->getSendEpollfd());
session->setStatus(waitdel);
}
else // EAGAIN
{
acct_time::sleepMs(100);
}
}
}
}
else if (0 == evCount) //epoll timeout
{
acct_time::sleepMs(100);
// handle timeout??
//printf("CSendThread epoll timeout!!! epoll_wait return:%d\n", evCount);
}
else // ret < 0 error or interrupt
{
if (evCount == -1 && errno == EINTR)
{
acct_time::sleepMs(200);
printf("CSendThread epoll EINTR!!! epoll_wait return:%d\n", evCount);
continue;
}
acct_time::sleepMs(300);
perror("epoll_wait error!!!");
printf("CSendThread error!!! epoll_wait return:%d\n", evCount);
}
}
return NULL;
}