예제 #1
0
static void 
from_data_new(struct tor_conn *tc)
{
	int from, to, amnt;
	char *buf;

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

		buf = cbuf_alloc(BUFF_SZ, &cb);
		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(buf);
	}
done:
	cbuf_free(buf);
	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;
}
예제 #2
0
파일: pid.c 프로젝트: songjiguo/Monitor_ML
/* simulator ==> pid */
static int
from_data_new(ap_data *in_data)
{
	char *buf;
	cbuf_t cb;
	int amnt;
	int ret = 0;

	/* printc("from_data_new\n"); */

	buf = cbuf_alloc(BUFF_SZ, &cb);
	assert(buf);
	amnt = from_tread(cos_spd_id(), pid_torrent, cb, BUFF_SZ-1);
	if (0 == amnt) {
		/* printc("0 amnt\n"); */
		goto done;
	}
	else if (-EPIPE == amnt) {
		printc("EPIPE close connection\n");
		goto close;
	} else if (amnt < 0) {
		/* printc("read from pid_torrent %d produced %d.\n", pid_torrent, amnt); */
		goto done;
	}

	/* copy the external information here*/
	// TODO

	printc("simulator ==> pid:: %s\n", buf);

	if (buf) ret = 1;
	
done:
	cbuf_free(buf);
	return ret;
close:
	from_trelease(cos_spd_id(), pid_torrent);
	goto done;
}