mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
specify a socket file in ToWeb
This commit is contained in:
parent
a860e67443
commit
25ea9bc8e4
6 changed files with 98 additions and 12 deletions
7
_oasis
7
_oasis
|
|
@ -100,6 +100,13 @@ Executable run_tests
|
||||||
Build$: flag(tests) && flag(lwt)
|
Build$: flag(tests) && flag(lwt)
|
||||||
BuildDepends: containers, oUnit, lwt
|
BuildDepends: containers, oUnit, lwt
|
||||||
|
|
||||||
|
Executable web_pwd
|
||||||
|
Path: examples
|
||||||
|
Install: false
|
||||||
|
MainIs: web_pwd.ml
|
||||||
|
Build$: flag(cgi)
|
||||||
|
BuildDepends: containers_cgi, threads, CamlGI
|
||||||
|
|
||||||
SourceRepository head
|
SourceRepository head
|
||||||
Type: git
|
Type: git
|
||||||
Location: https://github.com/c-cube/ocaml-containers
|
Location: https://github.com/c-cube/ocaml-containers
|
||||||
|
|
|
||||||
9
_tags
9
_tags
|
|
@ -1,5 +1,5 @@
|
||||||
# OASIS_START
|
# OASIS_START
|
||||||
# DO NOT EDIT (digest: 2ccc5fef0936d36155ec2a8d19a2c516)
|
# DO NOT EDIT (digest: 79585995b18632ac90365c888b75c5ba)
|
||||||
# Ignore VCS directories, you can use the same kind of rule outside
|
# Ignore VCS directories, you can use the same kind of rule outside
|
||||||
# OASIS_START/STOP if you want to exclude directories that contains
|
# OASIS_START/STOP if you want to exclude directories that contains
|
||||||
# useless stuff for the build process
|
# useless stuff for the build process
|
||||||
|
|
@ -75,4 +75,11 @@
|
||||||
<tests/*.ml{,i}>: pkg_oUnit
|
<tests/*.ml{,i}>: pkg_oUnit
|
||||||
<tests/*.ml{,i}>: pkg_lwt
|
<tests/*.ml{,i}>: pkg_lwt
|
||||||
<tests/*.ml{,i}>: pkg_unix
|
<tests/*.ml{,i}>: pkg_unix
|
||||||
|
# Executable web_pwd
|
||||||
|
"examples/web_pwd.byte": pkg_containers_cgi
|
||||||
|
"examples/web_pwd.byte": pkg_threads
|
||||||
|
"examples/web_pwd.byte": pkg_CamlGI
|
||||||
|
<examples/*.ml{,i}>: pkg_containers_cgi
|
||||||
|
<examples/*.ml{,i}>: pkg_threads
|
||||||
|
<examples/*.ml{,i}>: pkg_CamlGI
|
||||||
# OASIS_STOP
|
# OASIS_STOP
|
||||||
|
|
|
||||||
26
examples/web_pwd.ml
Normal file
26
examples/web_pwd.ml
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
|
||||||
|
(** Export the list of files in a directory *)
|
||||||
|
|
||||||
|
let dir = "/tmp/"
|
||||||
|
|
||||||
|
(* list of files in a dir *)
|
||||||
|
let lsdir dir =
|
||||||
|
let d = Unix.opendir dir in
|
||||||
|
let l = ref [] in
|
||||||
|
begin try while true do
|
||||||
|
l := Unix.readdir d :: !l
|
||||||
|
done with End_of_file -> Unix.closedir d
|
||||||
|
end;
|
||||||
|
!l
|
||||||
|
|
||||||
|
let export dir =
|
||||||
|
let l = lsdir dir in
|
||||||
|
ToWeb.HTML.(concat
|
||||||
|
[ h1 (str ("files in "^ dir))
|
||||||
|
; list (List.map str l)
|
||||||
|
])
|
||||||
|
|
||||||
|
let state = ToWeb.State.create dir ~export
|
||||||
|
|
||||||
|
let _ =
|
||||||
|
ToWeb.serve_state ~sockfile:"/tmp/foo.sock" state
|
||||||
38
setup.ml
38
setup.ml
|
|
@ -1,7 +1,7 @@
|
||||||
(* setup.ml generated for the first time by OASIS v0.3.0 *)
|
(* setup.ml generated for the first time by OASIS v0.3.0 *)
|
||||||
|
|
||||||
(* OASIS_START *)
|
(* OASIS_START *)
|
||||||
(* DO NOT EDIT (digest: f32ca79fc0b4813e77bbd8481226d30d) *)
|
(* DO NOT EDIT (digest: e88f591350fc76aa4ff518bff87740a1) *)
|
||||||
(*
|
(*
|
||||||
Regenerated by OASIS v0.3.0
|
Regenerated by OASIS v0.3.0
|
||||||
Visit http://oasis.forge.ocamlcore.org for more information and
|
Visit http://oasis.forge.ocamlcore.org for more information and
|
||||||
|
|
@ -6157,6 +6157,38 @@ let setup_t =
|
||||||
InternalExecutable "run_tests"
|
InternalExecutable "run_tests"
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
Executable
|
||||||
|
({
|
||||||
|
cs_name = "web_pwd";
|
||||||
|
cs_data = PropList.Data.create ();
|
||||||
|
cs_plugin_data = [];
|
||||||
|
},
|
||||||
|
{
|
||||||
|
bs_build =
|
||||||
|
[
|
||||||
|
(OASISExpr.EBool true, false);
|
||||||
|
(OASISExpr.EFlag "cgi", true)
|
||||||
|
];
|
||||||
|
bs_install = [(OASISExpr.EBool true, false)];
|
||||||
|
bs_path = "examples";
|
||||||
|
bs_compiled_object = Byte;
|
||||||
|
bs_build_depends =
|
||||||
|
[
|
||||||
|
FindlibPackage ("containers_cgi", None);
|
||||||
|
FindlibPackage ("threads", None);
|
||||||
|
FindlibPackage ("CamlGI", None)
|
||||||
|
];
|
||||||
|
bs_build_tools = [ExternalTool "ocamlbuild"];
|
||||||
|
bs_c_sources = [];
|
||||||
|
bs_data_files = [];
|
||||||
|
bs_ccopt = [(OASISExpr.EBool true, [])];
|
||||||
|
bs_cclib = [(OASISExpr.EBool true, [])];
|
||||||
|
bs_dlllib = [(OASISExpr.EBool true, [])];
|
||||||
|
bs_dllpath = [(OASISExpr.EBool true, [])];
|
||||||
|
bs_byteopt = [(OASISExpr.EBool true, [])];
|
||||||
|
bs_nativeopt = [(OASISExpr.EBool true, [])];
|
||||||
|
},
|
||||||
|
{exec_custom = false; exec_main_is = "web_pwd.ml"; });
|
||||||
SrcRepo
|
SrcRepo
|
||||||
({
|
({
|
||||||
cs_name = "head";
|
cs_name = "head";
|
||||||
|
|
@ -6183,7 +6215,7 @@ let setup_t =
|
||||||
};
|
};
|
||||||
oasis_fn = Some "_oasis";
|
oasis_fn = Some "_oasis";
|
||||||
oasis_version = "0.3.0";
|
oasis_version = "0.3.0";
|
||||||
oasis_digest = Some "/\253\176\237b\239\208]\237\230B\012\254\227e\207";
|
oasis_digest = Some "$\027-\146h\194\205\029\204\206\210\171\235|k-";
|
||||||
oasis_exec = None;
|
oasis_exec = None;
|
||||||
oasis_setup_args = [];
|
oasis_setup_args = [];
|
||||||
setup_update = false;
|
setup_update = false;
|
||||||
|
|
@ -6191,6 +6223,6 @@ let setup_t =
|
||||||
|
|
||||||
let setup () = BaseSetup.setup setup_t;;
|
let setup () = BaseSetup.setup setup_t;;
|
||||||
|
|
||||||
# 6195 "setup.ml"
|
# 6227 "setup.ml"
|
||||||
(* OASIS_STOP *)
|
(* OASIS_STOP *)
|
||||||
let () = setup ();;
|
let () = setup ();;
|
||||||
|
|
|
||||||
18
toWeb.ml
18
toWeb.ml
|
|
@ -341,8 +341,18 @@ end
|
||||||
|
|
||||||
(** {2 Main Interface} *)
|
(** {2 Main Interface} *)
|
||||||
|
|
||||||
let serve_state ?sockaddr st =
|
let serve_state ?sockfile ?sockaddr st =
|
||||||
CamlGI.Cgi.register_script ?sockaddr (State.handle_request st)
|
match sockfile with
|
||||||
|
| None ->
|
||||||
|
CamlGI.Cgi.register_script ?sockaddr (State.handle_request st)
|
||||||
|
| Some f ->
|
||||||
|
let sockaddr = Unix.ADDR_UNIX f in
|
||||||
|
CamlGI.Cgi.register_script ~sockaddr (State.handle_request st)
|
||||||
|
|
||||||
let serve_router ?sockaddr router =
|
let serve_router ?sockfile ?sockaddr router =
|
||||||
CamlGI.Cgi.register_script ?sockaddr (Router.handle_request router)
|
match sockfile with
|
||||||
|
| None ->
|
||||||
|
CamlGI.Cgi.register_script ?sockaddr (Router.handle_request router)
|
||||||
|
| Some f ->
|
||||||
|
let sockaddr = Unix.ADDR_UNIX f in
|
||||||
|
CamlGI.Cgi.register_script ~sockaddr (Router.handle_request router)
|
||||||
|
|
|
||||||
12
toWeb.mli
12
toWeb.mli
|
|
@ -193,9 +193,13 @@ end
|
||||||
|
|
||||||
(** {2 Main interface} *)
|
(** {2 Main interface} *)
|
||||||
|
|
||||||
val serve_state : ?sockaddr:Unix.sockaddr -> 'a State.t -> unit
|
val serve_state : ?sockfile:string -> ?sockaddr:Unix.sockaddr ->
|
||||||
(** Serve incoming requests using a single object. *)
|
'a State.t -> unit
|
||||||
|
(** Serve incoming requests using a single object.
|
||||||
|
@param sockfile the unix file to use as a socket *)
|
||||||
|
|
||||||
val serve_router : ?sockaddr:Unix.sockaddr -> Router.t -> unit
|
val serve_router : ?sockfile:string -> ?sockaddr:Unix.sockaddr ->
|
||||||
|
Router.t -> unit
|
||||||
(** Shortcut. It calls {!CamlGI.Cgi.register_script} with a callback
|
(** Shortcut. It calls {!CamlGI.Cgi.register_script} with a callback
|
||||||
that forwards requests to the given Router. *)
|
that forwards requests to the given Router.
|
||||||
|
@param sockfile the unix file to use as a socket *)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue