Skip to content

Commit

Permalink
feat ws: expose Close_connection
Browse files Browse the repository at this point in the history
  • Loading branch information
c-cube committed Apr 5, 2024
1 parent e4303b2 commit 1955406
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 1 addition & 6 deletions src/ws/tiny_httpd_ws.ml
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,7 @@ module Writer = struct
Mutex.unlock self.mutex;
raise e

let close self =
if not self.closed then (
self.closed <- true;
raise Close_connection
)

let[@inline] close self = self.closed <- true
let int_of_bool : bool -> int = Obj.magic

(** Write the frame header to [self.oc] *)
Expand Down
4 changes: 4 additions & 0 deletions src/ws/tiny_httpd_ws.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
(** 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 :
?accept:(unit Request.t -> (unit, int * string) result) ->
?accept_ws_protocol:(string -> bool) ->
Expand Down

0 comments on commit 1955406

Please sign in to comment.