/* pid ==> simulator */ static void to_data_new(ap_data *out_data) { int amnt, ret; char *buf; cbuf_t cb; /* printc("to_data_new\n"); */ if (!(buf = cbuf_alloc(BUFF_SZ, &cb))) BUG(); static int pid2out = 20; /* prepare the information to be sent simulator here */ // TODO: /* char tmpstr[1024]; */ /* char *test_str = tmpstr; */ /* sprintf(test_str, "%d", pid2out++); */ char *test_str = "fake msg from PID controller\n"; memcpy(buf, test_str, strlen(test_str)+1); amnt = strlen(test_str); if (amnt != (ret = from_twrite(cos_spd_id(), pid_torrent, cb, amnt))) { printc("write failed w/ %d of %d\n", ret, amnt); goto close; } printc("pid ==> simulator:: %s\n", buf); memset(buf, 0, strlen(test_str)+1); done: cbuf_free(buf); return; close: from_trelease(cos_spd_id(), pid_torrent); goto done; }
static void to_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; if (!(buf = cbuf_alloc(BUFF_SZ, &cb))) BUG(); amnt = tread(cos_spd_id(), to, 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 = from_twrite(cos_spd_id(), from, cb, amnt))) { printc("conn_mgr: write failed w/ %d of %d on fd %d\n", ret, amnt, 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; }