Exemplo n.º 1
0
int DbChannel::send_request(Dbt *request, u_int32_t nrequest,
    Dbt *response, db_timeout_t timeout, u_int32_t flags)
{
	DB_CHANNEL *dbchannel = unwrap(this);
	DB_ENV *dbenv = unwrap(dbenv_);
	DBT *dbtlist;
	int i, ret;

	ret = __os_malloc(dbenv->env, sizeof(DBT) * nrequest, &dbtlist);
	if (ret != 0) {
		DB_ERROR(dbenv_, "DbChannel::send_request", ret,
		    ON_ERROR_UNKNOWN);
		return (ret);
	}

	for (i = 0; i < (int)nrequest; i++)
		memcpy(&dbtlist[i], request[i].get_DBT(), sizeof(DBT));

	if ((ret = dbchannel->send_request(dbchannel, dbtlist, nrequest,
	    response->get_DBT(), timeout, flags)) != 0)
		DB_ERROR(dbenv_, "DbChannel::send_request", ret,
		    ON_ERROR_UNKNOWN);

	__os_free(dbenv->env, dbtlist);

	return (ret);
}
Exemplo n.º 2
0
JNIEXPORT void JNICALL Java_com_sleepycat_db_DbLsn_finalize
  (JNIEnv *jnienv, jobject jthis)
{
	DB_LSN *dblsn;

	dblsn = get_DB_LSN(jnienv, jthis);
	if (dblsn) {
		(void)__os_free(NULL, dblsn);
	}
}
Exemplo n.º 3
0
int DbChannel::send_msg(Dbt *msg, u_int32_t nmsg, u_int32_t flags)
{
	DB_CHANNEL *dbchannel = unwrap(this);
	DB_ENV *dbenv = unwrap(dbenv_);
	DBT *dbtlist;
	int i, ret;

	ret = __os_malloc(dbenv->env, sizeof(DBT) * nmsg, &dbtlist);
	if (ret != 0) {
		DB_ERROR(dbenv_, "DbChannel::send_msg", ret, ON_ERROR_UNKNOWN);
		return (ret);
	}

	for (i = 0; i < (int)nmsg; i++)
		memcpy(&dbtlist[i], msg[i].get_DBT(), sizeof(DBT));

	if ((ret = dbchannel->send_msg(dbchannel, dbtlist, nmsg, flags)) != 0)
		DB_ERROR(dbenv_, "DbChannel::send_msg", ret, ON_ERROR_UNKNOWN);

	__os_free(dbenv->env, dbtlist);

	return (ret);
}
Exemplo n.º 4
0
extern "C" ct_entry *
new_ct_ent(int *errp)
{
	time_t t;
	ct_entry *ctp, *octp;
	int ret;

	if ((ret = __os_malloc(NULL, sizeof(ct_entry), &ctp)) != 0) {
		*errp = ret;
		return (NULL);
	}
	memset(ctp, 0, sizeof(ct_entry));
	/*
	 * Get the time as ID.  We may service more than one request per
	 * second however.  If we are, then increment id value until we
	 * find an unused one.  We insert entries in LRU fashion at the
	 * head of the list.  So, if the first entry doesn't match, then
	 * we know for certain that we can use our entry.
	 */
	if ((t = time(NULL)) == -1) {
		*errp = __os_get_errno();
		__os_free(NULL, ctp);
		return (NULL);
	}
	octp = LIST_FIRST(&__dbsrv_head);
	if (octp != NULL && octp->ct_id >= t)
		t = octp->ct_id + 1;
	ctp->ct_id = t;
	ctp->ct_idle = __dbsrv_idleto;
	ctp->ct_activep = &ctp->ct_active;
	ctp->ct_origp = NULL;
	ctp->ct_refcount = 1;

	LIST_INSERT_HEAD(&__dbsrv_head, ctp, entries);
	return (ctp);
}
Exemplo n.º 5
0
JNIEXPORT jobjectArray JNICALL Java_com_sleepycat_db_xa_DbXAResource__1recover
  (JNIEnv *jnienv, jobject jthis, jint rmid, jint flags)
{
	XID *xids;
	int err;
	int total;
	int cnt;
	int i;
	int curflags;
	size_t nbytes;
	jclass xid_class;
	jmethodID mid;
	jobject obj;
	jobjectArray retval;

	COMPQUIET(jthis, NULL);
	total = 0;
	cnt = 0;
	xids = NULL;
	flags &= ~(DB_FIRST | DB_LAST | DB_NEXT);

	/* Repeatedly call __db_xa_recover to fill up an array of XIDs */
	curflags = flags | DB_FIRST;
	do {
		total += cnt;
		nbytes = sizeof(XID) * (total + 10);
		if ((err = __os_realloc(NULL, nbytes, &xids)) != 0) {
			if (xids != NULL)
				__os_free(NULL, xids);
			verify_return(jnienv, XAER_NOTA, EXCEPTION_XA);
			return (NULL);
		}
		cnt = __db_xa_recover(&xids[total], 10, rmid, curflags);
		curflags = flags | DB_NEXT;
	} while (cnt > 0);

	if (xids != NULL)
		__os_free(NULL, xids);

	if (cnt < 0) {
		verify_return(jnienv, cnt, EXCEPTION_XA);
		return (NULL);
	}

	/* Create the java DbXid array and fill it up */
	if ((xid_class = get_class(jnienv, name_DB_XID)) == NULL)
		return (NULL);
	mid = (*jnienv)->GetMethodID(jnienv, xid_class, "<init>",
				     "(I[B[B)V");
	if ((retval = (*jnienv)->NewObjectArray(jnienv, total, xid_class, 0))
	    == NULL)
		goto out;

	for (i = 0; i < total; i++) {
		jobject gtrid;
		jobject bqual;
		jsize gtrid_len;
		jsize bqual_len;

		gtrid_len = (jsize)xids[i].gtrid_length;
		bqual_len = (jsize)xids[i].bqual_length;
		gtrid = (*jnienv)->NewByteArray(jnienv, gtrid_len);
		bqual = (*jnienv)->NewByteArray(jnienv, bqual_len);
		if (gtrid == NULL || bqual == NULL)
			goto out;
		(*jnienv)->SetByteArrayRegion(jnienv, gtrid, 0, gtrid_len,
		    (jbyte *)&xids[i].data[0]);
		(*jnienv)->SetByteArrayRegion(jnienv, bqual, 0, bqual_len,
		    (jbyte *)&xids[i].data[gtrid_len]);
		if ((obj = (*jnienv)->NewObject(jnienv, xid_class, mid,
		    (jint)xids[i].formatID, gtrid, bqual)) == NULL)
			goto out;
		(*jnienv)->SetObjectArrayElement(jnienv, retval, i, obj);
	}
out:	return (retval);
}
Exemplo n.º 6
0
extern "C" void
__dbclear_ctp(ct_entry *ctp)
{
	LIST_REMOVE(ctp, entries);
	__os_free(NULL, ctp);
}