Example #1
0
static int cos_net_evt_loop(void)
{
	int alloc_sz = MTU;
	char *data;
	cbuf_t cb;

	assert(event_thd > 0);
	ip_td = parent_tsplit(cos_spd_id(), td_root, "", 0, TOR_ALL, -1);
	assert(ip_td > 0);
	printc("network uc %d starting...\n", cos_get_thd_id());
	alloc_sz = sizeof(struct cos_array) + MTU;
	while (1) {
		int sz;

		data = cbuf_alloc(alloc_sz, &cb);
		assert(data);
		/* printc("tnet_tip_tread (thd %d)\n", cos_get_thd_id()); */
		sz = parent_tread(cos_spd_id(), ip_td, cb, alloc_sz);
		tcp_tread_cnt++;
		assert(sz > 0);
		cos_net_interrupt(data, sz);
		assert(lock_contested(&net_lock) != cos_get_thd_id());
		cbuf_free(data);
	}

	return 0;
}
Example #2
0
int 
tread(spdid_t spdid, td_t td, int cbid, int sz)
{
	td_t ntd;
	struct torrent *t;
	char *buf, *nbuf;
	int ret = -1;
	cbuf_t ncbid;

	if (tor_isnull(td)) return -EINVAL;
	t = tor_lookup(td);
	if (!t)                      ERR_THROW(-EINVAL, done);
	if (!(t->flags & TOR_WRITE)) ERR_THROW(-EACCES, done);

	assert(t->data);
	ntd = (td_t)t->data;

	buf = cbuf2buf(cbid, sz);
	if (!buf) ERR_THROW(-EINVAL, done);

	nbuf = cbuf_alloc(sz, &ncbid);
	assert(nbuf);
	ret = parent_tread(cos_spd_id(), ntd, ncbid, sz);
	if (ret < 0) goto free;
	memcpy(buf, nbuf, ret);
free:
	cbuf_free(ncbid);
done:
	return ret;
}