Example #1
0
int 
twrite(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);
	memcpy(nbuf, buf, sz);
	ret = parent_twrite(cos_spd_id(), ntd, ncbid, sz);
	cbuf_free(ncbid);
done:
	return ret;
}
Example #2
0
int 
twrite(spdid_t spdid, td_t td, int cbid, int sz)
{
	td_t ntd;
	struct torrent *t;
	int ret = -1;

	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;
	ret = parent_twrite(cos_spd_id(), ntd, cbid, sz);
done:
	return ret;
}
Example #3
0
static err_t cos_net_stack_send(struct netif *ni, struct pbuf *p, struct ip_addr *ip)
{
	int tot_len = 0, sz;
	char *buff;
	cbuf_t cb;

	/* assuming the net lock is taken here */

	assert(p && p->ref == 1);
	assert(p->type == PBUF_RAM);
	buff = cbuf_alloc(MTU, &cb);
	assert(buff);
	while (p) {
		if (p->len + tot_len > MTU) BUG();
		memcpy(buff + tot_len, p->payload, p->len);
		tot_len += p->len;

#ifdef TCP_SEND_COPY
#ifdef TEST_TIMING
		if ((p->type == PBUF_REF || p->type == PBUF_ROM)) {
			struct packet_queue *pq;
			pq = net_packet_pq(p->payload);
			timing_record(SEND, pq->ts_start);
		}
#endif
#endif
		assert(p->type != PBUF_POOL);
		assert(p->ref == 1);
		p = p->next;
	}

	
	sz = parent_twrite(cos_spd_id(), ip_td, cb, tot_len);
	if (sz <= 0) {
		printc("<<transmit returns %d -> %d>>\n", sz, tot_len);
	}
	tcp_twrite_cnt++;
	assert(sz > 0);
	cbuf_free(buff);
	
	/* cannot deallocate packets here as we might need to
	 * retransmit them. */
	return ERR_OK;
}