Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: unify {input,output}_state into Io_state #142

Merged
merged 2 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/client_connection.ml
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ let rec _next_read_operation t =
let respd = current_respd_exn t in
match Respd.input_state respd with
| Wait -> `Yield
| Ready -> Reader.next t.reader
| Ready -> Reader.next t.reader
| Complete -> _final_read_operation_for t respd
)

Expand All @@ -217,7 +217,7 @@ and _final_read_operation_for t respd =
Reader.next t.reader;
) else (
match Respd.output_state respd with
| Waiting | Ready -> `Yield
| Wait | Ready -> `Yield
| Complete ->
match Reader.next t.reader with
| `Error _ | `Read as operation ->
Expand Down Expand Up @@ -271,7 +271,7 @@ let rec _next_write_operation t =
) else (
let respd = current_respd_exn t in
match Respd.output_state respd with
| Waiting -> `Yield
| Wait -> `Yield
| Ready ->
Respd.flush_request_body respd;
Writer.next t.writer
Expand Down
File renamed without changes.
4 changes: 0 additions & 4 deletions lib/output_state.ml

This file was deleted.

2 changes: 1 addition & 1 deletion lib/reqd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ let error_code t =
let persistent_connection t =
t.persistent

let input_state t : Input_state.t =
let input_state t : Io_state.t =
match t.response_state with
| Upgrade _ -> Ready
| _ ->
Expand Down
6 changes: 3 additions & 3 deletions lib/respd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ let close_response_body t =
Body.Reader.close response_body
| Upgraded _ -> t.state <- Closed

let input_state t : Input_state.t =
let input_state t : Io_state.t =
match t.state with
| Uninitialized
| Awaiting_response -> Ready
Expand All @@ -108,14 +108,14 @@ let input_state t : Input_state.t =
| Upgraded _
| Closed -> Complete

let output_state { request_body; state; writer; _ } : Output_state.t =
let output_state { request_body; state; writer; _ } : Io_state.t =
match state with
| Upgraded _ ->
(* XXX(anmonteiro): Connections that have been upgraded "require output"
* forever, but outside the HTTP layer, meaning they're permanently
* "yielding". For now they need to be explicitly shutdown in order to
* transition the response descriptor to the `Closed` state. *)
Waiting
Wait
| state ->
if Writer.is_closed writer then Complete
else if state = Uninitialized || Body.Writer.requires_output request_body
Expand Down
4 changes: 2 additions & 2 deletions lib/response_state.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ type t =
| Streaming of Response.t * Body.Writer.t
| Upgrade of Response.t * (unit -> unit)

let output_state t ~writer : Output_state.t =
let output_state t ~writer : Io_state.t =
match t with
| Fixed _ -> Complete
| Waiting ->
if Serialize.Writer.is_closed writer then Complete
else Waiting
else Wait
| Streaming(_, response_body) ->
if Serialize.Writer.is_closed writer then Complete
else if Body.Writer.requires_output response_body
Expand Down
8 changes: 4 additions & 4 deletions lib/server_connection.ml
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ let rec _next_read_operation t =
and there are still bytes remaining to be read in the request body.
*)
Reader.next t.reader
| Waiting | Ready ->
| Wait | Ready ->
(* `Wait` signals that we should add backpressure to the read channel,
* meaning the reader should tell the runtime to yield.
*
Expand All @@ -281,7 +281,7 @@ and _final_read_operation_for t reqd =
Reader.next t.reader;
) else
match Reqd.output_state reqd with
| Waiting | Ready -> `Yield
| Wait | Ready -> `Yield
| Complete ->
(* The "final read" operation for a request descriptor that is
* `Complete` from both input and output perspectives needs to account
Expand Down Expand Up @@ -340,7 +340,7 @@ let rec _next_write_operation t =
Writer.next t.writer
| Error { response_state; _ } ->
match Response_state.output_state response_state ~writer:t.writer with
| Waiting -> `Yield
| Wait -> `Yield
| Ready ->
flush_response_error_body response_state;
Writer.next t.writer
Expand All @@ -350,7 +350,7 @@ let rec _next_write_operation t =
) else (
let reqd = current_reqd_exn t in
match Reqd.output_state reqd with
| Waiting -> Writer.next t.writer
| Wait -> Writer.next t.writer
| Ready ->
Reqd.flush_response_body reqd;
Writer.next t.writer
Expand Down