-
Notifications
You must be signed in to change notification settings - Fork 125
/
runtimeType.ml
133 lines (109 loc) · 2.87 KB
/
runtimeType.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
(*
Copyright © 2011 MLstate
This file is part of OPA.
OPA is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License, version 3, as published by
the Free Software Foundation.
OPA is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
more details.
You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*)
(**
Ports and Description module for the Runtime layer.
@author Cedric Soulas
*)
module rec Ports :
sig
type t =
(string *
[ `Connection of Network.port
| `Http_dialog of Http_dialog.port
| `HttpDialog of HttpDialog.port
| `Logger
| `None
]) list
val add : Scheduler.t -> t -> unit
val init : Scheduler.t -> unit
end =
struct
type t =
(string *
[ `Connection of Network.port
| `Http_dialog of Http_dialog.port
| `HttpDialog of HttpDialog.port
| `Logger
| `None
]) list
let ports = ref []
let init_port sched (name, port) =
match port with
| `Connection c ->
let module N = Network in
let abort_listen = Network.listen sched c.N.port_spec c.N.secure_mode c.N.conn_incoming in
let _ = abort_listen in
()
| `Http_dialog hd ->
let e = Description.get name in
let dialog = match e with
| `Http_dialog dialog -> dialog
| _ -> assert false
in
hd.Http_dialog.set_dialog dialog
| `HttpDialog hd ->
let e = Description.get name in
let dialog = match e with
| `HttpDialog dialog -> dialog
| _ -> assert false
in
hd.HttpDialog.set_dialog dialog
| `Logger ->()
| `None -> ()
| _ -> assert false
let add _sched l =
ports := l@(!ports)
let init sched =
List.iter (init_port sched) !ports
end
and Description :
sig
type t =
[
| `Connection
| `Http_dialog of Http_dialog.t
| `HttpDialog of HttpDialog.t
| `Logger
| `HttpServer
| `FtpServer
| `SmtpServer
| `Watchdog
]
val get : string -> t
val add : string -> t -> unit
end =
struct
type t =
[
| `Connection
| `Http_dialog of Http_dialog.t
| `HttpDialog of HttpDialog.t
| `Logger
| `HttpServer
| `FtpServer
| `SmtpServer
| `Watchdog
]
exception Not_found
let (output: (string, t) Hashtbl.t) = Hashtbl.create 5
let add k e =
Hashtbl.add output k e
let get k =
if Hashtbl.mem output k then
Hashtbl.find output k
else begin
Logger.error "Unbound port '%s'" k;
raise Not_found
end
end