Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 150 lines (119 sloc) 4.156 kb
fccc685 Initial open-source release
MLstate authored
1 (*
2 Copyright © 2011 MLstate
3
4 This file is part of OPA.
5
6 OPA is free software: you can redistribute it and/or modify it under the
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
10 OPA is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
13 more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with OPA. If not, see <http://www.gnu.org/licenses/>.
17 *)
18
19 (**
20 Network specific operations.
21
22 @author Henri Binsztok
23 @author Laurent Le Brun
24 @author Frederic Ye
25 @author Cedric Soulas
26 *)
27
28 (**
29 This module provides functions to make connections, secured or not,
30 by listening or connecting on a port specification.
31 Connection returned by those functions, of type [Scheduler.connection_info],
32 should then be used with the Scheduler module.
33
34 {b Current use:}
35 For the moment it is used only to establish TCP connection (connected mode).
36 {b Intented future use:}
37 UPD specific function may be added in that module
38 *)
39
40 (** {6 Types} *)
41
42 (**
43 The type describing how secure have to be the connection.
44 An "Optional" mode may be added for future use.
45 *)
46 type secure_mode =
47 | Unsecured
48 | Secured of SslAS.secure_type
49
50 type socket_type =
51 | TCP
52 | UDP
53
54 (** The type describing the connection to establish *)
55 type port_spec = (* ADAM: how about hiding the type and forcing its construction via the [make_port_spec] function? *) {
56 addr : Unix.inet_addr;
57 port : int;
58 prot : NetAddr.protocol;
59 stype : Connection.socket_type
60 }
61
62 (** The type to plug a port in a Runtime.COMPONENT *)
63 type port = {
64 conn_incoming :
65 SslAS.secure_response -> Scheduler.connection_info -> unit;
66 conn_terminating : unit -> unit;
67 secure_mode : secure_mode;
68 port_spec : port_spec
69 }
70
71 type socket
72
73 (** A function to build a port_spec type *)
74 val make_port_spec : ?socket_type:socket_type -> protocol:NetAddr.protocol -> Unix.inet_addr -> int -> port_spec
75
76 (** Gives the port of the given [port_spec] *)
77 val get_port : port_spec -> int
78
79 (** Gives the network address of the given [port_spec] *)
80 val get_addr : port_spec -> Unix.inet_addr
81
82 (** Gives the socket type of the given [port_spec] *)
83 val get_socket_type : port_spec -> socket_type
84
85 (** {6 TCP functions} *)
86
87
88 (**
89 TCP listen over a [socket]
90 A SslAS.secure_response and a Scheduler.connection_info is
91 provided to your callback when a new client is connected.
92 *)
93 val listen :
94 Scheduler.t ->
95 port_spec ->
96 secure_mode ->
97 ?socket_flags:(Unix.socket_bool_option list) ->
98 (SslAS.secure_response -> Scheduler.connection_info -> unit) ->
99 (unit -> unit)
100
101 (**
102 TCP connect over a port specification.
103 A Scheduler.connection_info describing the
104 socket connection between you and the server is provided to your callback.
105 *)
106 val connect :
107 Scheduler.t ->
108 port_spec ->
109 secure_mode ->
110 ?socket_flags:(Unix.socket_bool_option list) ->
111 ?err_cont:(exn -> unit) ->
112 (Scheduler.connection_info -> unit) ->
113 unit
114
115 (** {6 Misc. functions } *)
116
117 exception Unknown_machine of string
118
119 (**
120 [inet_addr_of_name m] raise [Unknown_machine m] if
121 the the name can't be resolved.
122 *)
123 val inet_addr_of_name :
124 string -> Unix.inet_addr
125
126 val addr_of_ipv4 :
127 int * int * int * int -> Unix.inet_addr
128
129 val string_of_ipv4 :
130 int * int * int * int -> string
131
132 (**
133 @return a [secure_mode] [Secured (c, p)] if [c] or [p] isn't None.
134 and return [Unsecured] if c and p are both None.
135 Note that [Secured (None, None)] is permited in a client context.
136 See [SslAS.get_secure_socket] for more information.
137 *)
138 val secure_mode_from_params :
139 SslAS.ssl_certificate option -> SslAS.ssl_verify_params option -> secure_mode
140
141 (** {6 Old functions intended to be deleted} *)
142
143 (**
144 Loop over a Scheduler.t
145 {b For migration purpose only.
146 It will be deleted when the Runtime module will be used.}
147 @deprecated Use Scheduler.run
148 *)
149 val loop : Scheduler.t -> unit
Something went wrong with that request. Please try again.