当前位置: 首页>>代码示例>>C++>>正文


C++ cachedb_funcs::set方法代码示例

本文整理汇总了C++中cachedb_funcs::set方法的典型用法代码示例。如果您正苦于以下问题:C++ cachedb_funcs::set方法的具体用法?C++ cachedb_funcs::set怎么用?C++ cachedb_funcs::set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cachedb_funcs的用法示例。


在下文中一共展示了cachedb_funcs::set方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: put_dnscache_value

/* Pushes internal structure ( hostent or rdata ) to a cache backend
 * Params :
 * name - what query to be saved - binary IP for PTR and strings for other queries
 * r_type - type of DNS query
 * record - pointer to hostent or rdata
 * rdata_len - If rdata record, rdata_len holds the actual length of rdata buf,
		in order to avoid double iterations on the rdata struct. If it's a
		PTR record, rdata_len is used to differentiate between IP and IPv6
 * failure - should we blacklist or not
 * ttl - seconds the key should be kept in cache */
int put_dnscache_value(char *name,int r_type,void *record,int rdata_len,
				int failure,int ttl)
{
	str key,value;
	int key_ttl;

	if (cdbc == NULL) {
		/* assume dns request before forking - cache is not ready yet */
		return -1;	
	}

	/* generate key */
	key.s=create_keyname_for_record(name,r_type,rdata_len,&key.len);
	if (key.s == NULL) {
		LM_ERR("failed to create key\n");
		return -1;
	}

	if (failure) {
		/* just set value as failure marker, and push to back-end
		 * with the default timeout */
		value.s = FAILURE_MARKER;
		value.len= FAILURE_MARKER_LEN;
		key_ttl = blacklist_timeout; 
	} else {
		if (r_type == T_A || r_type == T_AAAA || r_type == T_PTR) {
			value.s = serialize_he_rdata((struct hostent *)record,
		&value.len,CACHEDB_CAPABILITY(&cdbf,CACHEDB_CAP_BINARY_VALUE)?0:1); 
			if (value.s == NULL) {
				LM_ERR("failed to serialize he rdata\n");
				return -1;
			}
		} else {
			value.s = serialize_dns_rdata((struct rdata *)record,
		rdata_len,&value.len,CACHEDB_CAPABILITY(&cdbf,CACHEDB_CAP_BINARY_VALUE)?0:1);
			if (value.s == NULL) {
				LM_ERR("failed to serialize rdata record\n");
				return -1;
			}
		}

		key_ttl = ttl;
	}

	LM_DBG("putting value [%.*s] with ttl = %d\n",key.len,key.s,key_ttl);
	if (cdbf.set(cdbc,&key,&value,key_ttl) < 0) {
		LM_ERR("failed to set dns key\n");
		return -1;
	}

	return 0;
}
开发者ID:KISSMonX,项目名称:opensips,代码行数:62,代码来源:dns_cache.c


注:本文中的cachedb_funcs::set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。