本文整理汇总了C++中cache_insert函数的典型用法代码示例。如果您正苦于以下问题:C++ cache_insert函数的具体用法?C++ cache_insert怎么用?C++ cache_insert使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cache_insert函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: do_server_request
static void
do_server_request(struct server *sv, int connfd)
{
int ret;
struct request *rq;
struct file_data *data;
data = file_data_init();
rq = request_init(connfd, data);
if (!rq) {
file_data_free(data);
return;
}
if(cache_active ==1){
pthread_mutex_lock( &conditionMutex);
struct hash_node *cache_stored;
cache_stored= cache_lookup(data->file_name);
if(cache_stored!=NULL){ // check if it populated in the cache{
data->file_buf = Malloc(cache_stored->data->file_size);
strncpy(data->file_buf, cache_stored->data->file_buf, cache_stored->data->file_size);
data->file_size =cache_stored->data->file_size;
}
else{
/* reads file,
* fills data->file_buf with the file contents,
* data->file_size with file size. */
pthread_mutex_unlock( &conditionMutex );
ret = request_readfile(rq);
pthread_mutex_lock( &conditionMutex );
// need to renew the cache
if(data->file_size<max_cache){
if(data->file_size <=(max_cache-cache_current_size) ){
cache_insert(data);
}
else{
cache_evict(data->file_size);
cache_insert(data);
}
}
}
pthread_mutex_unlock( &conditionMutex );
}
else{
ret = request_readfile(rq);
if (!ret)
goto out;
}
/* sends file to client */
request_sendfile(rq);
out:
request_destroy(rq);
file_data_free(data);
}
开发者ID:miki2112,项目名称:multi_threaded_web_server,代码行数:57,代码来源:server_thread.c
示例2: update_block_list
int
update_block_list(char *addr, int err_level)
{
size_t addr_len = strlen(addr);
if (cache_key_exist(block_list, addr, addr_len)) {
int *count = NULL;
cache_lookup(block_list, addr, addr_len, &count);
if (count != NULL) {
if (*count > MAX_TRIES)
return 1;
(*count) += err_level;
}
} else if (err_level > 0) {
int *count = (int *)ss_malloc(sizeof(int));
*count = 1;
cache_insert(block_list, addr, addr_len, count);
#ifdef __linux__
if (mode != NO_FIREWALL_MODE)
set_firewall_rule(addr, 1);
#endif
}
return 0;
}
开发者ID:ss-plus,项目名称:shadowsocksR-libev,代码行数:25,代码来源:acl.c
示例3: cache_insert
void memory_c::fill_queue()
{
/* For Lab #2, you need to fill out this function */
/* CAUTION!: This function is not completed. Please complete this function */
if (dram_out_queue.empty())
return;
dram_out_queue.sort();
mem_req_s *req = dram_out_queue.front();
dram_out_queue.pop_front();
/* insert into cache */
cache_insert(data_cache,req->m_addr);
/* search for matching mshr entry */
m_mshr_entry_s *entry = search_matching_mshr(req->m_addr);
while(entry->req_ops.size())
{
Op *w_op = entry->req_ops.front();
broadcast_rdy_op(w_op);
entry->req_ops.pop_front();
}
/* The following code will free mshr entry */
list<m_mshr_entry_s *>::iterator mii = search_matching_mshr_itr(req->m_addr);
m_mshr.erase(mii);
free_mshr_entry(entry);
}
开发者ID:rvbelapure,项目名称:comparch,代码行数:34,代码来源:memory.cpp
示例4: l2_cache_fill
void l2_cache_fill(int cpu_num, unsigned long long int addr, int set, int way, int prefetch, unsigned long long int evicted_addr)
{
// uncomment this line to see the information available to you when there is a cache fill event
//printf("0x%llx %d %d %d 0x%llx\n", addr, set, way, prefetch, evicted_addr);
cache_insert(addr, prefetch);
if (prefetch==1) {
prefetch_tot_num++;
// Insert Evicted address into pollution filter
// only if it is not prefetch
int found = cache_search(evicted_addr);
if (found == -1) {
if (evicted_addr != 0) {
printf("ERROR: evicted address not in the cache - %llx \n", evicted_addr);
exit(1);
}
}
else
if (cache[found].pf != 1)
poll_insert(evicted_addr);
poll_remove(addr);
}
cache_remove(evicted_addr);
}
开发者ID:ramyadhadidi,项目名称:DPC2,代码行数:30,代码来源:ampmE__prefetcher.c
示例5: gss_OID_loc_to_sap
/*
* When the local GSS-API library returns a single OID to the caller,
* this gss_OID is assumed to be a pointer to stable storage, and need
* not be freed by the caller. We cannot return this structure directly
* to the caller, since it is in the incorrect ABI. (Neither can we
* modify that stable storage directly, as it would break internal users
* of the OID, violate the hosts alignment expectations, attempt a write
* to immutable storage, or other bad things.) We must return a translated
* copy instead. However, to retain the "caller does not free" property,
* we must cache the values we hand out, and only ever allocate one OID
* structure in the SAP ABI for any given OID.
*
* Returns 0 on success, and errno on failure.
*/
static int
gss_OID_loc_to_sap(gss_OID loc, sapgss_OID *sap)
{
sapgss_OID s;
int code;
if (sap == NULL)
return 0;
if (loc == NULL) {
*sap = NULL;
return 0;
}
/* Try to find a cached copy to use. */
s = cache_lookup(loc);
if (s != NULL) {
*sap = s;
return 0;
} /* else */
/* Try to insert it into the cache. Success here means that the next
* lookup will succeed. */
code = cache_insert(loc);
if (code != 0) {
*sap = NULL;
return code;
}
*sap = cache_lookup(loc);
return 0;
}
开发者ID:Aribaaa,项目名称:osxsnc,代码行数:44,代码来源:sncgss.c
示例6: dri_getdata
/*
* load dri data
* type: data type
* no : file no ( >= 0 )
* return: loaded dridata object
*/
dridata *ald_getdata(DRIFILETYPE type, int no) {
dridata *ddata;
/* check wrong request number */
if (no < 0) return NULL;
/* check wrong type */
if (type >= DRIFILETYPEMAX) return NULL;
/* check uninitilized data */
if (dri[type] == NULL) return NULL;
/* if mmapped */
if (dri[type]->mmapped) return dri_getdata(dri[type], no);
/* not mmapped */
if (NULL == (ddata = (dridata *)cache_foreach(cacheid, (type << 16) + no))) {
ddata = dri_getdata(dri[type], no);
if (ddata != NULL) {
cache_insert(cacheid, (type << 16) + no, (void *)ddata, ddata->size, &(ddata->in_use));
ddata->in_use = TRUE;
}
}
return ddata;
}
开发者ID:avan06,项目名称:ONScripter-CN,代码行数:32,代码来源:ald_manager.c
示例7: save_xbzrle_page
static int save_xbzrle_page(QEMUFile *f, uint8_t **current_data,
ram_addr_t current_addr, RAMBlock *block,
ram_addr_t offset, int cont, bool last_stage)
{
int encoded_len = 0, bytes_sent = -1;
uint8_t *prev_cached_page;
if (!cache_is_cached(XBZRLE.cache, current_addr)) {
acct_info.xbzrle_cache_miss++;
if (!last_stage) {
if (cache_insert(XBZRLE.cache, current_addr, *current_data) == -1) {
return -1;
} else {
/* update *current_data when the page has been
inserted into cache */
*current_data = get_cached_data(XBZRLE.cache, current_addr);
}
}
return -1;
}
prev_cached_page = get_cached_data(XBZRLE.cache, current_addr);
/* save current buffer into memory */
memcpy(XBZRLE.current_buf, *current_data, TARGET_PAGE_SIZE);
/* XBZRLE encoding (if there is no overflow) */
encoded_len = xbzrle_encode_buffer(prev_cached_page, XBZRLE.current_buf,
TARGET_PAGE_SIZE, XBZRLE.encoded_buf,
TARGET_PAGE_SIZE);
if (encoded_len == 0) {
DPRINTF("Skipping unmodified page\n");
return 0;
} else if (encoded_len == -1) {
DPRINTF("Overflow\n");
acct_info.xbzrle_overflows++;
/* update data in the cache */
if (!last_stage) {
memcpy(prev_cached_page, *current_data, TARGET_PAGE_SIZE);
*current_data = prev_cached_page;
}
return -1;
}
/* we need to update the data in the cache, in order to get the same data */
if (!last_stage) {
memcpy(prev_cached_page, XBZRLE.current_buf, TARGET_PAGE_SIZE);
}
/* Send XBZRLE based compressed page */
bytes_sent = save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_XBZRLE);
qemu_put_byte(f, ENCODING_FLAG_XBZRLE);
qemu_put_be16(f, encoded_len);
qemu_put_buffer(f, XBZRLE.encoded_buf, encoded_len);
bytes_sent += encoded_len + 1 + 2;
acct_info.xbzrle_pages++;
acct_info.xbzrle_bytes += bytes_sent;
return bytes_sent;
}
开发者ID:DrCheadar,项目名称:orp,代码行数:60,代码来源:arch_init.c
示例8: client_recv_cb
static void
client_recv_cb(uv_udp_t *handle, ssize_t nread, const uv_buf_t *buf, const struct sockaddr *addr, unsigned flags) {
struct server_context *server = container_of(handle, struct server_context, udp);
if (nread > 0) {
char key[KEY_BYTES + 1] = {0};
crypto_generickey((uint8_t *)key, sizeof(key) -1, (uint8_t*)addr, sizeof(*addr), NULL, 0);
struct client_context *client = NULL;
uv_mutex_lock(&mutex);
cache_lookup(cache, key, (void *)&client);
uv_mutex_unlock(&mutex);
if (client == NULL) {
client = new_client();
client->addr = *addr;
client->local_handle = handle;
memcpy(client->key, key, sizeof(key));
uv_timer_init(handle->loop, client->timer);
uv_udp_init(handle->loop, &client->server_handle);
client->server_handle.data = client;
uv_udp_recv_start(&client->server_handle, server_alloc_cb, server_recv_cb);
uv_mutex_lock(&mutex);
cache_insert(cache, client->key, (void *)client);
uv_mutex_unlock(&mutex);
}
int clen = nread + PRIMITIVE_BYTES + addrlen;
int mlen = nread + addrlen;
uint8_t *c = (uint8_t *)buf->base - PRIMITIVE_BYTES - addrlen;
uint8_t *m = (uint8_t *)buf->base - addrlen;
if (server->dest_addr->sa_family == AF_INET) {
struct sockaddr_in *addr = (struct sockaddr_in *)server->dest_addr;
m[0] = 1;
memcpy(m + 1, &addr->sin_addr, 4);
memcpy(m + 1 + 4, &addr->sin_port, 2);
} else {
struct sockaddr_in6 *addr = (struct sockaddr_in6 *)server->dest_addr;
m[0] = 4;
memcpy(m + 1, &addr->sin6_addr, 16);
memcpy(m + 1 + 16, &addr->sin6_port, 2);
}
int rc = crypto_encrypt(c, m, mlen);
if (!rc) {
reset_timer(client);
forward_to_server(server->server_addr, client, c, clen);
}
} else {
goto error;
}
return;
error:
free(buf->base - addrlen - PRIMITIVE_BYTES);
}
开发者ID:sinme,项目名称:xsocks-1,代码行数:58,代码来源:xforwarder_udprelay.c
示例9: cache_write
void cache_write(cache_m *scheduler, cache_n *node)
{
web_P(&scheduler->w);
while (scheduler->total_size + node->size > MAX_CACHE_SIZE) {
cache_remove(scheduler, scheduler->head.prev);
}
cache_insert(scheduler, node);
web_V(&scheduler->w);
}
开发者ID:doublequan,项目名称:CSAPP,代码行数:9,代码来源:cache.c
示例10: cache_resize
int64_t cache_resize(PageCache *cache, int64_t new_num_pages)
{
PageCache *new_cache;
int64_t i;
CacheItem *old_it, *new_it;
g_assert(cache);
/* cache was not inited */
if (cache->page_cache == NULL) {
return -1;
}
/* same size */
if (pow2floor(new_num_pages) == cache->max_num_items) {
return cache->max_num_items;
}
new_cache = cache_init(new_num_pages, cache->page_size);
if (!(new_cache)) {
DPRINTF("Error creating new cache\n");
return -1;
}
/* move all data from old cache */
for (i = 0; i < cache->max_num_items; i++) {
old_it = &cache->page_cache[i];
if (old_it->it_addr != -1) {
/* check for collision, if there is, keep MRU page */
new_it = cache_get_by_addr(new_cache, old_it->it_addr);
if (new_it->it_data) {
/* keep the MRU page */
if (new_it->it_age >= old_it->it_age) {
g_free(old_it->it_data);
} else {
g_free(new_it->it_data);
new_it->it_data = old_it->it_data;
new_it->it_age = old_it->it_age;
new_it->it_addr = old_it->it_addr;
}
} else {
cache_insert(new_cache, old_it->it_addr, old_it->it_data);
}
}
}
g_free(cache->page_cache);
cache->page_cache = new_cache->page_cache;
cache->max_num_items = new_cache->max_num_items;
cache->num_items = new_cache->num_items;
g_free(new_cache);
return cache->max_num_items;
}
开发者ID:sartakov,项目名称:nv-qemu,代码行数:56,代码来源:page_cache.c
示例11: xbzrle_cache_zero_page
/* Update the xbzrle cache to reflect a page that's been sent as all 0.
* The important thing is that a stale (not-yet-0'd) page be replaced
* by the new data.
* As a bonus, if the page wasn't in the cache it gets added so that
* when a small write is made into the 0'd page it gets XBZRLE sent
*/
static void xbzrle_cache_zero_page(ram_addr_t current_addr)
{
if (ram_bulk_stage || !migrate_use_xbzrle()) {
return;
}
/* We don't care if this fails to allocate a new cache page
* as long as it updated an old one */
cache_insert(XBZRLE.cache, current_addr, ZERO_TARGET_PAGE);
}
开发者ID:Annovae,项目名称:qemu,代码行数:16,代码来源:arch_init.c
示例12: idmap_lookup_group
static int idmap_lookup_group(
struct idmap_context *context,
const struct idmap_lookup *lookup,
struct idmap_group *group)
{
PCHAR* values[NUM_ATTRIBUTES] = { NULL };
const unsigned attributes = ATTR_FLAG(ATTR_GROUP_NAME)
| ATTR_FLAG(ATTR_GID);
int i, status;
/* check the group cache for an existing entry */
status = cache_lookup(&context->groups, lookup, &group->entry);
if (status == NO_ERROR) {
/* don't return expired entries; query new attributes
* and overwrite the entry with cache_insert() */
if (time(NULL) - group->last_updated < context->config.cache_ttl)
goto out;
}
/* send the query to the ldap server */
status = idmap_query_attrs(context, lookup,
attributes, 0, values, NUM_ATTRIBUTES);
if (status)
goto out_free_values;
/* parse attributes */
if (FAILED(StringCchCopyA(group->name, VAL_LEN,
*values[ATTR_GROUP_NAME]))) {
eprintf("ldap attribute %s='%s' longer than %u characters\n",
context->config.attributes[ATTR_GROUP_NAME],
*values[ATTR_GROUP_NAME], VAL_LEN);
status = ERROR_BUFFER_OVERFLOW;
goto out_free_values;
}
if (!parse_uint(*values[ATTR_GID], &group->gid)) {
eprintf("failed to parse ldap attribute %s='%s'\n",
context->config.attributes[ATTR_GID], *values[ATTR_GID]);
status = ERROR_INVALID_PARAMETER;
goto out_free_values;
}
group->last_updated = time(NULL);
if (context->config.cache_ttl) {
/* insert the entry into the cache */
cache_insert(&context->groups, lookup, &group->entry);
}
out_free_values:
for (i = 0; i < NUM_ATTRIBUTES; i++)
ldap_value_free(values[i]);
out:
return status;
}
开发者ID:AchillesA,项目名称:ms-nfs41-client,代码行数:52,代码来源:idmap.c
示例13: cache_get
static struct file *
cache_get(const char *path)
{
struct file *f = NULL;
pthread_mutex_lock(&cache.lock);
cache_clean();
f = g_hash_table_lookup(cache.files, path);
if(f == NULL)
f = cache_insert(path);
pthread_mutex_unlock(&cache.lock);
return f;
}
开发者ID:JeremyOT,项目名称:stormfs,代码行数:14,代码来源:stormfs.c
示例14: client_recv_cb
/*
*
* SOCKS5 UDP Request
* +----+------+------+----------+----------+----------+
* |RSV | FRAG | ATYP | DST.ADDR | DST.PORT | DATA |
* +----+------+------+----------+----------+----------+
* | 2 | 1 | 1 | Variable | 2 | Variable |
* +----+------+------+----------+----------+----------+
*
*/
static void
client_recv_cb(uv_udp_t *handle, ssize_t nread, const uv_buf_t *buf, const struct sockaddr *addr, unsigned flags) {
struct server_context *server = container_of(handle, struct server_context, udp);
if (nread > 0) {
uint8_t frag = buf->base[2];
if (frag) {
logger_log(LOG_ERR, "don't support udp dgram frag");
goto err;
}
char key[KEY_BYTES + 1] = {0};
crypto_generickey((uint8_t *)key, sizeof(key) -1, (uint8_t*)addr, sizeof(*addr), NULL, 0);
struct client_context *client = NULL;
uv_mutex_lock(&mutex);
cache_lookup(cache, key, (void *)&client);
uv_mutex_unlock(&mutex);
if (client == NULL) {
client = new_client();
client->addr = *addr;
client->local_handle = handle;
memcpy(client->key, key, sizeof(key));
uv_timer_init(handle->loop, client->timer);
uv_udp_init(handle->loop, &client->server_handle);
client->server_handle.data = client;
uv_udp_recv_start(&client->server_handle, server_alloc_cb, server_recv_cb);
uv_mutex_lock(&mutex);
cache_insert(cache, client->key, (void *)client);
uv_mutex_unlock(&mutex);
}
int clen = nread - 3 + PRIMITIVE_BYTES;
uint8_t *c = (uint8_t *)buf->base - PRIMITIVE_BYTES;
int rc = crypto_encrypt(c, (uint8_t*)buf->base + 3, nread - 3);
if (!rc) {
reset_timer(client);
forward_to_server(server->server_addr, client, c, clen);
}
} else {
goto err;
}
return;
err:
free(buf->base - PRIMITIVE_BYTES);
}
开发者ID:nsdown,项目名称:xsocks-1,代码行数:59,代码来源:xsocks_udprelay.c
示例15: check_block_list
int
check_block_list(char *addr, int err_level)
{
size_t addr_len = strlen(addr);
if (cache_key_exist(block_list, addr, addr_len)) {
int *count = NULL;
cache_lookup(block_list, addr, addr_len, &count);
if (count != NULL) {
if (*count > MAX_TRIES)
return 1;
(*count) += err_level;
}
} else {
int *count = (int *)ss_malloc(sizeof(int));
*count = 1;
cache_insert(block_list, addr, addr_len, count);
}
return 0;
}
开发者ID:kdrx,项目名称:shadowsocks-libev,代码行数:21,代码来源:acl.c
示例16: curl_op
bool_t curl_op(char **arg, wd_in *result){
CURL *curl;
CURLcode res;
wd_in wdi;
char *url = arg[0];
memset(&wdi, 0, sizeof(wdi));
curl = curl_easy_init();
if(NULL != curl) {
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &wdi);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
copy_result(&wdi,result);
cache_insert(url, &wdi);
return 1;
}
else {
fprintf(stderr, "Error: could not get CURL handle.\n");
return 0;
}
}
开发者ID:rohantahiliani,项目名称:GTRPC,代码行数:22,代码来源:proxy_server.c
示例17: rosedb_add
static int rosedb_add(struct cache *cache, MDB_txn *txn, int argc, char *argv[])
{
printf("ADD %s\t%s\t%s\t%s\t%s\t%s\n", argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]);
knot_dname_t key[KNOT_DNAME_MAXLEN] = { '\0' };
knot_dname_from_str(key, argv[0], sizeof(key));
knot_dname_to_lower(key);
struct entry entry;
int ret = parse_rdata(&entry, argv[0], argv[1], argv[3], atoi(argv[2]), cache->pool);
entry.threat_code = argv[4];
entry.syslog_ip = argv[5];
if (ret != 0) {
fprintf(stderr, "PARSE: %s\n", knot_strerror(ret));
return ret;
}
ret = cache_insert(txn, cache->dbi, key, &entry);
if (ret != 0) {
fprintf(stderr, "%s\n", mdb_strerror(ret));
}
return ret;
}
开发者ID:idtek,项目名称:knot,代码行数:24,代码来源:rosedb_tool.c
示例18: cache_check
struct peer_cache *rand_cache(struct peer_cache *c, int n)
{
struct peer_cache *res;
cache_check(c);
if (c->current_size < n) {
n = c->current_size;
}
res = cache_init(n, c->metadata_size, c->max_timestamp);
while(res->current_size < n) {
int j;
j = ((double)rand() / (double)RAND_MAX) * c->current_size;
cache_insert(res, c->entries + j, c->metadata + c->metadata_size * j);
c->current_size--;
memmove(c->entries + j, c->entries + j + 1, sizeof(struct cache_entry) * (c->current_size - j));
memmove(c->metadata + c->metadata_size * j, c->metadata + c->metadata_size * (j + 1), c->metadata_size * (c->current_size - j));
c->entries[c->current_size].id = NULL;
cache_check(c);
}
return res;
}
开发者ID:HunterChen,项目名称:GRAPES,代码行数:24,代码来源:topocache.c
示例19: CC_HINT
//.........这里部分代码省略.........
if (rcode == RLM_MODULE_FAIL) goto finish;
rad_assert(handle);
/*
* If Cache-Status-Only == yes, only return whether we found a
* valid cache entry
*/
vp = pairfind(request->config_items, PW_CACHE_STATUS_ONLY, 0, TAG_ANY);
if (vp && vp->vp_integer) {
rcode = c ? RLM_MODULE_OK:
RLM_MODULE_NOTFOUND;
goto finish;
}
/*
* Update the expiry time based on the TTL.
* A TTL of 0 means "delete from the cache".
* A TTL < 0 means "delete from the cache and recreate the entry".
*/
vp = pairfind(request->config_items, PW_CACHE_TTL, 0, TAG_ANY);
if (vp) ttl = vp->vp_signed;
/*
* If there's no existing cache entry, go and create a new one.
*/
if (!c) {
if (ttl <= 0) ttl = inst->ttl;
goto insert;
}
/*
* Expire the entry if requested to do so
*/
if (vp) {
if (ttl == 0) {
cache_expire(inst, request, &handle, &c);
RDEBUG("Forcing expiry of entry");
rcode = RLM_MODULE_OK;
goto finish;
}
if (ttl < 0) {
RDEBUG("Forcing expiry of existing entry");
cache_expire(inst, request, &handle, &c);
ttl *= -1;
goto insert;
}
c->expires = request->timestamp + ttl;
RDEBUG("Setting TTL to %d", ttl);
}
/*
* Cache entry was still valid, so we merge it into the request
* and return. No need to add a new entry.
*/
cache_merge(inst, request, c);
rcode = RLM_MODULE_UPDATED;
goto finish;
insert:
/*
* If Cache-Read-Only == yes, then we only allow already cached entries
* to be merged into the request
*/
vp = pairfind(request->config_items, PW_CACHE_READ_ONLY, 0, TAG_ANY);
if (vp && vp->vp_integer) {
rcode = RLM_MODULE_NOTFOUND;
goto finish;
}
/*
* Create a new entry.
*/
rcode = cache_insert(inst, request, &handle, buffer, ttl);
rad_assert(handle);
finish:
cache_free(inst, &c);
cache_release(inst, request, &handle);
/*
* Clear control attributes
*/
for (vp = fr_cursor_init(&cursor, &request->config_items);
vp;
vp = fr_cursor_next(&cursor)) {
if (vp->da->vendor == 0) switch (vp->da->attr) {
case PW_CACHE_TTL:
case PW_CACHE_STATUS_ONLY:
case PW_CACHE_READ_ONLY:
case PW_CACHE_MERGE:
vp = fr_cursor_remove(&cursor);
talloc_free(vp);
break;
}
}
return rcode;
}
开发者ID:LarsKollstedt,项目名称:freeradius-server,代码行数:101,代码来源:rlm_cache.c
示例20: query_resolve_cb
static void
query_resolve_cb(struct sockaddr *addr, void *data)
{
struct query_ctx *query_ctx = (struct query_ctx *)data;
struct ev_loop *loop = query_ctx->server_ctx->loop;
if (verbose) {
LOGI("[udp] udns resolved");
}
query_ctx->query = NULL;
if (addr == NULL) {
LOGE("[udp] udns returned an error");
} else {
remote_ctx_t *remote_ctx = query_ctx->remote_ctx;
int cache_hit = 0;
// Lookup in the conn cache
if (remote_ctx == NULL) {
char *key = hash_key(AF_UNSPEC, &query_ctx->src_addr);
cache_lookup(query_ctx->server_ctx->conn_cache, key, HASH_KEY_LEN, (void *)&remote_ctx);
}
if (remote_ctx == NULL) {
int remotefd = create_remote_socket(addr->sa_family == AF_INET6);
if (remotefd != -1) {
setnonblocking(remotefd);
#ifdef SO_BROADCAST
set_broadcast(remotefd);
#endif
#ifdef SO_NOSIGPIPE
set_nosigpipe(remotefd);
#endif
#ifdef IP_TOS
// Set QoS flag
int tos = 46;
setsockopt(remotefd, IPPROTO_IP, IP_TOS, &tos, sizeof(tos));
#endif
#ifdef SET_INTERFACE
if (query_ctx->server_ctx->iface) {
if (setinterface(remotefd, query_ctx->server_ctx->iface) == -1)
ERROR("setinterface");
}
#endif
remote_ctx = new_remote(remotefd, query_ctx->server_ctx);
remote_ctx->src_addr = query_ctx->src_addr;
remote_ctx->server_ctx = query_ctx->server_ctx;
remote_ctx->addr_header_len = query_ctx->addr_header_len;
memcpy(remote_ctx->addr_header, query_ctx->addr_header,
query_ctx->addr_header_len);
} else {
ERROR("[udp] bind() error");
}
} else {
cache_hit = 1;
}
if (remote_ctx != NULL) {
memcpy(&remote_ctx->dst_addr, addr, sizeof(struct sockaddr_storage));
size_t addr_len = get_sockaddr_len(addr);
int s = sendto(remote_ctx->fd, query_ctx->buf->data, query_ctx->buf->len,
0, addr, addr_len);
if (s == -1) {
ERROR("[udp] sendto_remote");
if (!cache_hit) {
close_and_free_remote(EV_A_ remote_ctx);
}
} else {
if (!cache_hit) {
// Add to conn cache
char *key = hash_key(AF_UNSPEC, &remote_ctx->src_addr);
cache_insert(query_ctx->server_ctx->conn_cache, key, HASH_KEY_LEN, (void *)remote_ctx);
ev_io_start(EV_A_ & remote_ctx->io);
ev_timer_start(EV_A_ & remote_ctx->watcher);
}
}
}
}
// clean up
close_and_free_query(EV_A_ query_ctx);
}
开发者ID:wobrea,项目名称:shadowsocks-libev,代码行数:85,代码来源:udprelay.c
注:本文中的cache_insert函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论