void NetBalanceGetter::run(){ QNetworkAccessManager mng; manager = &mng; while(true){ QThread::sleep(wait_time); if(!login_cabinet()) continue; if(!get_cabinet_page()) continue; if(!get_timeleft()) continue; if(!unlogin_cabinet()) continue; } }
static void purge(h2o_cache_t *cache, uint64_t now) { /* by cache size */ while (cache->capacity < cache->size) { h2o_cache_ref_t *last; assert(!h2o_linklist_is_empty(&cache->lru)); last = H2O_STRUCT_FROM_MEMBER(h2o_cache_ref_t, _lru_link, cache->lru.next); erase_ref(cache, kh_get(cache, cache->table, last), 0); } /* by TTL */ while (!h2o_linklist_is_empty(&cache->age)) { h2o_cache_ref_t *oldest = H2O_STRUCT_FROM_MEMBER(h2o_cache_ref_t, _age_link, cache->age.next); if (get_timeleft(cache, oldest, now) >= 0) break; erase_ref(cache, kh_get(cache, cache->table, oldest), 0); } }
h2o_cache_ref_t *h2o_cache_fetch(h2o_cache_t *cache, uint64_t now, h2o_iovec_t key, h2o_cache_hashcode_t keyhash) { h2o_cache_ref_t search_key, *ref; khiter_t iter; int64_t timeleft; if (keyhash == 0) keyhash = h2o_cache_calchash(key.base, key.len); search_key.key = key; search_key.keyhash = keyhash; lock_cache(cache); purge(cache, now); if ((iter = kh_get(cache, cache->table, &search_key)) == kh_end(cache->table)) goto NotFound; /* found */ ref = kh_key(cache->table, iter); timeleft = get_timeleft(cache, ref, now); if (timeleft < 0) goto NotFound; if ((cache->flags & H2O_CACHE_FLAG_EARLY_UPDATE) != 0 && timeleft < 10 && !ref->_requested_early_update) { ref->_requested_early_update = 1; goto NotFound; } /* move the entry to the top of LRU */ h2o_linklist_unlink(&ref->_lru_link); h2o_linklist_insert(&cache->lru, &ref->_lru_link); __sync_fetch_and_add(&ref->_refcnt, 1); /* unlock and return the found entry */ unlock_cache(cache); return ref; NotFound: unlock_cache(cache); return NULL; }
bool started() const { return period != 0 && get_timeleft() > 0; }