//SIGPIPE信号write to pipe with no readers int Thread::Execute() { int rfd,wfd; rfd = set.in; wfd = set.out; int i,j; struct req_t *req; unsigned int address=0; while(1) { i=read(rfd,&address,sizeof(struct req_t*)); if(i==-1&&(errno==EINTR||errno==EAGAIN||errno==EWOULDBLOCK)) continue; else if(i==-1) { cerr<<"read from pipe error:"<<strerror(errno)<<endl; getchar(); return -1; } req = (struct req_t*)address; dealWith(req); //防止把数据写入管道阻塞 m_vAddr.push_back(address); for(vector<unsigned int>::iterator it=m_vAddr.begin();it<m_vAddr.end();it++) { address=*it; j= write(wfd,&address,sizeof(struct req_t*)); if(j==-1) { if(errno==EINTR) continue; else if(errno==EAGAIN||errno==EWOULDBLOCK) break; else { cerr<<"write into pipe error!"<<endl; getchar(); return -1; } } else if(j!=4) { cerr<<"write into pipe error:"<<strerror(errno)<<endl; getchar(); return -1; } else { // cout<<"write it:"<<*it<<endl; m_vAddr.erase(it); num++; } } // cut<<"size:"<<m_vAddr.size()<<endl; // out<<"size:"<<m_vAddr.size()<<" tid:"<<pthread_self()<<" response num:"<<num<<endl; } return 0; }
bool CCuco::actOn( int newX, int newY, std::shared_ptr<CMap> map ) { if (map->isValid( newX, newY ) ) { if (map->map[ newY][ newX ] != nullptr && map->map[ newY][ newX ]->team == Team::HEROES) { if (dealWith( map, newX, newY ) ) { return true; } } if ( map->isBlockAt( newX, newY ) ) { return true; } } return false; }
void Copy::dealWithGuard(Hero *hero){ dealWith(hero); }