Skip to content

Commit

Permalink
Release vere-2.4 (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkova authored May 11, 2023
2 parents 72f693b + 0371107 commit 5721373
Show file tree
Hide file tree
Showing 7 changed files with 202 additions and 91 deletions.
2 changes: 1 addition & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ build --host_copt='-DC3DBG'

# Set as per-file copts as a plain --copt gets passed to third party
# dependencies which forces recompilation (slow) if you are switching between
# including/excluding a symbol define
# including/excluding a symbol define.
build:mem_dbg --per_file_copt='pkg/.*@-DU3_MEMORY_DEBUG'
build:cpu_dbg --per_file_copt='pkg/.*@-DU3_CPU_DEBUG'

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/docker-shared.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ jobs:
if: steps.build-cache.outputs.cache-hit != 'true'
run: bazel run //bazel/toolchain:x86_64-linux-musl-gcc

- name: Set pace
run: echo "${{ inputs.pace }}" > ./PACE

#
# UPLOAD TO DOCKER
#
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ defined in its own package:
- [`pkg/noun`](pkg/noun): The Nock virtual machine and snapshotting system.
- [`pkg/vere`](pkg/vere): The I/O drivers, event log, and main event loop.


## Build

See [INSTALL.md](INSTALL.md).
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3
2.4
2 changes: 1 addition & 1 deletion pkg/noun/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ u3m_water(c3_w* low_w, c3_w* hig_w)
{
u3_assert(u3R == &u3H->rod_u);

*low_w = u3a_heap(u3R);
*low_w = u3R->hat_p;
*hig_w = u3a_temp(u3R) + c3_wiseof(u3v_home);
}

Expand Down
148 changes: 97 additions & 51 deletions pkg/vere/io/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,11 @@ _http_req_kill(u3_hreq* req_u)
typedef struct _u3_hgen {
h2o_generator_t neg_u; // response callbacks
c3_o red; // ready to send
c3_o dun; // done sending
enum { //
u3_hgen_wait = 0, // more expected
u3_hgen_done = 1, // complete
u3_hgen_fail = 2 // failed
} sat_e;
u3_hbod* bod_u; // pending body
u3_hbod* nud_u; // pending free
u3_hhed* hed_u; // pending free
Expand Down Expand Up @@ -539,19 +543,42 @@ _http_seq_done(void* ptr_v)
_http_seq_unlink(seq_u);
}

static void
_http_hgen_send(u3_hgen* gen_u);

/* _http_req_timer_cb(): request timeout callback
*/
static void
_http_req_timer_cb(uv_timer_t* tim_u)
{
u3_hreq* req_u = tim_u->data;

if ( u3_rsat_plan == req_u->sat_e ) {
_http_req_kill(req_u);
req_u->sat_e = u3_rsat_ripe;
switch ( req_u->sat_e ) {
case u3_rsat_init: u3_assert(0);

case u3_rsat_plan: {
_http_req_kill(req_u);
req_u->sat_e = u3_rsat_ripe;

c3_c* msg_c = "gateway timeout";
h2o_send_error_generic(req_u->rec_u, 504, msg_c, msg_c, 0);
} break;

c3_c* msg_c = "gateway timeout";
h2o_send_error_generic(req_u->rec_u, 504, msg_c, msg_c, 0);
case u3_rsat_ripe: {
u3_hgen* gen_u = req_u->gen_u;

// inform %eyre if response was incomplete
//
if ( u3_hgen_wait == gen_u->sat_e ) {
_http_req_kill(req_u);
}

gen_u->sat_e = u3_hgen_fail;

if ( c3y == gen_u->red ) {
_http_hgen_send(gen_u);
}
} break;
}
}

Expand Down Expand Up @@ -696,19 +723,19 @@ _http_hgen_dispose(void* ptr_v)
gen_u->bod_u = 0;
}

/* _http_hgen_send(): send (some/more of a) response.
*/
static void
_http_hgen_send(u3_hgen* gen_u)
{
u3_assert( c3y == gen_u->red );

u3_hreq* req_u = gen_u->req_u;
h2o_req_t* rec_u = req_u->rec_u;

c3_w len_w;
u3_hreq* req_u = gen_u->req_u;
h2o_req_t* rec_u = req_u->rec_u;
c3_w len_w;
h2o_iovec_t* vec_u = _cttp_bods_to_vec(gen_u->bod_u, &len_w);

// not ready again until _proceed
//
u3_assert( c3y == gen_u->red );
gen_u->red = c3n;

// stash [bod_u] to free later
Expand All @@ -717,20 +744,27 @@ _http_hgen_send(u3_hgen* gen_u)
gen_u->nud_u = gen_u->bod_u;
gen_u->bod_u = 0;

if ( c3n == gen_u->dun ) {
h2o_send(rec_u, vec_u, len_w, H2O_SEND_STATE_IN_PROGRESS);
uv_timer_start(req_u->tim_u, _http_req_timer_cb, 45 * 1000, 0);
}
else {
// close connection if shutdown pending
//
u3_h2o_serv* h2o_u = req_u->hon_u->htp_u->h2o_u;
switch ( gen_u->sat_e ) {
case u3_hgen_wait: {
h2o_send(rec_u, vec_u, len_w, H2O_SEND_STATE_IN_PROGRESS);
uv_timer_start(req_u->tim_u, _http_req_timer_cb, 45 * 1000, 0);
} break;

if ( 0 != h2o_u->ctx_u.shutdown_requested ) {
rec_u->http1_is_persistent = 0;
}
case u3_hgen_done: {
// close connection if shutdown pending
//
u3_h2o_serv* h2o_u = req_u->hon_u->htp_u->h2o_u;

if ( 0 != h2o_u->ctx_u.shutdown_requested ) {
rec_u->http1_is_persistent = 0;
}

h2o_send(rec_u, vec_u, len_w, H2O_SEND_STATE_FINAL);
h2o_send(rec_u, vec_u, len_w, H2O_SEND_STATE_FINAL);
} break;

case u3_hgen_fail: {
h2o_send(rec_u, vec_u, len_w, H2O_SEND_STATE_ERROR);
} break;
}

c3_free(vec_u);
Expand All @@ -745,7 +779,7 @@ _http_hgen_stop(h2o_generator_t* neg_u, h2o_req_t* rec_u)

// response not complete, enqueue cancel
//
if ( c3n == gen_u->dun ) {
if ( u3_hgen_wait == gen_u->sat_e ) {
_http_req_kill(gen_u->req_u);
}
}
Expand All @@ -763,7 +797,7 @@ _http_hgen_proceed(h2o_generator_t* neg_u, h2o_req_t* rec_u)

gen_u->red = c3y;

if ( 0 != gen_u->bod_u || c3y == gen_u->dun ) {
if ( gen_u->bod_u || (u3_hgen_wait != gen_u->sat_e) ) {
_http_hgen_send(gen_u);
}
}
Expand All @@ -777,10 +811,9 @@ _http_start_respond(u3_hreq* req_u,
u3_noun data,
u3_noun complete)
{
// u3l_log("start");

if ( u3_rsat_plan != req_u->sat_e ) {
//u3l_log("duplicate response");
u3l_log("http: %%start not sane");
u3z(status); u3z(headers); u3z(data); u3z(complete);
return;
}

Expand Down Expand Up @@ -827,7 +860,7 @@ _http_start_respond(u3_hreq* req_u,
_http_hgen_dispose);
gen_u->neg_u = (h2o_generator_t){ _http_hgen_proceed, _http_hgen_stop };
gen_u->red = c3y;
gen_u->dun = complete;
gen_u->sat_e = ( c3y == complete ) ? u3_hgen_done : u3_hgen_wait;
gen_u->bod_u = ( u3_nul == data ) ?
0 : _cttp_bod_from_octs(u3k(u3t(data)));
gen_u->nud_u = 0;
Expand All @@ -851,39 +884,24 @@ _http_start_respond(u3_hreq* req_u,
u3z(status); u3z(headers); u3z(data); u3z(complete);
}

/* _http_continue_respond(): write a [%http-response %continue ...] to
* h2o_req_t->res
/* _http_continue_respond(): apply [%http-response %continue ...].
*/
static void
_http_continue_respond(u3_hreq* req_u,
/* u3_noun status, */
/* u3_noun headers, */
u3_noun data,
u3_noun data,
u3_noun complete)
{
// u3l_log("continue");

// XX add sequence numbers for %continue effects?
// Arvo does not (currently) guarantee effect idempotence!!

// response has not yet been started
if ( u3_rsat_ripe != req_u->sat_e ) {
// u3l_log("duplicate response");
u3l_log("http: %%continue before %%start");
u3z(data); u3z(complete);
return;
}

u3_hgen* gen_u = req_u->gen_u;

uv_timer_stop(req_u->tim_u);

// XX proposed sequence number safety check
// if ( sequence <= gen_u->sequence ) {
// return;
// }
//
// u3_assert( sequence == ++gen_u->sequence );

gen_u->dun = complete;
gen_u->sat_e = ( c3y == complete ) ? u3_hgen_done : u3_hgen_wait;

if ( u3_nul != data ) {
u3_hbod* bod_u = _cttp_bod_from_octs(u3k(u3t(data)));
Expand All @@ -909,6 +927,34 @@ _http_continue_respond(u3_hreq* req_u,
u3z(data); u3z(complete);
}

/* _http_cancel_respond(): apply [%http-response %cancel ~].
*/
static void
_http_cancel_respond(u3_hreq* req_u)
{
switch ( req_u->sat_e ) {
case u3_rsat_init: u3_assert(0);

case u3_rsat_plan: {
req_u->sat_e = u3_rsat_ripe; // XX confirm

c3_c* msg_c = "hosed";
h2o_send_error_generic(req_u->rec_u, 500, msg_c, msg_c, 0);
} break;

case u3_rsat_ripe: {
u3_hgen* gen_u = req_u->gen_u;

uv_timer_stop(req_u->tim_u);
gen_u->sat_e = u3_hgen_fail;

if ( c3y == gen_u->red ) {
_http_hgen_send(gen_u);
}
}
}
}

/* _http_rec_to_httq(): convert h2o_req_t to httq
*/
static u3_weak
Expand Down Expand Up @@ -2118,7 +2164,7 @@ _http_ef_http_server(u3_httd* htd_u,
_http_continue_respond(req_u, u3k(data), u3k(complete));
}
else if (c3y == u3r_sing_c("cancel", u3h(response))) {
u3l_log("http: %%cancel not handled yet");
_http_cancel_respond(req_u);
}
else {
u3l_log("http: strange response");
Expand Down
Loading

0 comments on commit 5721373

Please sign in to comment.