⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 db_server_cxxproc.cpp

📁 关于Berkelay数据库的共享源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	int ret;	ACTIVATE_CTP(dbp_ctp, dbpcl_id, CT_DB);	dbp = (Db *)dbp_ctp->ct_anyp;	if (txnpcl_id != 0) {		ACTIVATE_CTP(txnp_ctp, txnpcl_id, CT_TXN);		txnp = (DbTxn *)txnp_ctp->ct_anyp;	} else		txnp = NULL;	ret = dbp->truncate(txnp, &count, flags);	replyp->status = ret;	if (ret == 0)		replyp->count = count;	return;}extern "C" void__db_cursor_proc(	u_int dbpcl_id,	u_int txnpcl_id,	u_int32_t flags,	__db_cursor_reply *replyp){	Db *dbp;	Dbc *dbc;	DbTxn *txnp;	ct_entry *dbc_ctp, *env_ctp, *dbp_ctp, *txnp_ctp;	int ret;	ACTIVATE_CTP(dbp_ctp, dbpcl_id, CT_DB);	dbp = (Db *)dbp_ctp->ct_anyp;	dbc_ctp = new_ct_ent(&replyp->status);	if (dbc_ctp == NULL)		return;	if (txnpcl_id != 0) {		ACTIVATE_CTP(txnp_ctp, txnpcl_id, CT_TXN);		txnp = (DbTxn *)txnp_ctp->ct_anyp;		dbc_ctp->ct_activep = txnp_ctp->ct_activep;	} else		txnp = NULL;	if ((ret = dbp->cursor(txnp, &dbc, flags)) == 0) {		dbc_ctp->ct_dbc = dbc;		dbc_ctp->ct_type = CT_CURSOR;		dbc_ctp->ct_parent = dbp_ctp;		env_ctp = dbp_ctp->ct_envparent;		dbc_ctp->ct_envparent = env_ctp;		__dbsrv_settimeout(dbc_ctp, env_ctp->ct_timeout);		__dbsrv_active(dbc_ctp);		replyp->dbcidcl_id = dbc_ctp->ct_id;	} else		__dbclear_ctp(dbc_ctp);	replyp->status = ret;	return;}extern "C" void__db_join_proc(	u_int dbpcl_id,	u_int32_t *curs,	u_int32_t curslen,	u_int32_t flags,	__db_join_reply *replyp){	Db *dbp;	Dbc **jcurs, **c;	Dbc *dbc;	ct_entry *dbc_ctp, *ctp, *dbp_ctp;	size_t size;	u_int32_t *cl, i;	int ret;	ACTIVATE_CTP(dbp_ctp, dbpcl_id, CT_DB);	dbp = (Db *)dbp_ctp->ct_anyp;	dbc_ctp = new_ct_ent(&replyp->status);	if (dbc_ctp == NULL)		return;	size = (curslen + 1) * sizeof(Dbc *);	if ((ret = __os_calloc(dbp->get_DB()->dbenv,	    curslen + 1, sizeof(Dbc *), &jcurs)) != 0) {		replyp->status = ret;		__dbclear_ctp(dbc_ctp);		return;	}	/*	 * If our curslist has a parent txn, we need to use it too	 * for the activity timeout.  All cursors must be part of	 * the same transaction, so just check the first.	 */	ctp = get_tableent(*curs);	DB_ASSERT(dbp->get_DB()->dbenv, ctp->ct_type == CT_CURSOR);	/*	 * If we are using a transaction, set the join activity timer	 * to point to the parent transaction.	 */	if (ctp->ct_activep != &ctp->ct_active)		dbc_ctp->ct_activep = ctp->ct_activep;	for (i = 0, cl = curs, c = jcurs; i < curslen; i++, cl++, c++) {		ctp = get_tableent(*cl);		if (ctp == NULL) {			replyp->status = DB_NOSERVER_ID;			goto out;		}		/*		 * If we are using a txn, the join cursor points to the		 * transaction timeout.  If we are not using a transaction,		 * then all the curslist cursors must point to the join		 * cursor's timeout so that we do not timeout any of the		 * curlist cursors while the join cursor is active.		 * Change the type of the curslist ctps to CT_JOIN so that		 * we know they are part of a join list and we can distinguish		 * them and later restore them when the join cursor is closed.		 */		DB_ASSERT(dbp->get_DB()->dbenv, ctp->ct_type == CT_CURSOR);		ctp->ct_type |= CT_JOIN;		ctp->ct_origp = ctp->ct_activep;		/*		 * Setting this to the ct_active field of the dbc_ctp is		 * really just a way to distinguish which join dbc this		 * cursor is part of.  The ct_activep of this cursor is		 * not used at all during its lifetime as part of a join		 * cursor.		 */		ctp->ct_activep = &dbc_ctp->ct_active;		*c = ctp->ct_dbc;	}	*c = NULL;	if ((ret = dbp->join(jcurs, &dbc, flags)) == 0) {		dbc_ctp->ct_dbc = dbc;		dbc_ctp->ct_type = (CT_JOINCUR | CT_CURSOR);		dbc_ctp->ct_parent = dbp_ctp;		dbc_ctp->ct_envparent = dbp_ctp->ct_envparent;		__dbsrv_settimeout(dbc_ctp, dbp_ctp->ct_envparent->ct_timeout);		__dbsrv_active(dbc_ctp);		replyp->dbcidcl_id = dbc_ctp->ct_id;	} else {		__dbclear_ctp(dbc_ctp);		/*		 * If we get an error, undo what we did above to any cursors.		 */		for (cl = curs; *cl != 0; cl++) {			ctp = get_tableent(*cl);			ctp->ct_type = CT_CURSOR;			ctp->ct_activep = ctp->ct_origp;		}	}	replyp->status = ret;out:	__os_free(dbp->get_DB()->dbenv, jcurs);	return;}extern "C" void__dbc_c_close_proc(	u_int dbccl_id,	__dbc_c_close_reply *replyp){	ct_entry *dbc_ctp;	ACTIVATE_CTP(dbc_ctp, dbccl_id, CT_CURSOR);	replyp->status = __dbc_close_int(dbc_ctp);	return;}extern "C" void__dbc_c_count_proc(	u_int dbccl_id,	u_int32_t flags,	__dbc_c_count_reply *replyp){	Dbc *dbc;	ct_entry *dbc_ctp;	db_recno_t num;	int ret;	ACTIVATE_CTP(dbc_ctp, dbccl_id, CT_CURSOR);	dbc = (Dbc *)dbc_ctp->ct_anyp;	ret = dbc->count(&num, flags);	replyp->status = ret;	if (ret == 0)		replyp->dupcount = num;	return;}extern "C" void__dbc_c_del_proc(	u_int dbccl_id,	u_int32_t flags,	__dbc_c_del_reply *replyp){	Dbc *dbc;	ct_entry *dbc_ctp;	int ret;	ACTIVATE_CTP(dbc_ctp, dbccl_id, CT_CURSOR);	dbc = (Dbc *)dbc_ctp->ct_anyp;	ret = dbc->del(flags);	replyp->status = ret;	return;}extern "C" void__dbc_c_dup_proc(	u_int dbccl_id,	u_int32_t flags,	__dbc_c_dup_reply *replyp){	Dbc *dbc, *newdbc;	ct_entry *dbc_ctp, *new_ctp;	int ret;	ACTIVATE_CTP(dbc_ctp, dbccl_id, CT_CURSOR);	dbc = (Dbc *)dbc_ctp->ct_anyp;	new_ctp = new_ct_ent(&replyp->status);	if (new_ctp == NULL)		return;	if ((ret = dbc->dup(&newdbc, flags)) == 0) {		new_ctp->ct_dbc = newdbc;		new_ctp->ct_type = CT_CURSOR;		new_ctp->ct_parent = dbc_ctp->ct_parent;		new_ctp->ct_envparent = dbc_ctp->ct_envparent;		/*		 * If our cursor has a parent txn, we need to use it too.		 */		if (dbc_ctp->ct_activep != &dbc_ctp->ct_active)			new_ctp->ct_activep = dbc_ctp->ct_activep;		__dbsrv_settimeout(new_ctp, dbc_ctp->ct_timeout);		__dbsrv_active(new_ctp);		replyp->dbcidcl_id = new_ctp->ct_id;	} else		__dbclear_ctp(new_ctp);	replyp->status = ret;	return;}extern "C" void__dbc_c_get_proc(	u_int dbccl_id,	u_int32_t keydlen,	u_int32_t keydoff,	u_int32_t keyulen,	u_int32_t keyflags,	void *keydata,	u_int32_t keysize,	u_int32_t datadlen,	u_int32_t datadoff,	u_int32_t dataulen,	u_int32_t dataflags,	void *datadata,	u_int32_t datasize,	u_int32_t flags,	__dbc_c_get_reply *replyp,	int * freep){	Dbc *dbc;	DbEnv *dbenv;	ct_entry *dbc_ctp;	int ret;	void *tmpdata;	ACTIVATE_CTP(dbc_ctp, dbccl_id, CT_CURSOR);	dbc = (Dbc *)dbc_ctp->ct_anyp;	dbenv = DbEnv::get_DbEnv(((DBC *)dbc)->dbp->dbenv);	replyp->keydata.keydata_val = NULL;	replyp->datadata.datadata_val = NULL;	*freep = 0;	/* Set up key and data */	Dbt key(keydata, keysize);	key.set_dlen(keydlen);	key.set_ulen(keyulen);	key.set_doff(keydoff);	key.set_flags(DB_DBT_MALLOC | (keyflags & DB_DBT_PARTIAL));	Dbt data(datadata, datasize);	data.set_dlen(datadlen);	data.set_ulen(dataulen);	data.set_doff(datadoff);	dataflags &= DB_DBT_PARTIAL;	if (flags & DB_MULTIPLE || flags & DB_MULTIPLE_KEY) {		if (data.get_data() == NULL) {			ret = __os_umalloc(dbenv->get_DB_ENV(),			    data.get_ulen(), &tmpdata);			if (ret != 0)				goto err;			data.set_data(tmpdata);		}		dataflags |= DB_DBT_USERMEM;	} else		dataflags |= DB_DBT_MALLOC;	data.set_flags(dataflags);	/* Got all our stuff, now do the get */	ret = dbc->get(&key, &data, flags);	/*	 * Otherwise just status.	 */	if (ret == 0) {		/*		 * XXX		 * We need to xdr_free whatever we are returning, next time.		 * However, DB does not allocate a new key if one was given		 * and we'd be free'ing up space allocated in the request.		 * So, allocate a new key/data pointer if it is the same one		 * as in the request.		 */		*freep = 1;		/*		 * Key		 */		if (key.get_data() == keydata) {			ret = __os_umalloc(dbenv->get_DB_ENV(), key.get_size(),			    &replyp->keydata.keydata_val);			if (ret != 0)				goto err;			memcpy(replyp->keydata.keydata_val,			    key.get_data(), key.get_size());		} else			replyp->keydata.keydata_val = (char *)key.get_data();		replyp->keydata.keydata_len = key.get_size();		/*		 * Data		 */		if (data.get_data() == datadata) {			ret = __os_umalloc(dbenv->get_DB_ENV(), data.get_size(),			    &replyp->datadata.datadata_val);			if (ret != 0)				goto err;			memcpy(replyp->datadata.datadata_val, data.get_data(),			    data.get_size());		} else			replyp->datadata.datadata_val = (char *)data.get_data();		replyp->datadata.datadata_len = data.get_size();	} else {err:		FREE_IF_CHANGED(dbenv->get_DB_ENV(),		    key.get_data(), keydata);		FREE_IF_CHANGED(dbenv->get_DB_ENV(),		    data.get_data(), datadata);		FREE_IF_CHANGED(dbenv->get_DB_ENV(),		    replyp->keydata.keydata_val, key.get_data());		FREE_IF_CHANGED(dbenv->get_DB_ENV(),		    replyp->datadata.datadata_val, data.get_data());		replyp->keydata.keydata_val = NULL;		replyp->keydata.keydata_len = 0;		replyp->datadata.datadata_val = NULL;		replyp->datadata.datadata_len = 0;		*freep = 0;	}	replyp->status = ret;	return;}extern "C" void__dbc_c_pget_proc(	u_int dbccl_id,	u_int32_t skeydlen,	u_int32_t skeydoff,	u_int32_t skeyulen,	u_int32_t skeyflags,	void *skeydata,	u_int32_t skeysize,	u_int32_t pkeydlen,	u_int32_t pkeydoff,	u_int32_t pkeyulen,	u_int32_t pkeyflags,	void *pkeydata,	u_int32_t pkeysize,	u_int32_t datadlen,	u_int32_t datadoff,	u_int32_t dataulen,	u_int32_t dataflags,	void *datadata,	u_int32_t datasize,	u_int32_t flags,	__dbc_c_pget_reply *replyp,	int * freep){	Dbc *dbc;	DbEnv *dbenv;	ct_entry *dbc_ctp;	int ret;	ACTIVATE_CTP(dbc_ctp, dbccl_id, CT_CURSOR);	dbc = (Dbc *)dbc_ctp->ct_anyp;	dbenv = DbEnv::get_DbEnv(((DBC *)dbc)->dbp->dbenv);	replyp->skeydata.skeydata_val = NULL;	replyp->pkeydata.pkeydata_val = NULL;	replyp->datadata.datadata_val = NULL;	*freep = 0;	/*	 * Ignore memory related flags on server.	 */	/* Set up key and data */	Dbt skey(skeydata, skeysize);	skey.set_dlen(skeydlen);	skey.set_ulen(skeyulen);	skey.set_doff(skeydoff);	skey.set_flags(DB_DBT_MALLOC | (skeyflags & DB_DBT_PARTIAL));	Dbt pkey(pkeydata, pkeysize);	pkey.set_dlen(pkeydlen);	pkey.set_ulen(pkeyulen);	pkey.set_doff(pkeydoff);	pkey.set_flags(DB_DBT_MALLOC | (pkeyflags & DB_DBT_PARTIAL));	Dbt data(datadata, datasize);	data.set_dlen(datadlen);	data.set_ulen(dataulen);	data.set_doff(datadoff);	data.set_flags(DB_DBT_MALLOC | (dataflags & DB_DBT_PARTIAL));	/* Got all our stuff, now do the get */	ret = dbc->pget(&skey, &pkey, &data, flags);	/*	 * Otherwise just status.	 */	if (ret == 0) {		/*		 * XXX		 * We need to xdr_free whatever we are returning, next time.		 * However, DB does not allocate a new key if one was given		 * and we'd be free'ing up space allocated in the request.		 * So, allocate a new key/data pointer if it is the same one		 * as in the request.		 */		*freep = 1;		/*		 * Key		 */		if (skey.get_data() == skeydata) {			ret = __os_umalloc(dbenv->get_DB_ENV(),			    skey.get_size(), &replyp->skeydata.skeydata_val);			if (ret != 0)				goto err;			memcpy(replyp->skeydata.skeydata_val, skey.get_data(),			    skey.get_size());		} else			replyp->skeydata.skeydata_val = (char *)skey.get_data();		replyp->skeydata.skeydata_len = skey.get_size();		/*		 * Primary key		 */		if (pkey.get_data() == pkeydata) {			ret = __os_umalloc(dbenv->get_DB_ENV(),			     pkey.get_size(), &replyp->pkeydata.pkeydata_val);			if (ret != 0)				goto err;			memcpy(replyp->pkeydata.pkeydata_val, pkey.get_data(),			    pkey.get_size());		} else			replyp->pkeydata.pkeydata_val = (char *)pkey.get_data();		replyp->pkeydata.pkeydata_len = pkey.get_size();		/*		 * Data		 */		if (data.get_data() == datadata) {			ret = __os_umalloc(dbenv->get_DB_ENV(),			     data.get_size(), &replyp->datadata.datadata_val);			if (ret != 0)				goto err;			memcpy(replyp->datadata.datadata_val, data.get_data(),			    data.get_size());		} else			replyp->datadata.datadata_val = (char *)data.get_data();		replyp->datadata.datadata_len = data.get_size();	} else {err:		FREE_IF_CHANGED(dbenv->get_DB_ENV(),		    skey.get_data(), skeydata);		FREE_IF_CHANGED(dbenv->get_DB_ENV(),		    pkey.get_data(), pkeydata);		FREE_IF_CHANGED(dbenv->get_DB_ENV(),		    data.get_data(), datadata);		FREE_IF_CHANGED(dbenv->get_DB_ENV(),		    replyp->skeydata.skeydata_val, skey.get_data());		FREE_IF_CHANGED(dbenv->get_DB_ENV(),		    replyp->pkeydata.pkeydata_val, pkey.get_data());		FREE_IF_CHANGED(dbenv->get_DB_ENV(),		    replyp->datadata.datadata_val, data.get_data());		replyp->skeydata.skeydata_val = NULL;		replyp->skeydata.skeydata_len = 0;		replyp->pkeydata.pkeydata_val = NULL;		replyp->pkeydata.pkeydata_len = 0;		replyp->datadata.datadata_val = NULL;		replyp->datadata.datadata_len = 0;		*freep = 0;	}	replyp->status = ret;	return;}extern "C" void__dbc_c_put_proc(	u_int dbccl_id,	u_int32_t keydlen,	u_int32_t keydoff,	u_int32_t keyulen,	u_int32_t keyflags,	void *keydata,	u_int32_t keysize,	u_int32_t datadlen,	u_int32_t datadoff,	u_int32_t dataulen,	u_int32_t dataflags,	void *datadata,	u_int32_t datasize,	u_int32_t flags,	__dbc_c_put_reply *replyp,	int * freep){	Db *dbp;	Dbc *dbc;	ct_entry *dbc_ctp;	int ret;	DBTYPE dbtype;	ACTIVATE_CTP(dbc_ctp, dbccl_id, CT_CURSOR);	dbc = (Dbc *)dbc_ctp->ct_anyp;	dbp = (Db *)dbc_ctp->ct_parent->ct_anyp;	/* Set up key and data */	Dbt key(keydata, keysize);	key.set_dlen(keydlen);	key.set_ulen(keyulen);	key.set_doff(keydoff);	/*	 * Ignore memory related flags on server.	 */	key.set_flags(DB_DBT_MALLOC | (keyflags & DB_DBT_PARTIAL));	Dbt data(datadata, datasize);	data.set_dlen(datadlen);	data.set_ulen(dataulen);	data.set_doff(datadoff);	data.set_flags(dataflags);	/* Got all our stuff, now do the put */	ret = dbc->put(&key, &data, flags);	*freep = 0;	replyp->keydata.keydata_val = NULL;	replyp->keydata.keydata_len = 0;	if (ret == 0 && (flags == DB_AFTER || flags == DB_BEFORE)) {		ret = dbp->get_type(&dbtype);		if (ret == 0 && dbtype == DB_RECNO) {			/*			 * We need to xdr_free whatever we are returning, next			 * time.			 */			replyp->keydata.keydata_val = (char *)key.get_data();			replyp->keydata.keydata_len = key.get_size();		}	}	replyp->status = ret;	return;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -