コード例 #1
0
static void clean_old_connections(request_rec *r) {
    upload_progress_node_t *prev = NULL;
    ServerConfig *config = get_server_config(r);
    CACHE_LOCK();
    upload_progress_node_t *node = fetch_first_node(config);
    while(node != NULL) {
        if(time(NULL) > node->expires && node->done == 1 && node->expires != -1) {
            /*clean*/
	    if(prev == NULL) {
		/* head */
		upload_progress_cache_t *cache = fetch_cache(config);
		cache->head = fetch_node(config, node->next);
		cache_free(config, node->key);
		cache_free(config, node);
		node = cache->head;
		continue;
	    } else {
		prev->next = node->next;
		cache_free(config, node->key);
		cache_free(config, node);
		node = prev;
		continue;
	    }
        }
	prev = node;
	node = fetch_node(config, node->next);
  }
  CACHE_UNLOCK();
}
コード例 #2
0
ファイル: cachemgr.c プロジェクト: cgroschupp/sslsplit
/*
 * Cleanup the caches and free all memory.  Since OpenSSL certificates are
 * being freed, this must be done before calling the OpenSSL cleanup methods.
 * Also, it is not safe to call this while cachemgr_gc() is still running.
 */
void
cachemgr_fini(void)
{
	cache_free(cachemgr_dsess);
	cache_free(cachemgr_ssess);
	cache_free(cachemgr_tgcrt);
	cache_free(cachemgr_fkcrt);
}
コード例 #3
0
ファイル: cyclon.c プロジェクト: HunterChen/GRAPES
static int cyclon_parse_data(struct peersampler_context *context, const uint8_t *buff, int len)
{
  cache_check(context->local_cache);
  if (len) {
    const struct topo_header *h = (const struct topo_header *)buff;
    struct peer_cache *remote_cache;
    struct peer_cache *sent_cache = NULL;

    if (h->protocol != MSG_TYPE_TOPOLOGY) {
      fprintf(stderr, "Peer Sampler: Wrong protocol!\n");

      return -1;
    }

    context->bootstrap = false;

    remote_cache = entries_undump(buff + sizeof(struct topo_header), len - sizeof(struct topo_header));
    if (h->type == CYCLON_QUERY) {
      sent_cache = rand_cache(context->local_cache, context->sent_entries);
      cyclon_reply(context->pc, remote_cache, sent_cache);
      context->dst = NULL;
    }
    cache_check(context->local_cache);
    cache_add_cache(context->local_cache, remote_cache);
    cache_free(remote_cache);
    if (sent_cache) {
      cache_add_cache(context->local_cache, sent_cache);
      cache_free(sent_cache);
    } else {
      if (context->flying_cache) {
        cache_add_cache(context->local_cache, context->flying_cache);
        cache_free(context->flying_cache);
        context->flying_cache = NULL;
      }
    }
  }

  if (time_to_send(context)) {
    if (context->flying_cache) {
      cache_add_cache(context->local_cache, context->flying_cache);
      cache_free(context->flying_cache);
      context->flying_cache = NULL;
    }
    cache_update(context->local_cache);
    context->dst = last_peer(context->local_cache);
    if (context->dst == NULL) {
      return 0;
    }
    context->dst = nodeid_dup(context->dst);
    cache_del(context->local_cache, context->dst);
    context->flying_cache = rand_cache(context->local_cache, context->sent_entries - 1);
    return cyclon_query(context->pc, context->flying_cache, context->dst);
  }
  cache_check(context->local_cache);

  return 0;
}
コード例 #4
0
ファイル: cache.c プロジェクト: yuyang0/yaspider
int main()
{
	cache_head_t cache;
	init_cache(&cache, 8);
	long long *data = cache_malloc(&cache);
	*data = 111111111;
	cache_free(&cache, data);
	data = cache_malloc(&cache);
	cache_free(&cache, data);
	return 0;
}
コード例 #5
0
void upload_progress_destroy_cache(ServerConfig *config) {
    upload_progress_cache_t *cache = fetch_cache(config);
    upload_progress_node_t *node, *temp;
   
    cache_free(config, cache);
    node = fetch_node(config, cache->head);
    while(node != NULL) {
      temp = fetch_node(config, node->next);
      
      cache_free(config, node);
      node = temp;
    }
}
コード例 #6
0
xconv_t *
xconv_free (xconv_t *xc) /*{{{*/
{
	if (xc) {
		if (xc -> lower)
			cache_free (xc -> lower);
		if (xc -> upper)
			cache_free (xc -> upper);
		if (xc -> title)
			cache_free (xc -> title);
		free (xc);
	}
	return NULL;
}/*}}}*/
コード例 #7
0
ファイル: testapp.c プロジェクト: bcui6611/moxi
static enum test_return cache_reuse_test(void)
{
    int ii;
    cache_t *cache = cache_create("test", sizeof(uint32_t), sizeof(char*),
                                  NULL, NULL);
    char *ptr = cache_alloc(cache);
    cache_free(cache, ptr);
    for (ii = 0; ii < 100; ++ii) {
        char *p = cache_alloc(cache);
        assert(p == ptr);
        cache_free(cache, ptr);
    }
    cache_destroy(cache);
    return TEST_PASS;
}
コード例 #8
0
int rdp_guac_client_free_handler(guac_client* client) {

    rdp_guac_client_data* guac_client_data =
        (rdp_guac_client_data*) client->data;

    freerdp* rdp_inst = guac_client_data->rdp_inst;
    rdpChannels* channels = rdp_inst->context->channels;

    /* Clean up RDP client */
	freerdp_channels_close(channels, rdp_inst);
	freerdp_channels_free(channels);
	freerdp_disconnect(rdp_inst);
    freerdp_clrconv_free(((rdp_freerdp_context*) rdp_inst->context)->clrconv);
    cache_free(rdp_inst->context->cache);
    freerdp_free(rdp_inst);

    /* Clean up filesystem, if allocated */
    if (guac_client_data->filesystem != NULL)
        guac_rdp_fs_free(guac_client_data->filesystem);

    /* Free SVC list */
    guac_common_list_free(guac_client_data->available_svc);

    /* Free client data */
    guac_common_clipboard_free(guac_client_data->clipboard);
    guac_common_surface_free(guac_client_data->default_surface);
    free(guac_client_data);

    return 0;

}
コード例 #9
0
ファイル: mod_mem_cache.c プロジェクト: Alivx/apache2nginx
static apr_status_t cleanup_cache_mem(void *sconfv)
{
    cache_object_t *obj;
    mem_cache_conf *co = (mem_cache_conf*) sconfv;

    if (!co) {
        return APR_SUCCESS;
    }
    if (!co->cache_cache) {
        return APR_SUCCESS;
    }

    if (sconf->lock) {
        apr_thread_mutex_lock(sconf->lock);
    }
    obj = cache_pop(co->cache_cache);
    while (obj) {
        /* Iterate over the cache and clean up each unreferenced entry */
        if (!apr_atomic_dec32(&obj->refcount)) {
            cleanup_cache_object(obj);
        }
        obj = cache_pop(co->cache_cache);
    }

    /* Cache is empty, free the cache table */
    cache_free(co->cache_cache);

    if (sconf->lock) {
        apr_thread_mutex_unlock(sconf->lock);
    }
    return APR_SUCCESS;
}
コード例 #10
0
ファイル: cache_stats.c プロジェクト: dpejesh/libsv-common
/* Perform various actions on a cache and check it's statistics. */
int main() {
  cache_t cache = CACHE_INIT;
  char *data;
  char *data1 = "data1";
  size_t dlen;
  uint8_t i;
  char *key1 = "key1";
  uint32_t ttl;
  
  if (!cache_init(&cache, 512))
    return 1;
    
  for (i = 1; i < UINT8_MAX; i++) {
    cache_set(&cache, key1, strlen(key1), data1, strlen(data1), CACHE_MAX_TTL);
  }
  
  cache_get(&cache, key1, strlen(key1), &dlen, &ttl);
  
  if (cache.stats.get != 1)
    return 2;
  if (cache.stats.set != 254)
    return 3;
  if (cache.stats.motion != (CACHE_HEADER_SIZE + 9) * cache.stats.set)
    return 4;
    
  cache_free(&cache);
  
  return 0;
}
コード例 #11
0
ファイル: wf_interface.c プロジェクト: akboom/FreeRDP
void wf_context_free(freerdp* instance, rdpContext* context)
{
	if (context->cache)
		cache_free(context->cache);

	freerdp_channels_free(context->channels);
}
コード例 #12
0
ファイル: cachetest.c プロジェクト: liei/ttk4145
main()
{
    CACHE *cache;
    char cmd[2];
    int val, *pval;

    /* Print some instructions. */
    printf("This program demonstrates the various cache manipulation\n");
    printf("routines supplied by this package.  Although this program\n");
    printf("manipulates a cache of integers, data of any type and size\n");
    printf("(and not just integers) are supported by the routines.  See\n");
    printf("the man page for more information.\n\n");
    printf("We illustrate a cache with a maximum size of 3 entries.\n\n");

    /* Allocate a new cache. */
    cache = cache_init(MAX_ELEMENTS);
    print_cache(cache);

    /* Get some commands. */
    printf("\n(e)nter new element, (c)heck for element; (q)uit: ");
    while (scanf("%1s", cmd) != EOF) {
        switch (cmd[0]) {
        case 'e':
            printf("Value (int) to enter: ");
            if (scanf("%d", &val)) {
                /* We ignore the return code here, but in practice,
                * we may fail (with a return code of NULL).
                */
                cache_enter(cache, &val, sizeof(val), &pval);
                if (pval != NULL) {
                    printf("%d was removed to make room.\n", *pval);
                }
            }
            break;
        case 'c':
            printf("Value (int) to check for: ");
            if (scanf("%d", &val)) {
                pval = (int *) cache_check(cache, (char *) &val, match);
                if (pval != NULL) {
                    printf("%d found!\n", *pval);
                }
                else {
                    printf("Not found.\n");
                }
            }
            break;
        case 'q':
            cache_free(cache, CACHE_DEALLOC);
            exit(0);
            break;
        default:
            printf("'%s' not a recognized command!\n", cmd);
            break;
        }
        print_cache(cache);
        printf("\n(e)nter new element, (c)heck for element; (q)uit: ");
    }

    exit(0);
}
コード例 #13
0
ファイル: mevent_aic.c プロジェクト: kingiol/cmoon
static struct event_entry* aic_init_driver(void)
{
    struct aic_entry *e = calloc(1, sizeof(struct aic_entry));
    if (e == NULL) return NULL;
    NEOERR *err;

