void nstx_handlepacket(const char *ptr, size_t len, void (*nstx_usepacket)(const char*, size_t)) { struct nstxhdr *nstxpkt = (struct nstxhdr *) ptr; struct nstx_item *nstxitem; char *netpacket; int netpacketlen; if ((!ptr) || (signed int) len < (signed int) sizeof(struct nstxhdr)) return; if (!nstxpkt->id) return; nstxitem = get_item_by_id(nstxpkt->id); if (!nstxitem) nstxitem = alloc_item(nstxpkt->id); if (add_data(nstxitem, nstxpkt, len)) { netpacket = dealloc_item(nstxitem, &netpacketlen); nstx_usepacket(netpacket, netpacketlen); } check_timeouts(); }
void check_timeouts(void) { /* nothing to do */ if (displayed->length == 0) return; for (GList * iter = g_queue_peek_head_link(displayed); iter; iter = iter->next) { notification *n = iter->data; /* don't timeout when user is idle */ if (x_is_idle()) { n->start = time(NULL); continue; } /* skip hidden and sticky messages */ if (n->start == 0 || n->timeout == 0) { continue; } /* remove old message */ if (difftime(time(NULL), n->start) > n->timeout) { /* close_notification may conflict with iter, so restart */ notification_close(n, 1); check_timeouts(); return; } } }
void TMClist::SetTimeToLive(time_t TTL) { if (time_to_live != TTL){ time_to_live = TTL; if (check_timeouts()) is_changed = true; } }
void loop() { while(!kb.keys[SDLK_ESCAPE] && !kb.exit) { check_timeouts(); handle_events(); //handles input, then moves blit_all(); SDL_Delay(1000/BASE_FPS); } }
dbuf_t *dtry_reasm_timed(void *pile, uint32_t xid, char *data, uint16_t len, uint16_t offs, int more, time_t now) { reasm_pile_struct_t *rp = (void *)(((dbuf_t *)pile)->buf); reasm_chunk_t *chk; if (now > 0) { check_timeouts(rp, now); } if(offs + len > rp->mtu) { debug(DBG_REASM, 10, "Offset + length (%d + %d) of fragment > MTU (%d), discard", offs, len, rp->mtu); return NULL; } if ((offs > 0) && (offs < HOLE_MIN_LENGTH)) { debug(DBG_REASM, 10, "Offset %d less than min hole length %d\n", offs, HOLE_MIN_LENGTH); return NULL; } chk = hfind(rp->chs, &xid, sizeof(xid)); if (!chk) { debug(DBG_REASM, 10, "Reasm chunk %lu not found, creating", xid); chk = malloc(sizeof(reasm_chunk_t)); chk->xid = xid; chk->maxfrags = rp->maxfrags; chk->hole = 0; chk->esize = rp->ftu; chk->d = dalloc(chk->esize); chk->deadline = now + rp->reasm_timeout; memset(chk->d->buf, 0xaa, chk->d->size); hole_set(chk, 0, chk->esize, 0); hinsert(rp->chs, &xid, sizeof(xid), chk, chk_destructor, NULL, NULL, NULL); TAILQ_INSERT_TAIL(&rp->lru, chk, entries); } else { debug(DBG_REASM, 10, "Reasm chunk %lu found", xid); } debug(DBG_REASM, 100, "Chunk data (hole: %d, esize: %d):", chk->hole, chk->esize); debug_dump(DBG_REASM, 100, chk->d->buf, chk->d->size); if(offs + len > chk->d->size) { debug(DBG_REASM, 10, "Reasm chunk %lu overflow - %d + %d > %d", xid, offs, len, chk->d->size); /* We already checked the MTU overflow above, so we can safely reallocate here */ int oldsize = chk->d->size; dgrow(chk->d, rp->mtu - chk->d->size); hole_grow(chk, oldsize-1, chk->d->size); chk->esize = chk->d->size; debug(DBG_REASM, 100, "Fresh chunk data after growth to MTU:"); debug_dump(DBG_REASM, 100, chk->d->buf, chk->d->size); } chk->atime = now; return dperform_reasm(rp, chk, xid, data, len, offs, more); }
static int without_jobs() { check_lua_sleep_timeouts(); check_timeouts(); if ( checkProcessForExit() || has_error_for_exit ) { //network_send_error ( epd, 500, "Child Process restart!" ); //close_client ( epd ); } sync_serv_status(); do_other_jobs(); }
ioremap::elliptics::data_pointer queue::peek(entry_id *entry_id) { check_timeouts(); ioremap::elliptics::data_pointer d; *entry_id = {-1, -1}; while (true) { auto found = m_chunks.begin(); if (found == m_chunks.end()) { break; } int chunk_id = found->first; auto chunk = found->second; entry_id->chunk = chunk_id; d = chunk->pop(&entry_id->pos); LOG_INFO("popping entry %d-%d (%ld)'%s'", entry_id->chunk, entry_id->pos, d.size(), d.to_string()); if (!d.empty()) { m_statistics.pop_count++; // set or reset timeout timer for the chunk update_chunk_timeout(chunk_id, chunk); } if (chunk_id == m_state.chunk_id_push) { break; } if (chunk->expect_no_more()) { //FIXME: this could happen to be called many times for the same chunk // (between queue restarts or because of chunk replaying) chunk->add(&m_statistics.chunks_popped); LOG_INFO("chunk %d exhausted, dropped from the popping line", chunk_id); // drop chunk from the pop list m_chunks.erase(found); } break; } return d; }
data_array queue::peek(int num) { check_timeouts(); data_array ret; while (num > 0) { auto found = m_chunks.begin(); if (found == m_chunks.end()) { break; } int chunk_id = found->first; auto chunk = found->second; data_array d = chunk->pop(num); LOG_INFO("chunk %d, popping %d entries", chunk_id, d.sizes().size()); if (!d.empty()) { m_statistics.pop_count += d.sizes().size(); ret.extend(d); // set or reset timeout timer for the chunk update_chunk_timeout(chunk_id, chunk); } if (chunk_id == m_state.chunk_id_push) { break; } if (chunk->expect_no_more()) { //FIXME: this could happen to be called many times for the same chunk // (between queue restarts or because of chunk replaying) chunk->add(&m_statistics.chunks_popped); LOG_INFO("chunk %d exhausted, dropped from the popping line", chunk_id); // drop chunk from the pop list m_chunks.erase(found); } num -= d.sizes().size(); } return ret; }
void update_lists() { int limit; check_timeouts(); if (pause_display) { while (displayed->length > 0) { g_queue_insert_sorted(queue, g_queue_pop_head(displayed), notification_cmp_data, NULL); } return; } if (xctx.geometry.h == 0) { limit = 0; } else if (xctx.geometry.h == 1) { limit = 1; } else if (settings.indicate_hidden) { limit = xctx.geometry.h - 1; } else { limit = xctx.geometry.h; } /* move notifications from queue to displayed */ while (queue->length > 0) { if (limit > 0 && displayed->length >= limit) { /* the list is full */ break; } notification *n = g_queue_pop_head(queue); if (!n) return; n->start = time(NULL); if (!n->redisplayed && n->script) { notification_run_script(n); } g_queue_insert_sorted(displayed, n, notification_cmp_data, NULL); } }
void step(Queue *channel) { check_result(channel); check_timeouts(s3eTimerGetUTC(),channel); check_queue(channel); }
/* ioctl */ static long intel_scu_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { void __user *argp = (void __user *)arg; u32 __user *p = argp; u32 val; int options; static const struct watchdog_info ident = { .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING, /* @todo Get from SCU via ipc_get_scu_fw_version()? */ .firmware_version = 0, /* len < 32 */ .identity = "Intel_SCU IOH Watchdog" }; switch (cmd) { case WDIOC_GETSUPPORT: return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0; case WDIOC_GETSTATUS: case WDIOC_GETBOOTSTATUS: return put_user(0, p); case WDIOC_KEEPALIVE: pr_warn("%s: KeepAlive ioctl\n", __func__); if (!watchdog_device.started) return -EINVAL; watchdog_keepalive(); return 0; case WDIOC_SETPRETIMEOUT: pr_warn("%s: SetPreTimeout ioctl\n", __func__); if (watchdog_device.started) return -EBUSY; /* Timeout to warn */ if (get_user(val, p)) return -EFAULT; pre_timeout = val; return 0; case WDIOC_SETTIMEOUT: pr_warn("%s: SetTimeout ioctl\n", __func__); if (watchdog_device.started) return -EBUSY; if (get_user(val, p)) return -EFAULT; timeout = val; return 0; case WDIOC_GETTIMEOUT: return put_user(timeout, p); case WDIOC_SETOPTIONS: if (get_user(options, p)) return -EFAULT; if (options & WDIOS_DISABLECARD) { pr_warn("%s: Stopping the watchdog\n", __func__); watchdog_stop(); return 0; } if (options & WDIOS_ENABLECARD) { pr_warn("%s: Starting the watchdog\n", __func__); if (watchdog_device.started) return -EBUSY; if (check_timeouts(pre_timeout, timeout)) { pr_warn("%s: Invalid thresholds\n", __func__); return -EINVAL; } if (watchdog_config_and_start(timeout, pre_timeout)) return -EINVAL; return 0; } return 0; default: return -ENOTTY; } } static int watchdog_set_reset_type(int reset_type) { int ret; struct ipc_wd_on_timeout { u32 reset_type; } ipc_wd_on_timeout = { reset_type }; ret = rpmsg_send_command(watchdog_instance, IPC_WATCHDOG, SCU_WATCHDOG_SET_ACTION_ON_TIMEOUT, (u8 *)&ipc_wd_on_timeout, NULL, sizeof(ipc_wd_on_timeout), 0); if (ret) { pr_crit("Error setting watchdog action: %d\n", ret); return -EIO; } watchdog_device.normal_wd_action = reset_type; return 0; }
void TMClist::AddGroup(RDSgroup& group) { if (group.GetGroupStatus() != GS_COMPLETE) return; TMCtype type = (TMCtype)((group.GetByte(1,0) & 0x18) >> 3); int duration = group.GetByte(1,0) & 0x07; int CI = duration; int event = group.GetWord(2) & 0x7FF; int location = group.GetWord(3); int extent = (group.GetByte(2,1) & 0x38) >> 3; int direction = (group.GetByte(2,1) & 0x40) >> 6; int SGI = direction; int diversion = (group.GetByte(2,1) & 0x80) >> 7; int GSI = (group.GetByte(2,1) & 0x30) >> 4; int frequency = ((group.GetWord(2) & 0xFFF) << 16)+group.GetWord(3); ostringstream oss; int i; switch (type){ case TMC_GROUP: if ((CI >= 1) & (CI <= 6)) { /* CI=0 is for encrypted TMCpro */ /* CI=7 is reserved for future use */ if (diversion) { /* first group */ oss << "GF evt=" << event << " loc=" << location; oss << " ext=" << extent << " CI=" << CI; oss << " dir=" << direction; } else { /* subsequent groups */ oss << "GS CI=" << CI << " GSI=" << GSI; oss << " F1=" << event << " F2=" << location; // Free Format } break; case TMC_SINGLE: oss << "S evt=" << event << " loc=" << location; oss << " ext=" << extent << " dur=" << duration; oss << " dir=" << direction << " div=" << diversion; break; case TMC_SYSTEM: oss << "Y "; switch (CI){ case 0: case 1: case 2: case 3: oss << "CI=" << CI << " "; for (i=1; i<=3; ++i){ oss.setf(ios::hex,ios::basefield); oss.width(4); oss.fill('0'); oss << group.GetWord(i) << " "; } break; case 4: tmc_provider[0]=group.GetByte(2,1); tmc_provider[1]=group.GetByte(2,0); tmc_provider[2]=group.GetByte(3,1); tmc_provider[3]=group.GetByte(3,0); oss << "provider=" << tmc_provider; break; case 5: tmc_provider[4]=group.GetByte(2,1); tmc_provider[5]=group.GetByte(2,0); tmc_provider[6]=group.GetByte(3,1); tmc_provider[7]=group.GetByte(3,0); oss << "provider=" << tmc_provider; break; case 6: case 7:; } break; case TMC_TUNING: oss << "T "; switch (CI){ case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: oss << "CI=" << CI << " "; for (i=1; i<=3; ++i){ oss.setf(ios::hex,ios::basefield); oss.width(4); oss.fill('0'); oss << group.GetWord(i) << " "; } } break; } if (add_string(oss.str())) is_changed = true; if (check_timeouts()) is_changed = true; } const string& TMClist::AsString() { ostringstream oss; list<TMCinfo>::iterator it; for (it=tmc_list.begin(); it != tmc_list.end(); ++it){ oss << (*it).data << endl; } list_string = oss.str(); return list_string; }
void listener_loop(void) { int i,n,addr; unsigned int sock_size; fd_set fds; struct timeval tv; char cmd[1024]; struct sockaddr_in sa; #ifdef __CYGWIN__ WORD verreq; WSADATA wsadata; #endif /* catch broken pipe ! */ #ifdef __SVR4 sigignore(SIGPIPE); sigset(SIGCHLD,cleanchild); #else signal(SIGPIPE,SIG_IGN); signal(SIGCHLD,cleanchild); #endif /* myip=getmyip(); if (myip==NULL) { printf("Determining localhost-IP failed.\n"); exit(1); } #ifdef DEBUG printf("My IP is: %d.%d.%d.%d\n", myip[0],myip[1],myip[2],myip[3]); #endif */ /* server init */ #ifdef __CYGWIN__ verreq=MAKEWORD(1,1); i=WSAStartup(verreq,&wsadata); if (i!=0) { printf("Error: winsock-lib couldn't be initialized."); } #endif if (!daemonmode) printf("Starting server ... "); if ((server_socket=socket(PF_INET,SOCK_STREAM,0))==INVALID_SOCKET) { #ifdef __CYGWIN__ i=WSAGetLastError(); #else i=errno; #endif printf("Error: could not create server socket (%d).\n",i); exit(1); } i=1; if (setsockopt(server_socket,SOL_SOCKET,SO_REUSEADDR,(void *)&i,sizeof(i))<0) printf("setsockopt failed.\n"); sock_size=sizeof(struct sockaddr_in); memset(&sa,0,sock_size); sa.sin_family=PF_INET; sa.sin_port=htons(serverport); addr=INADDR_ANY; memcpy(&sa.sin_addr.s_addr,&addr,sizeof(int)); if (bind(server_socket,(struct sockaddr *)&sa,sock_size)<0) { printf("Error: bind failed.\n"); printf(" port %i already in use ?\n",serverport); exit(1); } if (listen(server_socket,5)<0) { printf("Error: listen failed.\n"); exit(1); } if (!daemonmode) { printf("OK\n\n"); out_prompt(); } #ifdef DEBUG printf("Listening ...\n"); #endif serverstop=0; while (!serverstop) { FD_ZERO(&fds); if (!daemonmode) FD_SET(1,&fds); FD_SET(server_socket,&fds); for (i=0;i<maxusers;i++) if (pchild[i]->sock) FD_SET(pchild[i]->sock,&fds); /* memset(&tv,0,sizeof(struct timeval)); */ tv.tv_sec=REACTION_TIME;tv.tv_usec=0L; n=select(32+maxusers*4,&fds,NULL,NULL,&tv); if (n<0) { if (errno==EINTR) continue; if ( #ifdef __CYGWIN__ 1) { i=WSAGetLastError(); #else !daemonmode) { i=errno; #endif fprintf(stderr,"*** Fehler: select (ret: %d,errno=%d).\n",n,i); } exit(1); } if (!daemonmode) if (FD_ISSET(1,&fds)) { i=read(1,cmd,sizeof(cmd)); if (i<1) continue; cmd[i-1]=0; execcmd(cmd); if (serverstop) break; out_prompt(); } if (FD_ISSET(server_socket,&fds)) init_login(); for (i=0;i<maxusers;i++) { if (pchild[i]->sock) { if (FD_ISSET(pchild[i]->sock,&fds)) serve_child(i); } } check_timeouts(); } close(server_socket); #ifdef __CYGWIN__ WSACleanup(); #endif if (!daemonmode) printf("Server stopped.\n"); }