diff --git a/pkg/urbit/include/vere/vere.h b/pkg/urbit/include/vere/vere.h index de8379d3ba..b47dd50d09 100644 --- a/pkg/urbit/include/vere/vere.h +++ b/pkg/urbit/include/vere/vere.h @@ -40,7 +40,7 @@ /* u3_moor_poke: poke callback function. */ - typedef void (*u3_moor_poke)(void*, u3_atom); + typedef void (*u3_moor_poke)(void*, c3_d, c3_y*); /* u3_moor_bail: bailout callback function. */ @@ -407,7 +407,6 @@ */ typedef struct _u3_writ { struct timeval tim_u; // time enqueued - u3_atom mat; // serialized struct _u3_writ* nex_u; // next in queue u3_writ_type typ_e; // type-tagged union { // @@ -1169,10 +1168,10 @@ void u3_newt_decode(u3_moat* mot_u, c3_y* buf_y, c3_d len_d); - /* u3_newt_write(): write atom to stream; free atom. + /* u3_newt_send(): write buffer to stream. */ void - u3_newt_write(u3_mojo* moj_u, u3_atom mat); + u3_newt_send(u3_mojo* moj_u, c3_d len_d, c3_y* byt_y); /* u3_newt_read_sync(): start reading; multiple msgs synchronous. */ diff --git a/pkg/urbit/vere/lord.c b/pkg/urbit/vere/lord.c index fef5584c5d..2fc2762ba1 100644 --- a/pkg/urbit/vere/lord.c +++ b/pkg/urbit/vere/lord.c @@ -652,14 +652,12 @@ _lord_plea_work(u3_lord* god_u, u3_noun dat) /* _lord_on_plea(): handle plea from serf. */ static void -_lord_on_plea(void* ptr_v, u3_noun mat) +_lord_on_plea(void* ptr_v, c3_d len_d, c3_y* byt_y) { u3_lord* god_u = ptr_v; - u3_noun jar = u3ke_cue(mat); - u3_noun tag, dat; + u3_noun tag, dat, jar = u3ke_cue(u3i_bytes(len_d, byt_y)); if ( c3n == u3r_cell(jar, &tag, &dat) ) { - u3m_p("jar", jar); return _lord_plea_foul(god_u, 0, jar); } @@ -706,64 +704,62 @@ _lord_writ_new(u3_lord* god_u) return wit_u; } -/* _lord_writ_jam(): serialize writ. +/* _lord_writ_make(): cons writ. */ -static void -_lord_writ_jam(u3_lord* god_u, u3_writ* wit_u) +static u3_noun +_lord_writ_make(u3_lord* god_u, u3_writ* wit_u) { - if ( 0 == wit_u->mat ) { - u3_noun msg; + u3_noun msg; - switch ( wit_u->typ_e ) { - default: c3_assert(0); + switch ( wit_u->typ_e ) { + default: c3_assert(0); - case u3_writ_work: { - u3_noun mil = u3i_words(1, &wit_u->wok_u.egg_u->mil_w); - msg = u3nt(c3__work, mil, u3k(wit_u->wok_u.job)); - } break; + case u3_writ_work: { + u3_noun mil = u3i_words(1, &wit_u->wok_u.egg_u->mil_w); + msg = u3nt(c3__work, mil, u3k(wit_u->wok_u.job)); + } break; - case u3_writ_peek: { - msg = u3nc(c3__peek, u3nq(0, // XX support timeouts - u3k(wit_u->pek_u->now), - u3k(wit_u->pek_u->gan), - u3k(wit_u->pek_u->ful))); - } break; + case u3_writ_peek: { + msg = u3nc(c3__peek, u3nq(0, // XX support timeouts + u3k(wit_u->pek_u->now), + u3k(wit_u->pek_u->gan), + u3k(wit_u->pek_u->ful))); + } break; - case u3_writ_play: { - u3_fact* tac_u = wit_u->fon_u.ext_u; - c3_d eve_d = tac_u->eve_d; - u3_noun lit = u3_nul; + case u3_writ_play: { + u3_fact* tac_u = wit_u->fon_u.ext_u; + c3_d eve_d = tac_u->eve_d; + u3_noun lit = u3_nul; - while ( tac_u ) { - lit = u3nc(u3k(tac_u->job), lit); - tac_u = tac_u->nex_u; - } + while ( tac_u ) { + lit = u3nc(u3k(tac_u->job), lit); + tac_u = tac_u->nex_u; + } - msg = u3nt(c3__play, u3i_chubs(1, &eve_d), u3kb_flop(lit)); + msg = u3nt(c3__play, u3i_chubs(1, &eve_d), u3kb_flop(lit)); - } break; + } break; - case u3_writ_save: { - msg = u3nt(c3__live, c3__save, u3i_chubs(1, &god_u->eve_d)); - } break; + case u3_writ_save: { + msg = u3nt(c3__live, c3__save, u3i_chubs(1, &god_u->eve_d)); + } break; - case u3_writ_cram: { - msg = u3nt(c3__live, c3__cram, u3i_chubs(1, &god_u->eve_d)); - } break; + case u3_writ_cram: { + msg = u3nt(c3__live, c3__cram, u3i_chubs(1, &god_u->eve_d)); + } break; - case u3_writ_pack: { - msg = u3nt(c3__live, c3__pack, u3_nul); - } break; + case u3_writ_pack: { + msg = u3nt(c3__live, c3__pack, u3_nul); + } break; - case u3_writ_exit: { - // requested exit code is always 0 - // - msg = u3nt(c3__live, c3__exit, 0); - } break; - } - - wit_u->mat = u3ke_jam(msg); + case u3_writ_exit: { + // requested exit code is always 0 + // + msg = u3nt(c3__live, c3__exit, 0); + } break; } + + return msg; } /* _lord_writ_send(): send writ to serf. @@ -778,9 +774,17 @@ _lord_writ_send(u3_lord* god_u, u3_writ* wit_u) god_u->inn_u.bal_f = _lord_bail_noop; } - _lord_writ_jam(god_u, wit_u); - u3_newt_write(&god_u->inn_u, wit_u->mat); - wit_u->mat = 0; + { + u3_noun jar = _lord_writ_make(god_u, wit_u); + u3_noun mat = u3ke_jam(jar); + c3_w len_w = u3r_met(3, mat); + c3_y* byt_y = c3_malloc(len_w); + + u3r_bytes(0, len_w, byt_y, mat); + u3_newt_send(&god_u->inn_u, len_w, byt_y); + + u3z(mat); + } } /* _lord_writ_plan(): enqueue a writ and send. diff --git a/pkg/urbit/vere/newt.c b/pkg/urbit/vere/newt.c index e7cfe2be50..3b349a46cd 100644 --- a/pkg/urbit/vere/newt.c +++ b/pkg/urbit/vere/newt.c @@ -70,8 +70,7 @@ _newt_meat_plan(u3_moat* mot_u, u3_meat* met_u) static void _newt_meat_poke(u3_moat* mot_u, u3_meat* met_u) { - u3_noun mat = u3i_bytes((c3_w)met_u->len_d, met_u->hun_y); - mot_u->pok_f(mot_u->ptr_v, mat); + mot_u->pok_f(mot_u->ptr_v, met_u->len_d, met_u->hun_y); c3_free(met_u); } @@ -388,7 +387,8 @@ u3_newt_moat_info(u3_moat* mot_u) typedef struct _n_req { uv_write_t wri_u; u3_mojo* moj_u; - c3_y buf_y[0]; + c3_y* buf_y; + c3_y len_y[8]; } n_req; /* _newt_write_cb(): generic write callback. @@ -399,6 +399,7 @@ _newt_write_cb(uv_write_t* wri_u, c3_i sas_i) n_req* req_u = (n_req*)wri_u; u3_mojo* moj_u = req_u->moj_u; + c3_free(req_u->buf_y); c3_free(req_u); if ( 0 != sas_i ) { @@ -435,35 +436,37 @@ u3_newt_mojo_stop(u3_mojo* moj_u, u3_moor_bail bal_f) uv_close((uv_handle_t*)&moj_u->pyp_u, _mojo_stop_cb); } -/* u3_newt_write(): write atom to stream; free atom. +/* u3_newt_send(): write buffer to stream. */ void -u3_newt_write(u3_mojo* moj_u, u3_atom mat) +u3_newt_send(u3_mojo* moj_u, c3_d len_d, c3_y* byt_y) { - c3_w len_w = u3r_met(3, mat); - n_req* req_u = c3_malloc(8 + len_w + sizeof(*req_u)); + n_req* req_u = c3_malloc(sizeof(*req_u)); req_u->moj_u = moj_u; + req_u->buf_y = byt_y; - // write header; c3_d is futureproofing + // write header // - req_u->buf_y[0] = ((len_w >> 0) & 0xff); - req_u->buf_y[1] = ((len_w >> 8) & 0xff); - req_u->buf_y[2] = ((len_w >> 16) & 0xff); - req_u->buf_y[3] = ((len_w >> 24) & 0xff); - req_u->buf_y[4] = req_u->buf_y[5] = req_u->buf_y[6] = req_u->buf_y[7] = 0; - - // write payload - // - u3r_bytes(0, len_w, req_u->buf_y + 8, mat); - u3z(mat); + req_u->len_y[0] = ( len_d & 0xff); + req_u->len_y[1] = ((len_d >> 8) & 0xff); + req_u->len_y[2] = ((len_d >> 16) & 0xff); + req_u->len_y[3] = ((len_d >> 24) & 0xff); + req_u->len_y[4] = ((len_d >> 32) & 0xff); + req_u->len_y[5] = ((len_d >> 40) & 0xff); + req_u->len_y[6] = ((len_d >> 48) & 0xff); + req_u->len_y[7] = ((len_d >> 56) & 0xff); { - uv_buf_t buf_u = uv_buf_init((c3_c*)req_u->buf_y, 8 + len_w); + uv_buf_t buf_u[2] = { + uv_buf_init((c3_c*)req_u->len_y, 8), + uv_buf_init((c3_c*)req_u->buf_y, len_d) + }; + c3_i sas_i; if ( 0 != (sas_i = uv_write(&req_u->wri_u, (uv_stream_t*)&moj_u->pyp_u, - &buf_u, 1, + buf_u, 2, _newt_write_cb)) ) { c3_free(req_u); diff --git a/pkg/urbit/worker/main.c b/pkg/urbit/worker/main.c index d7060d6b44..84baa65e47 100644 --- a/pkg/urbit/worker/main.c +++ b/pkg/urbit/worker/main.c @@ -42,7 +42,14 @@ _cw_serf_fail(void* vod_p, const c3_c* wut_c) static void _cw_serf_send(u3_noun pel) { - u3_newt_write(&out_u, u3ke_jam(pel)); + u3_noun mat = u3ke_jam(pel); + c3_d len_w = u3r_met(3, mat); + c3_y* byt_y = c3_malloc(len_w); + + u3r_bytes(0, len_w, byt_y, mat); + u3_newt_send(&out_u, len_w, byt_y); + + u3z(mat); } /* _cw_serf_send_slog(): send hint output (hod is [priority tank]). @@ -64,11 +71,11 @@ _cw_serf_send_stdr(c3_c* str_c) /* _cw_serf_writ(): */ static void -_cw_serf_writ(void* vod_p, u3_noun mat) +_cw_serf_writ(void* vod_p, c3_d len_d, c3_y* byt_y) { - u3_noun ret; + u3_noun ret, jar = u3ke_cue(u3i_bytes(len_d, byt_y)); - if ( c3n == u3_serf_writ(&u3V, u3ke_cue(mat), &ret) ) { + if ( c3n == u3_serf_writ(&u3V, jar, &ret) ) { _cw_serf_fail(0, "bad jar"); } else {