    e->base.name = (unsigned char*)strdup(PLUGIN_NAME);
    e->base.ksize = strlen(PLUGIN_NAME);
    e->base.process_driver = aic_process_driver;
    e->base.stop_driver = aic_stop_driver;

    char *dbsn = hdf_get_value(g_cfg, CONFIG_PATH".dbsn", NULL);
    err = mdb_init(&e->db, dbsn);
    JUMP_NOK(err, error);
    
    e->cd = cache_create(hdf_get_int_value(g_cfg, CONFIG_PATH".numobjs", 1024), 0);
    if (e->cd == NULL) {
        wlog("init cache failure");
        goto error;
    }
    
    return (struct event_entry*)e;
    
error:
    if (e->base.name) free(e->base.name);
    if (e->db) mdb_destroy(e->db);
    if (e->cd) cache_free(e->cd);
    free(e);
    return NULL;
}
コード例 #14
0
ファイル: encoder.c プロジェクト: csdanping/gstreamill
static GstFlowReturn new_sample_callback (GstAppSink * sink, gpointer user_data)
{
        GstBuffer *buffer;
        GstSample *sample;
        Encoder *encoder = (Encoder *)user_data;

        *(encoder->output->heartbeat) = gst_clock_get_time (encoder->system_clock);
        sample = gst_app_sink_pull_sample (GST_APP_SINK (sink));
        buffer = gst_sample_get_buffer (sample);

        sem_wait (encoder->output->semaphore);

        (*(encoder->output->total_count)) += gst_buffer_get_size (buffer);

        /* update head_addr, free enough memory for current buffer. */
        while (cache_free (encoder) < gst_buffer_get_size (buffer) + 12) { /* timestamp + gop size = 12 */
                move_head (encoder);
        }

        if (!GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT)) {
                /* 
                 * random access point found.
                 * write previous gop size to 4 bytes reservation,
                 * write current gop timestamp,
                 * reserve 4 bytes for size of current gop,
                 */
                if (encoder->mqdes == -1) {
                        /* no m3u8 output */
                        move_last_rap (encoder, buffer);

                } else if (GST_BUFFER_PTS (buffer) == encoder->last_running_time) {
                        gchar *msg;

                        move_last_rap (encoder, buffer);
                        msg = g_strdup_printf ("%lu", encoder->last_segment_duration);
                        if (mq_send (encoder->mqdes, msg, strlen (msg), 1) == -1) {
                                GST_ERROR ("mq_send error: %s", g_strerror (errno));
                        }
                        g_free (msg);
                        encoder->last_running_time = GST_CLOCK_TIME_NONE;
                }
        }

        /* udpstreaming? */
        if (encoder->udpstreaming) {
                udp_streaming (encoder, buffer);
        }

        /*
         * copy buffer to cache.
         * update tail_addr
         */
        copy_buffer (encoder, buffer);

        sem_post (encoder->output->semaphore);

        gst_sample_unref (sample);

        return GST_FLOW_OK;
}
コード例 #15
0
ファイル: mc_connection.c プロジェクト: AllenDou/twemcache
void
conn_cleanup(struct conn *c)
{
    ASSERT(c != NULL);

    if (c->item != NULL) {
        item_remove(c->item);
        c->item = NULL;
    }

    while (c->ileft > 0) {
        item_remove(*(c->icurr));
        c->ileft--;
        c->icurr++;
    }

    while (c->sleft > 0) {
        cache_free(c->thread->suffix_cache, *(c->scurr));
        c->sleft--;
        c->scurr++;
    }

    if (c->write_and_free != NULL) {
        mc_free(c->write_and_free);
    }
}
コード例 #16
0
ファイル: mevent_skeleton.c プロジェクト: adderly/cmoon
static EventEntry* skeleton_init_driver(void)
{
    struct skeleton_entry *e = calloc(1, sizeof(struct skeleton_entry));
    if (e == NULL) return NULL;
    NEOERR *err;

    e->base.name = (unsigned char*)strdup(PLUGIN_NAME);
    e->base.ksize = strlen(PLUGIN_NAME);
    e->base.process_driver = skeleton_process_driver;
    e->base.stop_driver = skeleton_stop_driver;
    //mevent_add_timer(&e->base.timers, 60, true, hint_timer_up_term);

    //char *s = hdf_get_value(g_cfg, CONFIG_PATH".dbsn", NULL);
    //err = mdb_init(&e->db, s);
    //JUMP_NOK(err, error);
    
    e->cd = cache_create(hdf_get_int_value(g_cfg, CONFIG_PATH".numobjs", 1024), 0);
    if (e->cd == NULL) {
        wlog("init cache failure");
        goto error;
    }
    
    return (EventEntry*)e;
    
error:
    if (e->base.name) free(e->base.name);
    if (e->db) mdb_destroy(e->db);
    if (e->cd) cache_free(e->cd);
    free(e);
    return NULL;
}
コード例 #17
0
ファイル: db.c プロジェクト: yqingp/testness
void env_close(struct env *e)
{
	cache_free(e->cache);
	status_free(e->status);
	txnmgr_free(e->txnmgr);
	xfree(e->dir);
	xfree(e);
}
コード例 #18
0
ファイル: cache.c プロジェクト: Hexasoft/WebFS
/* destroy a cache */
int cache_destroy(const char *file) {
  Cache *tmp;
  
  tmp = cache_search(file);
  if (tmp == NULL)
    return(0);
  cache_free(tmp);
  return(1);
}
コード例 #19
0
ファイル: kpathsea.c プロジェクト: QQ1350995917/pdftex.js
/* Sadly, quite a lot of the freeing is not safe:
   it seems there are literals used all over. */
