本文整理汇总了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;
}