void epioer::mainfunction() { g_log.log(LOG_LV_INFO,"epioer thread come!"); const int maxevsize = 4096; int ifd = 0,nfd= 0,i = 0; epoll_event evarr[maxevsize]; int itimeout = 50; while (isrun()) { int iwaitnum = (m_socknum > 0 ? std::min((int)m_socknum,maxevsize) : maxevsize); ifd = epoll_wait(m_epfd,evarr,iwaitnum,itimeout); if (ifd == -1) { if(errno == EINTR) continue; g_log.log(LOG_LV_DEBUG,"epoll_wait fail,errno %d,socknum %d.",errno,iwaitnum); return; } for (i = 0; i != ifd; ++i) { if (evarr[i].events & EPOLLERR || evarr[i].events & EPOLLHUP) { g_log.log(LOG_LV_DEBUG,"fd %d event err %d.",evarr[i].data.fd,evarr[i].events); delsock(evarr[i].data.fd); }else if (evarr[i].events & EPOLLIN) { if (!m_pep->readx(evarr[i].data.fd)) { g_log.log(LOG_LV_DEBUG,"sock %d read false.",evarr[i].data.fd); delsock(evarr[i].data.fd); } else setctl(evarr[i].data.fd,EPOLLOUT); }else if (evarr[i].events & EPOLLOUT) { if (!m_pep->writex(evarr[i].data.fd)) { g_log.log(LOG_LV_DEBUG,"sock %d write false.",evarr[i].data.fd); delsock(evarr[i].data.fd); } else setctl(evarr[i].data.fd,EPOLLIN); } } } g_log.log(LOG_LV_INFO,"epioer thread exit!"); }
int main(){ int n,k,a[12]; scanf("%d%d",&n,&k); if(k==2){ if(isrun(n))printf("%d",29); else printf("28"); return 0; } switch(k){ case 1:case 3:case 5:case 7:case 8:case 10:case 12:printf("31");break; case 4:case 6:case 9:case 11:printf("30");break; } return 0; }
void eplister::mainfunction() { g_log.log(LOG_LV_INFO,"eplister thread come!"); int ifd = -1; sockaddr_in cliaddr; socklen_t addrlen = sizeof(cliaddr); //overtime handle thread; unsigned int uilastcheckalive = getticktime(); while (isrun()) { ifd = accept(m_listerfd,(sockaddr*)&cliaddr,&addrlen); if(ifd != -1) { g_log.log(LOG_LV_DEBUG,"link in,sock %d.",ifd); if (m_pep->bfull(ifd)) { g_log.log(LOG_LV_DEBUG,"link refuse,sock %d.",ifd); close(ifd); } else { m_pep->dispatch(ifd,cliaddr.sin_addr.s_addr,ntohs(cliaddr.sin_port)); } } else { if (errno == EAGAIN || errno == EWOULDBLOCK) usleep(1 * 1000); } if (getinterval(uilastcheckalive,getticktime()) > (MAXDIETIME / 2)) { m_pep->checkalive(); uilastcheckalive = getticktime(); } } g_log.log(LOG_LV_INFO,"eplister thread exit!"); }
/* vpsd is PVA process, executes in CT context via 'vzctl exec' * will kill */ int VEObj::stopVpsd() { char path[PATH_MAX + 1]; FILE *fp; pid_t pid; char buf[PATH_MAX + 1]; char *p; const char * args[] = { buf, NULL }; int tries; if (!isrun()) return 0; snprintf(path, sizeof(path), "%s/var/run/vpsd.pid", root); if ((fp = fopen(path, "r")) == NULL) return 0; if (fgets(buf, sizeof(buf), fp) == NULL) { fclose(fp); return 0; } fclose(fp); if ((p = strchr(buf, '\n'))) *p = '\0'; pid = atol(buf); snprintf(path, sizeof(path), "%s/proc/%d", root, pid); if (access(path, F_OK)) return 0; snprintf(buf, sizeof(buf), "kill -TERM %d", pid); for (tries = 0; tries < 10; ++tries) { operateVE("exec", "Exec", args, 0); sleep(1); if (access(path, F_OK)) return 0; } return putErr(MIG_ERR_SYSTEM, "Can't stop vpsd in CT %s", ctid()); }