void
kpathsea_finish (kpathsea kpse)
{
#if KPATHSEA_CAN_FREE
    int i;
    kpse_format_info_type f;
#endif /* KPATHSEA_CAN_FREE */
    if (kpse==NULL)
        return;
#if KPATHSEA_CAN_FREE
    /* free internal stuff */
    hash_free (kpse->cnf_hash);
    hash_free (kpse->db);
    hash_free (kpse->alias_db);
    str_list_free(&kpse->db_dir_list);
    hash_free (kpse->link_table);
    cache_free (kpse->the_cache, kpse->cache_length);
    hash_free (kpse->map);
    string_free (kpse->map_path);
    string_free (kpse->elt);
    /*string_free (kpse->path);*/
    if (kpse->log_file != (FILE *)NULL)
        fclose(kpse->log_file);
    string_free (kpse->invocation_name);
    string_free (kpse->invocation_short_name);
    string_free (kpse->program_name);
    string_free (kpse->fallback_font);
    string_free (kpse->fallback_resolutions_string);
    if(kpse->fallback_resolutions != NULL)
        free(kpse->fallback_resolutions);
    for (i = 0; i != kpse_last_format; ++i) {
        f = kpse->format_info[i];
        /*string_free ((string)f.path);*/
        string_free ((string)f.override_path);
        string_free ((string)f.client_path);
        /*string_free ((string)f.cnf_path);*/
    }

    if (kpse->missfont != (FILE *)NULL)
        fclose(kpse->missfont);

    for (i = 0; i < (int)kpse->expansion_len; i++) {
        string_free (kpse->expansions[i].var);
    }
    free (kpse->expansions);
    if (kpse->saved_env!=NULL) {
        for (i = 0; i != kpse->saved_count; ++i)
            string_free (kpse->saved_env[i]);
        free (kpse->saved_env);
    }
#if defined(WIN32) || defined(__MINGW32__) || defined(__CYGWIN__)
    if (kpse->suffixlist != NULL) {
        char **p;
        for p = kpse->suffixlist; *p; p++)
            free (*p);
        free (kpse->suffixlist);
    }
