📄 db_server_proc.c.in
字号:
* PUBLIC: __db_join_reply *)); */void__db_join_proc(dbpcl_id, curs, curslen, flags, replyp) long dbpcl_id; u_int32_t * curs; u_int32_t curslen; u_int32_t flags; __db_join_reply *replyp;/* END __db_join_proc */{ 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->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(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(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(dbp, 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->dbenv, jcurs); return;}/* BEGIN __dbc_close_proc *//* * PUBLIC: void __dbc_close_proc __P((long, __dbc_close_reply *)); */void__dbc_close_proc(dbccl_id, replyp) long dbccl_id; __dbc_close_reply *replyp;/* END __dbc_close_proc */{ ct_entry *dbc_ctp; ACTIVATE_CTP(dbc_ctp, dbccl_id, CT_CURSOR); replyp->status = __dbc_close_int(dbc_ctp); return;}/* BEGIN __dbc_count_proc *//* * PUBLIC: void __dbc_count_proc __P((long, u_int32_t, __dbc_count_reply *)); */void__dbc_count_proc(dbccl_id, flags, replyp) long dbccl_id; u_int32_t flags; __dbc_count_reply *replyp;/* END __dbc_count_proc */{ 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->c_count(dbc, &num, flags); replyp->status = ret; if (ret == 0) replyp->dupcount = num; return;}/* BEGIN __dbc_del_proc *//* * PUBLIC: void __dbc_del_proc __P((long, u_int32_t, __dbc_del_reply *)); */void__dbc_del_proc(dbccl_id, flags, replyp) long dbccl_id; u_int32_t flags; __dbc_del_reply *replyp;/* END __dbc_del_proc */{ DBC *dbc; ct_entry *dbc_ctp; int ret; ACTIVATE_CTP(dbc_ctp, dbccl_id, CT_CURSOR); dbc = (DBC *)dbc_ctp->ct_anyp; ret = dbc->c_del(dbc, flags); replyp->status = ret; return;}/* BEGIN __dbc_dup_proc *//* * PUBLIC: void __dbc_dup_proc __P((long, u_int32_t, __dbc_dup_reply *)); */void__dbc_dup_proc(dbccl_id, flags, replyp) long dbccl_id; u_int32_t flags; __dbc_dup_reply *replyp;/* END __dbc_dup_proc */{ 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->c_dup(dbc, &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;}/* BEGIN __dbc_get_proc *//* * PUBLIC: void __dbc_get_proc __P((long, u_int32_t, u_int32_t, u_int32_t, * PUBLIC: u_int32_t, void *, u_int32_t, u_int32_t, u_int32_t, u_int32_t, u_int32_t, void *, * PUBLIC: u_int32_t, u_int32_t, __dbc_get_reply *, int *)); */void__dbc_get_proc(dbccl_id, keydlen, keydoff, keyulen, keyflags, keydata, keysize, datadlen, datadoff, dataulen, dataflags, datadata, datasize, flags, replyp, freep) long 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_get_reply *replyp; int * freep;/* END __dbc_get_proc */{ DBC *dbc; DBT key, data; DB_ENV *dbenv; ct_entry *dbc_ctp; int key_alloc, bulk_alloc, ret; ACTIVATE_CTP(dbc_ctp, dbccl_id, CT_CURSOR); dbc = (DBC *)dbc_ctp->ct_anyp; dbenv = dbc->dbp->dbenv; *freep = 0; bulk_alloc = 0; memset(&key, 0, sizeof(key)); memset(&data, 0, sizeof(data)); /* Set up key and data DBT */ key.dlen = keydlen; key.ulen = keyulen; key.doff = keydoff; /* * Ignore memory related flags on server. */ key.flags = DB_DBT_MALLOC; if (keyflags & DB_DBT_PARTIAL) key.flags |= DB_DBT_PARTIAL; key.size = keysize; key.data = keydata; data.dlen = datadlen; data.ulen = dataulen; data.doff = datadoff; data.size = datasize; data.data = datadata; if (flags & DB_MULTIPLE || flags & DB_MULTIPLE_KEY) { if (data.data == 0) { ret = __os_umalloc(dbenv, data.ulen, &data.data); if (ret != 0) goto err; bulk_alloc = 1; } data.flags |= DB_DBT_USERMEM; } else data.flags |= DB_DBT_MALLOC; if (dataflags & DB_DBT_PARTIAL) data.flags |= DB_DBT_PARTIAL; /* Got all our stuff, now do the get */ ret = dbc->c_get(dbc, &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 */ key_alloc = 0; if (key.data == keydata) { ret = __os_umalloc(dbenv, key.size, &replyp->keydata.keydata_val); if (ret != 0) { __os_ufree(dbenv, key.data); __os_ufree(dbenv, data.data); goto err; } key_alloc = 1; memcpy(replyp->keydata.keydata_val, key.data, key.size); } else replyp->keydata.keydata_val = key.data; replyp->keydata.keydata_len = key.size; /* * Data */ if (data.data == datadata) { ret = __os_umalloc(dbenv, data.size, &replyp->datadata.datadata_val); if (ret != 0) { __os_ufree(dbenv, key.data); __os_ufree(dbenv, data.data); if (key_alloc) __os_ufree(dbenv, replyp->keydata.keydata_val); goto err; } memcpy(replyp->datadata.datadata_val, data.data, data.size); } else replyp->datadata.datadata_val = data.data; replyp->datadata.datadata_len = data.size; } else {err: replyp->keydata.keydata_val = NULL; replyp->keydata.keydata_len = 0; replyp->datadata.datadata_val = NULL; replyp->datadata.datadata_len = 0; *freep = 0; if (bulk_alloc) __os_ufree(dbenv, data.data); } replyp->status = ret; return;}/* BEGIN __dbc_pget_proc *//* * PUBLIC: void __dbc_pget_proc __P((long, u_int32_t, u_int32_t, u_int32_t, * PUBLIC: u_int32_t, void *, u_int32_t, u_int32_t, u_int32_t, u_int32_t, u_int32_t, void *, * PUBLIC: u_int32_t, u_int32_t, u_int32_t, u_int32_t, u_int32_t, void *, u_int32_t, * PUBLIC: u_int32_t, __dbc_pget_reply *, int *)); */void__dbc_pget_proc(dbccl_id, skeydlen, skeydoff, skeyulen, skeyflags, skeydata, skeysize, pkeydlen, pkeydoff, pkeyulen, pkeyflags, pkeydata, pkeysize, datadlen, datadoff, dataulen, dataflags, datadata, datasize, flags, replyp, freep) long 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_pget_reply *replyp; int * freep;/* END __dbc_pget_proc */{ DBC *dbc; DBT skey, pkey, data; DB_ENV *dbenv; ct_entry *dbc_ctp; int key_alloc, ret; ACTIVATE_CTP(dbc_ctp, dbccl_id, CT_CURSOR); dbc = (DBC *)dbc_ctp->ct_anyp; dbenv = dbc->dbp->dbenv; *freep = 0; memset(&skey, 0, sizeof(skey)); memset(&pkey, 0, sizeof(pkey)); memset(&data, 0, sizeof(data)); /* * Ignore memory related flags on server. */ /* Set up key and data DBT */ skey.flags = DB_DBT_MALLOC; skey.dlen = skeydlen; skey.ulen = skeyulen; skey.doff = skeydoff; if (skeyflags & DB_DBT_PARTIAL) skey.flags |= DB_DBT_PARTIAL; skey.size = skeysize; skey.data = skeydata; pkey.flags = DB_DBT_MALLOC; pkey.dlen = pkeydlen; pkey.ulen = pkeyulen; pkey.doff = pkeydoff; if (pkeyflags & DB_DBT_PARTIAL) pkey.flags |= DB_DBT_PARTIAL; pkey.size = pkeysize; pkey.data = pkeydata; data.flags = DB_DBT_MALLOC; data.dlen = datadlen; data.ulen = dataulen; data.doff = datadoff; if (dataflags & DB_DBT_PARTIAL) data.flags |= DB_DBT_PARTIAL; data.size = datasize; data.data = datadata; /* Got all our stuff, now do the get */ ret = dbc->c_pget(dbc, &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 */ key_alloc = 0; if (skey.data == skeydata) { ret = __os_umalloc(dbenv, skey.size, &replyp->skeydata.skeydata_val); if (ret != 0) { __os_ufree(dbenv, skey.data); __os_ufree(dbenv, pkey.data); __os_ufree(dbenv, data.data); goto err; } key_alloc = 1; memcpy(replyp->skeydata.skeydata_val, skey.data, skey.size); } else replyp->skeydata.skeydata_val = skey.data; replyp->skeydata.skeydata_len = skey.size; /* * Primary key */ if (pkey.data == pkeydata) { ret = __os_umalloc(dbenv, pkey.size, &replyp->pkeydata.pkeydata_val); if (ret != 0) { __os_ufree(dbenv, skey.data); __os_ufree(dbenv, pkey.data); __os_ufree(dbenv, data.data); if (key_alloc) __os_ufree(dbenv, replyp->skeydata.skeydata_val); goto err; } /* * We can set it to 2, because they cannot send the * pkey over without sending the skey over too. * So if they did send a pkey, they must have sent * the skey as well. */ key_alloc = 2; memcpy(replyp->pkeydata.pkeydata_val, pkey.data, pkey.size); } else replyp->pkeydata.pkeydata_val = pkey.data; replyp->pkeydata.pkeydata_len = pkey.size; /* * Data */ if (data.data == datadata) { ret = __os_umalloc(dbenv, data.size, &replyp->datadata.datadata_val); if (ret != 0) { __os_ufree(dbenv, skey.data); __os_ufree(dbenv, pkey.data); __os_ufree(dbenv, data.data); /* * If key_alloc is 1, just skey needs to be * freed, if key_alloc is 2, both skey and pkey * need to be freed. */ if (key_alloc--) __os_ufree(dbenv, replyp->skeydata.skeydata_val); if (key_alloc) __os_ufree(dbenv, replyp->pkeydata.pkeydata_val); goto err; } memcpy(replyp->datadata.datadata_val, data.data, data.size); } else replyp->datadata.datadata_val = data.data; replyp->datadata.datadata_len = data.size; } else {err: 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;}/* BEGIN __dbc_put_proc *//* * PUBLIC: void __dbc_put_proc __P((long, u_int32_t, u_int32_t, u_int32_t, * PUBLIC: u_int32_t, void *, u_int32_t, u_int32_t, u_int32_t, u_int32_t, u_int32_t, void *, * PUBLIC: u_int32_t, u_int32_t, __dbc_put_reply *, int *)); */void__dbc_put_proc(dbccl_id, keydlen, keydoff, keyulen, keyflags, keydata, keysize, datadlen, datadoff, dataulen, dataflags, datadata, datasize, flags, replyp, freep) long 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_put_reply *replyp; int * freep;/* END __dbc_put_proc */{ DB *dbp; DBC *dbc; DBT key, data; ct_entry *dbc_ctp; int ret; ACTIVATE_CTP(dbc_ctp, dbccl_id, CT_CURSOR); dbc = (DBC *)dbc_ctp->ct_anyp; dbp = (DB *)dbc_ctp->ct_parent->ct_anyp; memset(&key, 0, sizeof(key)); memset(&data, 0, sizeof(data)); /* Set up key and data DBT */ key.dlen = keydlen; key.ulen = keyulen; key.doff = keydoff; /* * Ignore memory related flags on server. */ key.flags = 0; if (keyflags & DB_DBT_PARTIAL) key.flags |= DB_DBT_PARTIAL; key.size = keysize; key.data = keydata; data.dlen = datadlen; data.ulen = dataulen; data.doff = datadoff; data.flags = dataflags; data.size = datasize; data.data = datadata; /* Got all our stuff, now do the put */ ret = dbc->c_put(dbc, &key, &data, flags); *freep = 0; if (ret == 0 && (flags == DB_AFTER || flags == DB_BEFORE) && dbp->type == DB_RECNO) { /* * We need to xdr_free whatever we are returning, next time. */ replyp->keydata.keydata_val = key.data; replyp->keydata.keydata_len = key.size; } else { replyp->keydata.keydata_val = NULL; replyp->keydata.keydata_len = 0; } replyp->status = ret; return;}#endif /* HAVE_RPC */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -