本文整理汇总了C++中DB::get_re_len方法的典型用法代码示例。如果您正苦于以下问题:C++ DB::get_re_len方法的具体用法?C++ DB::get_re_len怎么用?C++ DB::get_re_len使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DB
的用法示例。
在下文中一共展示了DB::get_re_len方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pctldb_rcv
int pctldb_rcv(struct pctldb_st *pctldb, void *p, uint32_t *size, int *dberror){
int status = 0;
DBT key, data;
uint32_t recno;
uint32_t reclen;
DB* dbp = pctldb->dbp;
assert(p != NULL);
if(p == NULL){
*dberror = EINVAL;
return(-1);
}
memset(&key, 0 , sizeof(DBT));
memset(&data, 0 , sizeof(DBT));
if((status = dbp->get_re_len(dbp, &reclen)) != 0){
*dberror = status;
return(-1);
}
if(*size < reclen){
*dberror = EINVAL;
return(-1);
}
key.data = &recno;
key.ulen = sizeof(recno);
key.flags = DB_DBT_USERMEM;
data.data = p;
data.ulen = reclen;
data.flags = DB_DBT_USERMEM;
status = dbp->get(dbp, NULL, &key, &data, DB_CONSUME);
if(status != 0){
*dberror = status;
status = -1;
}else{
*size = reclen;
--pctldb->n;
}
return(status);
}
示例2: qdb_rcv
int qdb_rcv(struct nbspq_st *nbspq, void **p, uint32_t *size, int *dberror){
/*
* If (*p == NULL), it allocates space for the data. But if *p is not NULL
* it reuses the space, updating the size to return the true size of the
* data.
*/
int status = 0;
DBT key, data;
uint32_t recno;
uint32_t reclen;
void *p_copy;
DB* dbp = nbspq->dbp;
memset(&key, 0 , sizeof(DBT));
memset(&data, 0 , sizeof(DBT));
if((status = dbp->get_re_len(dbp, &reclen)) != 0){
*dberror = status;
return(-1);
}
if(*p == NULL)
p_copy = malloc(reclen);
else{
if(*size < reclen){
*dberror = EINVAL;
return(-1);
}else
p_copy = *p;
}
if(p_copy == NULL){
*dberror = errno;
return(-1);
}
key.data = &recno;
key.ulen = sizeof(recno);
key.flags = DB_DBT_USERMEM;
data.data = p_copy;
data.ulen = reclen;
data.flags = DB_DBT_USERMEM;
status = dbp->get(dbp, NULL, &key, &data, DB_CONSUME);
if(status != 0){
*dberror = status;
status = -1;
if(*p == NULL)
free(p_copy);
}else{
if(*p == NULL)
*p = p_copy;
*size = reclen;
--nbspq->n;
/*
* The call to truncate() below is added to handle the case of in-memory
* queues, in which case the page/extent size mechanism for reclaiming
* unused space does not operate (both calls return errors when the
* data base is configured as in-memory db). If this is not done here,
* or somewhere, then the cache is eventually exhasusted and the
* the next calls to qdb_send return an error (memory cannot be allocated.)
*/
if(nbspq->f_memory_based && (nbspq->n == 0))
status = dbp->truncate(dbp, NULL, NULL, 0);
}
return(status);
}