コード例 #20
0
ファイル: mevent_skeleton.c プロジェクト: adderly/cmoon
static void skeleton_stop_driver(EventEntry *entry)
{
    struct skeleton_entry *e = (struct skeleton_entry*)entry;

    /*
     * e->base.name, e->base will free by mevent_stop_driver() 
     */
    mdb_destroy(e->db);
    cache_free(e->cd);
}
コード例 #21
0
ファイル: mevent_aic.c プロジェクト: kingiol/cmoon
static void aic_stop_driver(struct event_entry *entry)
{
    struct aic_entry *e = (struct aic_entry*)entry;

    /*
     * e->base.name, e->base will free by mevent_stop_driver() 
     */
    mdb_destroy(e->db);
    cache_free(e->cd);
}
コード例 #22
0
ファイル: cache.c プロジェクト: Hexasoft/WebFS
/* cache cleanup (final, no rescue) */
int cache_fini() {
  int i;
  
  mylog("cache_fini()\n");
  for(i=0; i<CACHE_MAX; i++) {
    cache_free(&(caches[i]));
  }

  return(1);
}
コード例 #23
0
ファイル: rlm_cache.c プロジェクト: geaaru/freeradius-server
/** Find a cached entry.
 *
 * @return
 *	- #RLM_MODULE_OK on cache hit.
 *	- #RLM_MODULE_FAIL on failure.
 *	- #RLM_MODULE_NOTFOUND on cache miss.
 */
