Skip to content

Commit

Permalink
adapt to Eio.Net interface changes
Browse files Browse the repository at this point in the history
  • Loading branch information
avsm committed May 29, 2023
1 parent 02fce6a commit dfdd8f2
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 29 deletions.
4 changes: 2 additions & 2 deletions lib/gluten/eio/gluten_eio.ml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ module IO_loop = struct
-> read_buffer_size:int
-> cancel:unit Promise.t
-> t
-> #Eio.Flow.two_way
-> #Eio.Net.stream_socket
-> unit
=
fun (module Runtime) ~read_buffer_size ~cancel t socket ->
Expand Down Expand Up @@ -182,7 +182,7 @@ end
module Client = struct
type t =
{ connection : Gluten.Client.t
; socket : Eio.Flow.two_way
; socket : Eio.Net.stream_socket
; shutdown_reader : unit -> unit
; shutdown_complete : unit Promise.t
}
Expand Down
8 changes: 4 additions & 4 deletions lib/gluten/eio/gluten_eio.mli
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module Server : sig
-> protocol:'t Gluten.runtime
-> 't
-> Eio.Net.Sockaddr.stream
-> Eio.Flow.two_way
-> Eio.Net.stream_socket
-> unit

val create_upgradable_connection_handler :
Expand All @@ -46,7 +46,7 @@ module Server : sig
-> request_handler:
(Eio.Net.Sockaddr.stream -> 'reqd Gluten.Server.request_handler)
-> Eio.Net.Sockaddr.stream
-> Eio.Flow.two_way
-> Eio.Net.stream_socket
-> unit
end

Expand All @@ -58,11 +58,11 @@ module Client : sig
-> read_buffer_size:int
-> protocol:'t Gluten.runtime
-> 't
-> Eio.Flow.two_way
-> Eio.Net.stream_socket
-> t

val upgrade : t -> Gluten.impl -> unit
val shutdown : t -> unit Eio.Promise.t
val is_closed : t -> bool
val socket : t -> Eio.Flow.two_way
val socket : t -> Eio.Net.stream_socket
end
4 changes: 2 additions & 2 deletions lib/h2/eio/h2_eio.mli
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module Server : sig
-> error_handler:
(Eio.Net.Sockaddr.stream -> H2.Server_connection.error_handler)
-> Eio.Net.Sockaddr.stream
-> Eio.Flow.two_way
-> Eio.Net.stream_socket
-> unit
end

Expand All @@ -53,7 +53,7 @@ module Client : sig
(H2.Request.t -> (H2.Client_connection.response_handler, unit) result)
-> sw:Eio.Switch.t
-> error_handler:H2.Client_connection.error_handler
-> Eio.Flow.two_way
-> Eio.Net.stream_socket
-> t

val request :
Expand Down
4 changes: 2 additions & 2 deletions lib/httpaf/eio/httpaf_eio.mli
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module Server : sig
-> request_handler : (Eio.Net.Sockaddr.stream -> Httpaf.Reqd.t Gluten.reqd -> unit)
-> error_handler : (Eio.Net.Sockaddr.stream -> Httpaf.Server_connection.error_handler)
-> Eio.Net.Sockaddr.stream
-> Eio.Flow.two_way
-> Eio.Net.stream_socket
-> unit
end

Expand All @@ -50,7 +50,7 @@ module Client : sig
}

val create_connection
: ?config:Httpaf.Config.t -> sw:Eio.Switch.t -> Eio.Flow.two_way -> t
: ?config:Httpaf.Config.t -> sw:Eio.Switch.t -> Eio.Net.stream_socket -> t

val request
: t
Expand Down
2 changes: 2 additions & 0 deletions lib/tls/eio/tls_eio.ml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ end

type t = <
Eio.Flow.two_way;
close : unit;
t : Raw.t;
>

Expand All @@ -213,6 +214,7 @@ let of_t t =
method read_into = Raw.read t
method copy = Raw.copy_from t
method shutdown = Raw.shutdown t
method close = Raw.close_tls t
method t = t
end

Expand Down
2 changes: 1 addition & 1 deletion lib/tls/eio/tls_eio.mli
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ exception Tls_alert of Tls.Packet.alert_type
(** [Tls_failure] exception while processing incoming data *)
exception Tls_failure of Tls.Engine.failure

type t = private < Eio.Flow.two_way; .. >
type t = private < Eio.Flow.two_way; close : unit; .. >

(** {2 Constructors} *)

Expand Down
23 changes: 5 additions & 18 deletions src/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,7 @@ module H2_handler = struct
| `Not_found ->
Reqd.respond_with_string reqd (Response.create `Not_found) "Not found"

let error_handler :
Eio.Net.Sockaddr.stream ->
?request:H2.Request.t ->
_ ->
(Headers.t -> Body.Writer.t) ->
unit =
fun _client_address ?request:_ _error start_response ->
let error_handler _client_address ?request:_ _error start_response =
let response_body = start_response Headers.empty in
Body.Writer.close response_body
end
Expand All @@ -84,8 +78,7 @@ module H1_handler = struct
| s -> Some s
| exception _ -> None

let request_handler : Eio.Net.Sockaddr.stream -> Reqd.t Gluten.reqd -> unit =
fun _client_address { Gluten.reqd; _ } ->
let request_handler _client_address { Gluten.reqd; _ } =
let request = Reqd.request reqd in
Eio.traceln "HTTP1 %a" Request.pp_hum request;
let response_content_type =
Expand All @@ -110,13 +103,7 @@ module H1_handler = struct
in
Reqd.respond_with_string reqd response response_body

let error_handler :
Eio.Net.Sockaddr.stream ->
?request:Request.t ->
_ ->
(Headers.t -> Body.Writer.t) ->
unit =
fun _client_address ?request:_ _error start_response ->
let error_handler _client_address ?request:_ _error start_response =
let response_body = start_response Headers.empty in
Body.Writer.close response_body
end
Expand Down Expand Up @@ -165,8 +152,8 @@ module Alpn_lib = struct
| Ok {alpn_protocol;_} ->
match alpn_protocol with
| None -> ()
| Some "http/1.1" -> h1_handler (flow :> Eio.Flow.two_way) sa
| Some "h2" -> h2_handler ~docroot (flow :> Eio.Flow.two_way) sa
| Some "http/1.1" -> h1_handler (flow :> Eio.Net.stream_socket) sa
| Some "h2" -> h2_handler ~docroot (flow :> Eio.Net.stream_socket) sa
| Some _ -> Eio.traceln "invalid ALPN response"; ()
)
done
Expand Down

0 comments on commit dfdd8f2

Please sign in to comment.