feat ws: expose Close_connection

This commit is contained in:
Simon Cruanes 2024-04-05 16:14:23 -04:00
parent e4303b2fd4
commit 19554068b5
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 5 additions and 6 deletions

View file

@ -76,12 +76,7 @@ module Writer = struct
Mutex.unlock self.mutex; Mutex.unlock self.mutex;
raise e raise e
let close self = let[@inline] close self = self.closed <- true
if not self.closed then (
self.closed <- true;
raise Close_connection
)
let int_of_bool : bool -> int = Obj.magic let int_of_bool : bool -> int = Obj.magic
(** Write the frame header to [self.oc] *) (** Write the frame header to [self.oc] *)

View file

@ -10,6 +10,10 @@ type handler = unit Request.t -> IO.Input.t -> IO.Output.t -> unit
val upgrade : IO.Input.t -> IO.Output.t -> IO.Input.t * IO.Output.t val upgrade : IO.Input.t -> IO.Output.t -> IO.Input.t * IO.Output.t
(** Upgrade a byte stream to the websocket framing protocol. *) (** Upgrade a byte stream to the websocket framing protocol. *)
exception Close_connection
(** Exception that can be raised from IOs inside the handler,
when the connection is closed from underneath. *)
val add_route_handler : val add_route_handler :
?accept:(unit Request.t -> (unit, int * string) result) -> ?accept:(unit Request.t -> (unit, int * string) result) ->
?accept_ws_protocol:(string -> bool) -> ?accept_ws_protocol:(string -> bool) ->