static rlm_rcode_t cache_find(rlm_cache_entry_t **out, rlm_cache_t const *inst, REQUEST *request,
			      rlm_cache_handle_t **handle, uint8_t const *key, size_t key_len)
{
	cache_status_t ret;

	rlm_cache_entry_t *c;

	*out = NULL;

	for (;;) {
		ret = inst->driver->find(&c, &inst->config, inst->driver_inst->data, request, *handle, key, key_len);
		switch (ret) {
		case CACHE_RECONNECT:
			RDEBUG2("Reconnecting...");
			if (cache_reconnect(handle, inst, request) == 0) continue;
			return RLM_MODULE_FAIL;

		case CACHE_OK:
			break;

		case CACHE_MISS:
			RDEBUG2("No cache entry found for \"%pV\"", fr_box_strvalue_len((char const *)key, key_len));
			return RLM_MODULE_NOTFOUND;

		/* FALL-THROUGH */
		default:
			return RLM_MODULE_FAIL;

		}

		break;
	}

	/*
	 *	Yes, but it expired, OR the "forget all" epoch has
	 *	passed.  Delete it, and pretend it doesn't exist.
	 */
	if ((c->expires < request->packet->timestamp.tv_sec) || (c->created < inst->config.epoch)) {
		RDEBUG2("Found entry for \"%pV\", but it expired %li seconds ago.  Removing it",
			fr_box_strvalue_len((char const *)key, key_len),
			request->packet->timestamp.tv_sec - c->expires);

		inst->driver->expire(&inst->config, inst->driver_inst->data, request, handle, c->key, c->key_len);
		cache_free(inst, &c);
		return RLM_MODULE_NOTFOUND;	/* Couldn't find a non-expired entry */
	}

	RDEBUG2("Found entry for \"%pV\"", fr_box_strvalue_len((char const *)key, key_len));

	c->hits++;
	*out = c;

	return RLM_MODULE_OK;
}
コード例 #24
0
ファイル: cache.c プロジェクト: Hexasoft/WebFS
/* create a new cache for given file.
   returns true if created, false else
   can destroy an other one if no place available */
