本文整理汇总了C++中EndPoint::close方法的典型用法代码示例。如果您正苦于以下问题:C++ EndPoint::close方法的具体用法?C++ EndPoint::close怎么用?C++ EndPoint::close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EndPoint
的用法示例。
在下文中一共展示了EndPoint::close方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
int
IterativeServer::epollLoop()
{
#if 0
MustBeTrue(ok_);
MustBeTrue(!endpoints_.empty());
epoll_event ev;
::memset(&ev,0,sizeof(ev));
epoll_event events[DefaultEPollEventsToHandle];
for (Timer2 zero(0,0); !endpoints_.empty(); )
{
// do we have any timers?
int timer;
TMRQIter tit = tmrqueue_.begin();
if (tit != tmrqueue_.end())
{
Timer2 t2 = tit->first;
Timer2 now;
now.setToNow();
t2 -= now;
if (t2 < zero) t2 = zero;
timer = t2.getTimeInMillisecs();
}
else
{
timer = -1;
}
// wait for an event
int eventnum = ::epoll_wait(epollfd_, events,
DefaultEPollEventsToHandle, timer);
if (eventnum < 0)
{
// error of some type
TMSG("epoll_wait failed");
DUMP(errno);
return(-1);
}
else if (eventnum == 0)
{
// we have a timeout. check queue
TMRQIter titbegin = tmrqueue_.begin();
TMRQIter titend = tmrqueue_.end();
TMRQIter tit = tmrqueue_.begin();
Timer2 now;
now.setToNow();
for ( ; tit != titend && tit->first <= now; ++tit)
{
Timer2 tmr = tit->second.first;
EndPoint ep = tit->second.second;
int socket = ep.getSocket();
THS::iterator hit = timerhandlers_.find(socket);
if (hit == timerhandlers_.end()) continue;
TimerHandler *handler = hit->second.second;
int status = (*handler)(ep, tmr);
if (status > 0)
{
// success and done with this server
::epoll_ctl(epollfd_, EPOLL_CTL_DEL, socket, &ev);
unregisterAllHandlers(ep);
ep.close();
}
else if (status < 0)
{
// some type of error. for now, close endpoint
TMSG("timer handler failed");
DUMP(ep); DUMP(socket); DUMP(errno);
::epoll_ctl(epollfd_, EPOLL_CTL_DEL, socket, &ev);
unregisterAllHandlers(ep);
ep.close();
}
}
tmrqueue_.erase(titbegin, tit);
}
else
{
// we have i/o to handle
for (int ievent=0; ievent<eventnum; ++ievent)
{
// socket with an event
int socket = events[ievent].data.fd;
// handle i/o
HS::iterator hit = handlers_.find(socket);
if (hit == handlers_.end()) continue;
EndPoint ep = hit->second.first;
Handler *handler = hit->second.second;
int status = (*handler)(ep);
if (status > 0)
{
// success and done with this server
::epoll_ctl(epollfd_, EPOLL_CTL_DEL, socket, &ev);
//.........这里部分代码省略.........