示例#1
0
CSTUB_FN(int, tmerge)(struct usr_inv_cap *uc,
                      spdid_t spdid, td_t td, td_t td_into, char *param, int len)
{
    int ret;
    long fault = 0;
    struct __sg_tmerge_data *d;
    cbuf_t cb;
    int sz = len + sizeof(struct __sg_tmerge_data);

    assert(param && len > 0);
    assert(param[len-1] == '\0');

    d = cbuf_alloc_ext(sz, &cb, CBUF_TMEM);
    if (!d) return -1;

    d->td = td;
    d->td_into = td_into;
    d->len[0] = 0;
    d->len[1] = len;
    memcpy(&d->data[0], param, len);

    CSTUB_INVOKE(ret, fault, uc, 3, spdid, cb, sz);

    cbuf_free(cb);
    return ret;
}
示例#2
0
CSTUB_FN(td_t, tsplit)(struct usr_inv_cap *uc,
                       spdid_t spdid, td_t tid, char * param,
                       int len, tor_flags_t tflags, long evtid)
{
    long fault = 0;
    td_t ret;
    struct __sg_tsplit_data *d;
    cbuf_t cb;
    int sz = len + sizeof(struct __sg_tsplit_data);

    assert(param && len >= 0);
    assert(param[len] == '\0');

    d = cbuf_alloc_ext(sz, &cb, CBUF_TMEM);
    if (!d) return -6;

    d->tid    = tid;
    d->tflags = tflags;
    d->evtid  = evtid;
    d->len[0] = 0;
    d->len[1] = len;
    memcpy(&d->data[0], param, len + 1);

    CSTUB_INVOKE(ret, fault, uc, 3, spdid, cb, sz);

    cbuf_free(cb);
    return ret;
}
示例#3
0
CSTUB_FN(int, twmeta)(struct usr_inv_cap *uc,
                      spdid_t spdid, td_t td, const char *key,
                      unsigned int klen, const char *val, unsigned int vlen)
{
    int ret;
    long fault = 0;
    cbuf_t cb;
    int sz = sizeof(struct __sg_twmeta_data) + klen + vlen + 1;
    struct __sg_twmeta_data *d;

    assert(key && val && klen > 0 && vlen > 0);
    assert(key[klen] == '\0' && val[vlen] == '\0' && sz <= PAGE_SIZE);

    d = cbuf_alloc_ext(sz, &cb, CBUF_TMEM);
    if (!d) assert(0); //return -1;

    d->td = td;
    d->klen = klen;
    d->vlen = vlen;
    memcpy(&d->data[0], key, klen + 1);
    memcpy(&d->data[klen + 1], val, vlen + 1);

    CSTUB_INVOKE(ret, fault, uc, 3, spdid, cb, sz);

    cbuf_free(cb);
    return ret;
}
示例#4
0
CSTUB_FN(int, trmeta)(struct usr_inv_cap *uc,
                      spdid_t spdid, td_t td, const char *key,
                      unsigned int klen, char *retval, unsigned int max_rval_len)
{
    int ret;
    long fault = 0;
    cbuf_t cb;
    int sz = sizeof(struct __sg_trmeta_data) + klen + max_rval_len + 1;
    struct __sg_trmeta_data *d;

    assert(key && retval && klen > 0 && max_rval_len > 0);
    assert(key[klen] == '\0' && sz <= PAGE_SIZE);

    d = cbuf_alloc_ext(sz, &cb, CBUF_TMEM);
    if (!d) return -1;

    d->td = td;
    d->klen = klen;
    d->retval_len = max_rval_len;
    memcpy(&d->data[0], key, klen + 1);

    CSTUB_INVOKE(ret, fault, uc, 3, spdid, cb, sz);

    if (ret >= 0) {
        if ((unsigned int)ret > max_rval_len) { // as ret >= 0, cast it to unsigned int to omit compiler warning
            cbuf_free(cb);
            return -EIO;
        }
        memcpy(retval, &d->data[klen + 1], ret + 1);
    }
    cbuf_free(cb);
    return ret;
}
示例#5
0
文件: cbufc.c 项目: georgit/Composite
void unit_cbuf(cbuf_t cbuf, int sz)
{
	char *c = cbuf2buf(cbuf, sz);
	cbuf_t cb;
	char *addr;

	assert(c);
	assert(c[0] == '_');

	addr = cbuf_alloc_ext(sz, &cb, CBUF_TMEM);
	cbuf_free(cb);
	cbuf_free(cbuf);
}
示例#6
0
static void 
from_data_new(struct tor_conn *tc)
{
	int from, to, amnt;
	char *buf;
	cbuf_t cb;

	from = tc->from;
	to   = tc->to;
	while (1) {
		int ret;

		buf = cbuf_alloc_ext(BUFF_SZ, &cb, CBUF_TMEM);
		assert(buf);
		amnt = from_tread(cos_spd_id(), from, cb, BUFF_SZ-1);
		if (0 == amnt) break;
		else if (-EPIPE == amnt) {
			goto close;
		} else if (amnt < 0) {
			printc("read from fd %d produced %d.\n", from, amnt);
			BUG();
		}
		assert(amnt <= BUFF_SZ);
		if (amnt != (ret = twrite(cos_spd_id(), to, cb, amnt))) {
			printc("conn_mgr: write failed w/ %d on fd %d\n", ret, to);
			goto close;

		}
		cbuf_free(cb);
	}
done:
	cbuf_free(cb);
	return;
close:
	mapping_remove(from, to, tc->feid, tc->teid);
	from_trelease(cos_spd_id(), from);
	trelease(cos_spd_id(), to);
	assert(tc->feid && tc->teid);
	evt_put(tc->feid);
	evt_put(tc->teid);
	goto done;
}
示例#7
0
int __attribute__((format(printf,1,2))) printc(char *fmt, ...)
{
    static td_t tor = 0;
    char *s;
    va_list arg_ptr;
    int ret;
    cbuf_t cb = cbuf_null();

    if (!tor) tor = printt_init();

    s = cbuf_alloc_ext(4096, &cb, CBUF_TMEM);
    assert(s);
    va_start(arg_ptr, fmt);
    ret = vsnprintf(s, 4096, fmt, arg_ptr);
    va_end(arg_ptr);
    print_twrite(cos_spd_id(), tor, cb, ret);
    cbuf_free(cb);

    return ret;
}
示例#8
0
static int connection_get_reply(struct connection *c, char *resp, int resp_sz)
{
	struct http_request *r;
	int used = 0;

	/* 
	 * Currently, this doesn't do anything interesting.  In the
	 * future it will call the content provider and get the
	 * (ready) response.
	 */
	r = c->pending_reqs;
	if (NULL == r) return 0;
	while (r) {
		struct http_request *next;
		char *local_resp;
		cbuf_t cb;
		int consumed, ret, local_resp_sz;

		assert(r->c == c);
		if (r->flags & HTTP_REQ_PENDING) break;
		assert(r->flags & HTTP_REQ_PROCESSED);
		assert(r->content_id >= 0);

		/* Previously saved response? */
		if (NULL != r->resp.resp) {
			local_resp = r->resp.resp;
			local_resp_sz = r->resp.resp_len;
		} else {
			int sz;
			/* Make the request to the content
			 * component */
			sz         = resp_sz - used;
			local_resp = cbuf_alloc_ext(sz, &cb, CBUF_TMEM);
			if (!local_resp) BUG();

			ret = server_tread(cos_spd_id(), r->content_id, cb, sz);
			if (ret < 0) {
				cbuf_free(cb);
				printc("https get reply returning %d.\n", ret);
				return ret;
			}
			local_resp_sz = ret;
		}

		/* no more data */
		if (local_resp_sz == 0) {
			cbuf_free(cb);
			break;
		}

		/* If the header and data couldn't fit into the
		 * provided buffer, then we need to save the response,
		 * so that we can send it out later... */
		if (http_get_header(resp+used, resp_sz-used, local_resp_sz, &consumed)) {
			if (NULL == r->resp.resp) {
				char *save;
			
				save = malloc(local_resp_sz);
				assert(save);
				assert(local_resp);
				memcpy(save, local_resp, local_resp_sz);
				cbuf_free(cb);
				local_resp = NULL;

				r->resp.resp = save;
				r->resp.resp_len = local_resp_sz;
			}
			if (0 == used) {
				printc("https: could not allocate either header or response of sz %d:%s\n", local_resp_sz, local_resp);
				if (local_resp) cbuf_free(cb);
				return -ENOMEM;
			}
			break;
		}

		memcpy(resp+used+consumed, local_resp, local_resp_sz);
		
		assert(local_resp);
		cbuf_free(cb);
		local_resp = NULL;

		used += local_resp_sz + consumed;
		next = r->next;
		/* bookkeeping */
		http_req_cnt++;

		http_free_request(r);
		r = c->pending_reqs;
		assert(r == next || NULL == r);
	}

	return used;
}