本文整理汇总了C++中connection::Ptr::processWrite方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptr::processWrite方法的具体用法?C++ Ptr::processWrite怎么用?C++ Ptr::processWrite使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类connection::Ptr
的用法示例。
在下文中一共展示了Ptr::processWrite方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: masterLoop
void Network::masterLoop()
{
struct timeval tv;
fd_set cur_set;
halt = false;
while (!halt) {
//sleep(1);
bool netstat = active;
while(!timers.empty() && (timers.top()->getExpireTime() <= static_cast<uint64_t>(time(NULL)) ||
!(timers.top()->isValid()))){
TimerCallback::Ptr callback = timers.top();
timers.pop();
if(callback->isValid())
callback->call();
}
if(timers.empty()){
tv.tv_sec = 60;
tv.tv_usec = 0;
}else{
tv.tv_sec = (timers.top()->getExpireTime() - time(NULL)) - 1;
if(tv.tv_sec <= 0){
tv.tv_sec = 0;
tv.tv_usec = 200000;
}else{
tv.tv_usec = 0;
}
}
fd_set write_set;
FD_ZERO(&write_set);
// Unsure what the macro FD_SET stands for, so I can't do for_each
for(ConnMap::iterator itcurr = writequeue.begin();
itcurr != writequeue.end(); ++itcurr){
FD_SET(itcurr->first, &write_set);
}
cur_set = master_set;
if (select(max_fd + 1, &cur_set, &write_set, NULL, &tv) > 0) {
for(ConnMap::iterator itcurr = writequeue.begin();
itcurr != writequeue.end(); ++itcurr){
if(FD_ISSET(itcurr->first, &write_set)){
Connection::Ptr conn = itcurr->second;
writequeue.erase(itcurr);
conn->processWrite();
//use select again, don't check rest of list as it has changed.
break;
}
}
ConnMap::iterator itcurr;
for (itcurr = connections.begin(); itcurr != connections.end(); itcurr++) {
Connection::Ptr connection = itcurr->second;
if (FD_ISSET(itcurr->first, &cur_set)) {
connection->process();
}
if (connection->getStatus() == Connection::DISCONNECTED) {
INFO("Closed connection %d", connection->getFD());
removeConnection(itcurr->first);
//use select again, don't check rest of list as it has changed.
break;
}
}
}
//advertiser->poll();
if(netstat != active && active == false){
for_each_key( connections.begin(), connections.end(), boost::bind( &Network::removeConnection, this, _1 ) );
DEBUG("Network really stopped");
}
}
}