Exemple #1
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;
}
static int connection_process_requests(struct connection *c, char *req, int req_sz,
				char *resp, int resp_sz)
{
	/* FIXME: close connection on error? */
	if (connection_parse_requests(c, req, req_sz)) return -EINVAL;
	return connection_get_reply(c, resp, resp_sz);
}
int content_read(spdid_t spdid, long connection_id, char *buff, int sz)
{
	struct connection *c;
	
//	printc("HTTP read");

	c = cos_map_lookup(&conn_map, connection_id);
	if (NULL == c) return -EINVAL;
	
	return connection_get_reply(c, buff, sz);
}
Exemple #4
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;
}