Пример #1
0
int 
tread(spdid_t spdid, td_t td, int cbid, int sz)
{
	int ret = -1, left;
	struct torrent *t;
	struct fsobj *fso;
	char *buf;

	if (tor_isnull(td)) return -EINVAL;

	LOCK();
	t = tor_lookup(td);
	if (!t) ERR_THROW(-EINVAL, done);
	assert(!tor_is_usrdef(td) || t->data);
	if (!(t->flags & TOR_READ)) ERR_THROW(-EACCES, done);

	fso = t->data;
	assert(fso->size <= fso->allocated);
	assert(t->offset <= fso->size);
	if (!fso->size) ERR_THROW(0, done);

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

	left = fso->size - t->offset;
	ret  = left > sz ? sz : left;

	assert(fso->data);
	memcpy(buf, fso->data + t->offset, ret);
	t->offset += ret;
	cbuf_free(cbid);
done:	
	UNLOCK();
	return ret;
}
Пример #2
0
int 
tread(spdid_t spdid, td_t td, int cbid, int sz)
{
	struct connection *c;
	struct torrent *t;
	char *buf;
	int ret;
	
	if (tor_isnull(td)) return -EINVAL;
	buf = cbuf2buf(cbid, sz);
	if (!buf) ERR_THROW(-EINVAL, done);

	LOCK();
	t = tor_lookup(td);
	if (!t) ERR_THROW(-EINVAL, unlock);
	assert(!tor_is_usrdef(td) || t->data);
	if (!(t->flags & TOR_READ)) ERR_THROW(-EACCES, unlock);
	c = t->data;

	lock_connection(c);
	UNLOCK();
	ret = connection_get_reply(c, buf, sz);
	unlock_connection(c);
done:	
	return ret;
unlock:
	UNLOCK();
	goto done;
}
Пример #3
0
int 
tread(spdid_t spdid, td_t td, int cbid, int sz)
{
	int ret = -1;
	struct channel_info *channel;
	struct torrent *t;
	char *buf;

	if (tor_isnull(td)) return -EINVAL;

	LOCK();
	t = tor_lookup(td);
	if (!t) ERR_THROW(-EINVAL, done);
	assert(!tor_is_usrdef(td) || t->data);
	if (!(t->flags & TOR_READ)) ERR_THROW(-EACCES, done);

	buf = cbuf2buf(cbid, sz);
	if (!buf) goto done;

	channel = (struct channel_info*)t->data;
	ret = cringbuf_consume(&channel->rb, buf, sz);
done:	
	UNLOCK();
	return ret;
}
Пример #4
0
void
trelease(spdid_t spdid, td_t td)
{
	struct torrent *t;
	struct connection *c;

	if (!tor_is_usrdef(td)) return;

	LOCK();
	t = tor_lookup(td);
	if (!t) goto done;
	c = t->data;
	lock_connection(c);
	/* wait till others release the connection */
	unlock_connection(c);
	if (c) {
		http_free_connection(c);
		/* bookkeeping */
		http_conn_cnt++;
	}
	tor_free(t);
done:
	UNLOCK();
	return;
}
Пример #5
0
void
trelease(spdid_t spdid, td_t td)
{
	struct torrent *t;

	if (!tor_is_usrdef(td)) return;
	t = tor_lookup(td);
	if (!t) goto done;
	netif_event_release(cos_spd_id());
	tor_free(t);
done:
	return;
}
Пример #6
0
int 
tread(spdid_t spdid, td_t td, int cbid, int sz)
{
	struct connection *c;
	struct torrent *t;
	char *buf;
	int ret;

	/* printc("connmgr reads https thd %d\n", cos_get_thd_id()); */
	if (tor_isnull(td)) return -EINVAL;
	buf = cbuf2buf(cbid, sz);
	if (!buf) ERR_THROW(-EINVAL, done);

	LOCK();
	t = tor_lookup(td);
	if (!t) ERR_THROW(-EINVAL, unlock);
	assert(!tor_is_usrdef(td) || t->data);
	if (!(t->flags & TOR_READ)) ERR_THROW(-EACCES, unlock);
	c = t->data;

	lock_connection(c);
	UNLOCK();

	/* // debug only */
	/* if (debug_buf && debug_amnt > 0) { */
	/* 	printc("use saved cbuf\n"); */
	/* 	memcpy(buf, debug_buf, sz); */
	/* 	ret = debug_amnt;		 */
	/* 	unlock_connection(c); */
	/* 	goto done; */
	/* } */

 	ret = connection_get_reply(c, buf, sz);

	/* // debug only */
	/* if (!debug_buf && debug_amnt == 0) { */
	/* 	if (!(debug_buf = cbuf_alloc(sz, &debug_cb))) BUG(); */
	/* 	printc("save the response cbuf\n"); */
	/* 	memcpy(debug_buf, buf, sz); */
	/* 	debug_amnt = ret; */
	/* } */

	unlock_connection(c);
done:	
	return ret;
unlock:
	UNLOCK();
	goto done;
}
Пример #7
0
void
trelease(spdid_t spdid, td_t td)
{
	struct torrent *t;
	td_t ntd;

	if (!tor_is_usrdef(td)) return;
	t = tor_lookup(td);
	if (!t) goto done;
	ntd = (td_t)t->data;
	parent_trelease(cos_spd_id(), ntd);
	tor_free(t);
done:
	return;
}
Пример #8
0
void
trelease(spdid_t spdid, td_t td)
{
	struct torrent *t;

	if (!tor_is_usrdef(td)) return;

	LOCK();
	t = tor_lookup(td);
	if (!t) goto done;
	fsobj_release((struct fsobj *)t->data);
	tor_free(t);
done:
	UNLOCK();
	return;
}
Пример #9
0
void
trelease(spdid_t spdid, td_t td)
{
	struct torrent *t;

	if (!tor_is_usrdef(td)) return;
	LOCK();
	t = tor_lookup(td);
	if (!t) goto done;
	assert(t->data);
	((struct channel_info *)t->data)->t = NULL;
	tor_free(t);
done:
	UNLOCK();
	return;
}
Пример #10
0
void
trelease(spdid_t spdid, td_t td)
{
	struct torrent *t;
	net_connection_t nc;

	if (!tor_is_usrdef(td)) return;

	NET_LOCK_TAKE();
	t = tor_lookup(td);
	if (!t) goto done;
	nc = (net_connection_t)t->data;
	if (nc) net_close(spdid, nc);
	tor_free(t);
done:
	NET_LOCK_RELEASE();
	assert(lock_contested(&net_lock) != cos_get_thd_id());
	return;
}
Пример #11
0
int 
tmerge(spdid_t spdid, td_t td, td_t td_into, char *param, int len)
{
	struct torrent *t;
	int ret = 0;

	LOCK();
	if (!tor_is_usrdef(td)) ERR_THROW(-EINVAL, done);
	t = tor_lookup(td);
	if (!t) ERR_THROW(-EINVAL, done);
	/* currently only allow deletion */
	if (td_into != td_null) ERR_THROW(-EINVAL, done);
	assert(t->data);
	((struct channel_info *)t->data)->t = NULL;
	tor_free(t);
done:
	UNLOCK();
	return ret;
}