Cache *cache_create(const char *file, unsigned int size) {
  int i;
  Cache *tmp=NULL;
  
  mylog("cache_create(%s, %u)\n", file, size);
  /* search a free cache */
  for(i=0; i<CACHE_MAX; i++) {
    if (caches[i].name == NULL) {
      tmp = &(caches[i]);
      break;
    }
  }
  if (tmp == NULL) {
    /* not found. destroy the oldest cache */
    tmp = cache_oldest();
    if (tmp == NULL) {
      /* should not occur */
      return(NULL);
    }
  }
  /* initialise common cache data */
  tmp->name = strdup(file);
  tmp->created = tmp->last_use = (unsigned int)time(NULL);
  tmp->firstblock = NULL;
  for(i=0; i<CACHE_MAX_CHUNK; i++)
    tmp->chunks[i] = NULL;
  tmp->size = size;
  
  /* alocate 'firstblock' to cache_chunksize or size
     if smaller (for dl at 'connect') */
  tmp->firstblock = malloc(MIN(cache_chunksize, size));
  if (tmp->firstblock != NULL) {
     tmp->firstblocksize = MIN(cache_chunksize, size);
  }
  /* just ignore if failed (NULL) as in this case
     fistblock will be ignored */
  
  /* creation connection for this file */
  
  mylog("cache_create: connextion cache %p (cnx=%p)\n", tmp, &(tmp->connection));
  if (!cache_connect(&(tmp->connection), file,
          url_path, tmp->firstblock, MIN(cache_chunksize, size))) {
    /* destroy this cache... */
    cache_free(tmp);
    return(NULL);
  }
  
  mylog("cache_create: %p->connection = { %s, %d, %p, %d}\n", tmp,
    tmp->connection.target, tmp->connection.type,
    tmp->connection.data, tmp->connection.idata);
  
  /* ok */
  return(tmp);
}
コード例 #25
0
ファイル: moc_base.c プロジェクト: bigclean/moc
static void base_stop_driver(EventEntry *entry)
{
    struct base_entry *e = (struct base_entry*)entry;

    /*
     * e->base.name, e->base will free by moc_stop_driver() 
     */
    mdb_destroy(e->db);
    cache_free(e->cd);
    base_info_destroy(m_base);
}
コード例 #26
0
void *cuda_make_ctx(CUcontext ctx, int flags) {
  int64_t v = 0;
  cuda_context *res;
  int e = 0;

  res = malloc(sizeof(*res));
  if (res == NULL)
    return NULL;
  res->ctx = ctx;
  res->err = CUDA_SUCCESS;
  res->blas_handle = NULL;
  res->refcnt = 1;
  res->flags = flags;
  res->enter = 0;
  if (detect_arch(ARCH_PREFIX, res->bin_id, &err)) {
    free(res);
    return NULL;
  }
  res->extcopy_cache = cache_alloc(64, 32);
  if (res->extcopy_cache == NULL) {
    free(res);
    return NULL;
  }
  err = cuStreamCreate(&res->s, 0);
  if (err != CUDA_SUCCESS) {
    cache_free(res->extcopy_cache);
    free(res);
    return NULL;
  }
  TAG_CTX(res); /* Need to tag before cuda_alloc */
  res->errbuf = cuda_alloc(res, 8, &v, GA_BUFFER_INIT, &e);
  if (e != GA_NO_ERROR) {
    err = res->err;
    cache_free(res->extcopy_cache);
    cuStreamDestroy(res->s);
    free(res);
    return NULL;
  }
  res->refcnt--; /* Don't want to create a reference loop with the errbuf */
  return res;
}
コード例 #27
0
ファイル: ncast_proto.c プロジェクト: lucabe72/GRAPES
int ncast_reply(struct ncast_proto_context *context, const struct peer_cache *c, const struct peer_cache *local_cache)
{
  int ret;
  struct peer_cache *send_cache;

  send_cache = cache_copy(local_cache);
  cache_update(send_cache);
  ret = topo_reply(context->context, c, send_cache, MSG_TYPE_TOPOLOGY, NCAST_REPLY, 0, 1);
  cache_free(send_cache);

  return ret;
}
コード例 #28
0
ファイル: lfs_ops.c プロジェクト: shenyan1/aiofs
static void __op_evict (struct __arc_object *e)
{
    struct object *obj = __arc_list_entry (e, struct object, entry);
#ifndef CONFIG_SHMEM
    cache_free (lfs_n.lfs_cache, obj->obj_data);
    e->read_state = 10;
#else
    e->read_state = 10;
    cache_free_shm (lfs_n.lfs_cache, obj->obj_data);
#endif
    lfs_printf ("evict happend!\n");
}
コード例 #29
0
/** Find a cached entry.
 *
 * @return RLM_MODULE_OK on success, RLM_MODULE_FAIL on failure, RLM_MODULE_NOTFOUND if notfound.
 */
