From: Stefano Zacchiroli Date: Fri, 6 Dec 2002 16:43:38 +0000 (+0000) Subject: - split init_socket_and_callback in two functions X-Git-Tag: v0_3_99~172 X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=d1569b80cc7b9fd2ca7551f2eb74e2dc10b02443;p=helm.git - split init_socket_and_callback in two functions - exported init_socket --- diff --git a/helm/DEVEL/ocaml-http/http_tcp_server.ml b/helm/DEVEL/ocaml-http/http_tcp_server.ml index 33f06e8a0..69da5c109 100644 --- a/helm/DEVEL/ocaml-http/http_tcp_server.ml +++ b/helm/DEVEL/ocaml-http/http_tcp_server.ml @@ -18,6 +18,21 @@ let wrap_callback_w_timeout ~callback ~timeout ~timeout_callback = ignore (Unix.alarm timeout); callback inchan outchan) +let init_socket sockaddr = + let suck = Unix.socket Unix.PF_INET Unix.SOCK_STREAM 0 in + Unix.setsockopt suck Unix.SO_REUSEADDR true; + Unix.bind suck sockaddr; + Unix.listen suck backlog; + suck + +let init_callback callback timeout = + let timeout_callback signo = + if signo = Sys.sigalrm then + raise Timeout + in + wrap_callback_w_timeout ~callback ~timeout ~timeout_callback + +(* let init_socket_and_callback sockaddr callback timeout = let suck = Unix.socket Unix.PF_INET Unix.SOCK_STREAM 0 in Unix.setsockopt suck Unix.SO_REUSEADDR true; @@ -29,6 +44,7 @@ let init_socket_and_callback sockaddr callback timeout = in let callback = wrap_callback_w_timeout ~callback ~timeout ~timeout_callback in (suck, callback) +*) (** tcp_server which use Unix.establish_server which in turn forks a child for each request *) @@ -44,7 +60,9 @@ let ocaml_builtin ~sockaddr ~timeout callback = (** tcp_server which doesn't fork, requests are server sequentially and in the same address space of the calling process *) let simple ~sockaddr ~timeout callback = - let (suck, callback) = init_socket_and_callback sockaddr callback timeout in +(* let (suck, callback) = init_socket_and_callback sockaddr callback timeout in *) + let suck = init_socket sockaddr in + let callback = init_callback callback timeout in while true do let (client, _) = Unix.accept suck in (* client is now connected *) @@ -60,7 +78,9 @@ let simple ~sockaddr ~timeout callback = (** tcp_server which creates a new thread for each request to be served *) let thread ~sockaddr ~timeout callback = - let (suck, callback) = init_socket_and_callback sockaddr callback timeout in +(* let (suck, callback) = init_socket_and_callback sockaddr callback timeout in *) + let suck = init_socket sockaddr in + let callback = init_callback callback timeout in let callback (i, o) = try callback i o; diff --git a/helm/DEVEL/ocaml-http/http_tcp_server.mli b/helm/DEVEL/ocaml-http/http_tcp_server.mli index 7c038a570..881fb58fa 100644 --- a/helm/DEVEL/ocaml-http/http_tcp_server.mli +++ b/helm/DEVEL/ocaml-http/http_tcp_server.mli @@ -1,3 +1,11 @@ + + (* servers *) + val simple: Http_types.tcp_server val ocaml_builtin: Http_types.tcp_server val thread: Http_types.tcp_server + + (* low level functions *) + +val init_socket: Unix.sockaddr -> Unix.file_descr +