diff --git a/src/ws/tiny_httpd_ws.ml b/src/ws/tiny_httpd_ws.ml index 81d452cc..d278e919 100644 --- a/src/ws/tiny_httpd_ws.ml +++ b/src/ws/tiny_httpd_ws.ml @@ -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] *) diff --git a/src/ws/tiny_httpd_ws.mli b/src/ws/tiny_httpd_ws.mli index 77e71232..bb63f992 100644 --- a/src/ws/tiny_httpd_ws.mli +++ b/src/ws/tiny_httpd_ws.mli @@ -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) ->