static rlm_rcode_t cache_find(rlm_cache_entry_t **out, rlm_cache_t *inst, REQUEST *request,
			      rlm_cache_handle_t **handle, char const *key)
{
	cache_status_t ret;

	rlm_cache_entry_t *c;

	*out = NULL;

	for (;;) {
		ret = inst->module->find(&c, inst, request, handle, key);
		switch (ret) {
		case CACHE_RECONNECT:
			RDEBUG("Reconnecting...");
			if (cache_reconnect(inst, request, handle) == 0) continue;
			return RLM_MODULE_FAIL;

		case CACHE_OK:
			break;

		case CACHE_MISS:
			RDEBUG("No cache entry found for \"%s\"", key);
			return RLM_MODULE_NOTFOUND;

		/* FALL-THROUGH */
		default:
			return RLM_MODULE_FAIL;

		}

		break;
	}

	/*
	 *	Yes, but it expired, OR the "forget all" epoch has
	 *	passed.  Delete it, and pretend it doesn't exist.
	 */
	if ((c->expires < request->timestamp) || (c->created < inst->epoch)) {
		RDEBUG("Removing expired entry");

		inst->module->expire(inst, request, handle, c);
		cache_free(inst, &c);
		return RLM_MODULE_NOTFOUND;	/* Couldn't find a non-expired entry */
	}

	RDEBUG("Found entry for \"%s\"", key);

	c->hits++;
	*out = c;

	return RLM_MODULE_OK;
}
コード例 #30
0
ファイル: testapp.c プロジェクト: bcui6611/moxi
static enum test_return cache_destructor_test(void)
{
    cache_t *cache = cache_create("test", sizeof(uint32_t), sizeof(char*),
                                  NULL, cache_destructor);
    char *ptr;

    assert(cache != NULL);
    ptr = cache_alloc(cache);
    cache_free(cache, ptr);
    cache_destroy(cache);

    return (ptr == destruct_data) ? TEST_PASS : TEST_FAIL;
}