Skip to content

Commit dc546b7

Browse files
committed
shutdown server
1 parent fcfd4d5 commit dc546b7

File tree

5 files changed

+16
-1
lines changed

5 files changed

+16
-1
lines changed

src/server/cohttp/ezAPIServerCohttp.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ let create_server ?catch ?allow_origin ?allow_headers ?allow_methods
123123
~mode:(`TCP (`Port server_port))
124124
(Server.make_response_action ~callback ())
125125

126+
let shutdown () = Lwt.return_unit
127+
126128
let server ?catch ?allow_origin ?allow_headers ?allow_methods ?allow_credentials ?footer servers =
127129
Lwt.join (List.map (fun (port,kind) ->
128130
create_server ?catch ?allow_origin ?allow_headers ?allow_methods ?allow_credentials ?footer

src/server/httpaf/ezAPIServerHttpAf.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ let connection_handler ?catch ?allow_origin ?allow_headers ?allow_methods
113113
sockaddr
114114
fd
115115

116+
let shutdown = Server_common.shutdown
117+
116118
let server ?catch ?allow_origin ?allow_headers ?allow_methods ?allow_credentials ?footer servers =
117119
Server_common.server ~name:"HTTPAF" ?catch ?allow_origin ?allow_headers
118120
?allow_methods ?allow_credentials ?footer connection_handler servers

src/server/httpun/ezAPIServerHttpun.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,7 @@ let connection_handler ?catch ?allow_origin ?allow_headers ?allow_methods
107107

108108
Httpun_lwt_unix.Server.create_connection_handler ~request_handler ~error_handler sockaddr fd
109109

110+
let shutdown = Server_common.shutdown
111+
110112
let server ?catch ?allow_origin ?allow_headers ?allow_methods ?allow_credentials ?footer servers =
111113
Server_common.server ?catch ?allow_origin ?allow_headers ?allow_methods ?allow_credentials ?footer connection_handler servers

src/server/server_common.ml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ let mk_uri ~meth ~target ~header =
211211
uri
212212
end
213213

214+
let server = ref None
215+
214216
let create_server ?(name="HTTPUN") ~max_connections server_port server_kind handler =
215217
let open EzAPIServerUtils in
216218
let s = { server_port; server_kind } in
@@ -222,9 +224,14 @@ let create_server ?(name="HTTPUN") ~max_connections server_port server_kind hand
222224
~nb_max_connections:max_connections
223225
listen_address (handler s)(* fun sockaddr fd -> *)
224226
(* handler ?catch ?allow_origin ?allow_headers ?allow_methods *)
225-
(* ?allow_credentials s sockaddr fd) *) >>= fun _server ->
227+
(* ?allow_credentials s sockaddr fd) *) >>= fun s ->
228+
server := Some s;
226229
Lwt.return_unit
227230

231+
let shutdown () = match !server with
232+
| None -> Lwt.return_unit
233+
| Some server -> Lazy.force server.shutdown
234+
228235
let server ?name ?catch ?allow_origin ?allow_headers ?allow_methods ?allow_credentials ?footer handler servers =
229236
let max_connections =
230237
let n = List.length servers in

src/server/virtual/ezServer.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ val server : ?catch:(string -> exn -> string Answer.t Lwt.t) ->
1515
?allow_methods:allow_kind -> ?allow_credentials:bool -> ?footer:string ->
1616
(int * server_kind) list -> unit Lwt.t
1717

18+
val shutdown : unit -> unit Lwt.t
19+
1820
val set_debug : unit -> unit

0 commit comments

Comments
 (0)