diff --git a/tunnels/client/http2/helpers.h b/tunnels/client/http2/helpers.h index acc2adfd..e14a64a0 100644 --- a/tunnels/client/http2/helpers.h +++ b/tunnels/client/http2/helpers.h @@ -184,7 +184,7 @@ static http2_client_con_state_t *take_http2_connection(tunnel_t *self, int tid, if (vec_cons_size(vector) > 0) { // http2_client_con_state_t * con = *vec_cons_at(vector, round_index); - c_foreach(k, vec_cons, vector) + c_foreach(k, vec_cons, *vector) { if ((*k.ref)->childs_added < MAX_CHILD_PER_STREAM) { diff --git a/tunnels/client/http2/http2_client.c b/tunnels/client/http2/http2_client.c index ebebcc81..fff978d0 100644 --- a/tunnels/client/http2/http2_client.c +++ b/tunnels/client/http2/http2_client.c @@ -15,7 +15,7 @@ static void sendGrpcFinalData(tunnel_t *self, line_t *line, size_t stream_id) endstream_ctx->payload = buf; self->up->upStream(self->up, endstream_ctx); } -static bool trySendRequest(tunnel_t *self, http2_client_con_state_t *con, size_t stream_id,hio_t*stream_io, shift_buffer_t *buf) +static bool trySendRequest(tunnel_t *self, http2_client_con_state_t *con, size_t stream_id, hio_t *stream_io, shift_buffer_t *buf) { line_t *line = con->line; if (con == NULL) @@ -34,6 +34,11 @@ static bool trySendRequest(tunnel_t *self, http2_client_con_state_t *con, size_t context_t *req = newContext(line); req->payload = send_buf; req->src_io = stream_io; + if (!con->first_sent) + { + con->first_sent = true; + req->first = true; + } self->up->upStream(self->up, req); if (nghttp2_session_want_read(con->session) == 0 && @@ -116,7 +121,7 @@ static void flush_write_queue(http2_client_con_state_t *con) con->state = H2_SEND_HEADERS; // consumes payload - while (trySendRequest(self, con, stream->stream_id,stream->io, stream_context->payload)) + while (trySendRequest(self, con, stream->stream_id, stream->io, stream_context->payload)) ; if (con->line->chains_state[self->chain_index] == NULL) @@ -309,7 +314,7 @@ static inline void upStream(tunnel_t *self, context_t *c) con->state = H2_SEND_HEADERS; // consumes payload - while (trySendRequest(self, con, stream->stream_id,stream->io , c->payload)) + while (trySendRequest(self, con, stream->stream_id, stream->io, c->payload)) ; c->payload = NULL; destroyContext(c); @@ -318,7 +323,7 @@ static inline void upStream(tunnel_t *self, context_t *c) { if (c->init) { - http2_client_con_state_t *con = take_http2_connection(self, c->line->tid,NULL); + http2_client_con_state_t *con = take_http2_connection(self, c->line->tid, NULL); if (con->line->chains_state[self->chain_index] == NULL) { destroyContext(c); @@ -328,7 +333,7 @@ static inline void upStream(tunnel_t *self, context_t *c) while (trySendRequest(self, con, 0, NULL, NULL)) ; - http2_client_child_con_state_t *stream = create_http2_stream(con, c->line,c->src_io); + http2_client_child_con_state_t *stream = create_http2_stream(con, c->line, c->src_io); CSTATE_MUT(c) = stream; if (!ISALIVE(c)) @@ -374,7 +379,7 @@ static inline void downStream(tunnel_t *self, context_t *c) http2_client_state_t *state = STATE(self); http2_client_con_state_t *con = CSTATE(c); con->io = c->src_io; - + if (c->payload != NULL) { diff --git a/tunnels/client/http2/types.h b/tunnels/client/http2/types.h index 1b0854d5..11a59385 100644 --- a/tunnels/client/http2/types.h +++ b/tunnels/client/http2/types.h @@ -61,6 +61,7 @@ typedef struct http2_client_con_state_s int host_port; const char *scheme; bool init_sent; + bool first_sent; tunnel_t *tunnel; line_t *line; diff --git a/tunnels/server/http2/http2_server.c b/tunnels/server/http2/http2_server.c index 1d3abedb..fc2f5af5 100644 --- a/tunnels/server/http2/http2_server.c +++ b/tunnels/server/http2/http2_server.c @@ -116,7 +116,11 @@ static int on_data_chunk_recv_callback(nghttp2_session *session, context_t *stream_data = newContext(stream->line); stream_data->payload = buf; stream_data->src_io = con->io; - + if (!stream->first_sent) + { + stream->first_sent = true; + stream_data->first = true; + } stream->tunnel->upStream(stream->tunnel, stream_data); // if (hp->parsed->http_cb) // { @@ -195,7 +199,7 @@ static int on_frame_recv_callback(nghttp2_session *session, return 0; } -static bool trySendResponse(tunnel_t *self, http2_server_con_state_t *con, size_t stream_id,hio_t*stream_io, shift_buffer_t *buf) +static bool trySendResponse(tunnel_t *self, http2_server_con_state_t *con, size_t stream_id, hio_t *stream_io, shift_buffer_t *buf) { line_t *line = con->line; // http2_server_con_state_t *con = ((http2_server_con_state_t *)(((line->chains_state)[self->chain_index]))); @@ -314,7 +318,7 @@ static inline void upStream(tunnel_t *self, context_t *c) return; } - while (trySendResponse(self, con, 0,NULL, NULL)) + while (trySendResponse(self, con, 0, NULL, NULL)) ; destroyContext(c); } @@ -322,7 +326,7 @@ static inline void upStream(tunnel_t *self, context_t *c) { if (c->init) { - CSTATE_MUT(c) = create_http2_connection(self, c->line,c->src_io); + CSTATE_MUT(c) = create_http2_connection(self, c->line, c->src_io); destroyContext(c); } else if (c->fin) @@ -342,7 +346,7 @@ static inline void downStream(tunnel_t *self, context_t *c) if (c->payload != NULL) { con->state = H2_SEND_HEADERS; - while (trySendResponse(self, con, stream->stream_id,stream->io, c->payload)) + while (trySendResponse(self, con, stream->stream_id, stream->io, c->payload)) ; c->payload = NULL; destroyContext(c); @@ -359,7 +363,7 @@ static inline void downStream(tunnel_t *self, context_t *c) } else nghttp2_submit_headers(con->session, flags, stream->stream_id, NULL, NULL, 0, NULL); - while (trySendResponse(self, con, stream->stream_id,NULL, NULL)) + while (trySendResponse(self, con, stream->stream_id, NULL, NULL)) ; nghttp2_session_set_stream_user_data(con->session, stream->stream_id, NULL); diff --git a/tunnels/server/http2/types.h b/tunnels/server/http2/types.h index 9cdc40ad..a77c7fd7 100644 --- a/tunnels/server/http2/types.h +++ b/tunnels/server/http2/types.h @@ -37,7 +37,7 @@ typedef struct http2_server_child_con_state_s struct http2_server_child_con_state_s *prev, *next; char *request_path; int32_t stream_id; - + bool first_sent; line_t *parent; line_t *line; hio_t* io;