Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 84 lines (65 sloc) 3.181 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 (** A shared directory beetween several server.
19
20 NOTE : Currently is a very simple implementation which support
21 only one server and doesn't support any failure of server.
22 Implementation may change for support several servers and server
23 failure, but interface should not be change (or maybe just the
24 make function...)
25 *)
26
27 (** {6 Who} *)
28 (** A type used for indicates who put a value on directory. *)
29 type who = Me | Other of Unix.inet_addr
30
31 (** Returns a readable string from a [who]. *)
32 val who_to_string : who -> string
33
34 (** {6 Directory interface} *)
35
36 (** A directory is parametrized by a type of ['key] and ['value]. *)
37 type ('key, 'value) t
38
39 (** [make scheduler endpoint path kind] Create a new directory. Behaviour
40 depends of [kind] :
41 - [`server] creates a directory and launch a server that
42 listen on [endpoint].
43 - [`client] creates a client directory which request a server
44 directory at [endpoint].
45 [path] it's using for distinguishes directories if you have
46 several. Limited to 8 characters.
47 *)
48 val make : ?err_cont:(exn -> unit) -> Scheduler.t -> Hlnet.endpoint -> string ->
49 [ `client | `server ] -> ('key, 'value) t Cps.t
50
51 (** Add a new binding of [key] to [value]. That doesn't erase previous
52 bindings. *)
53 val add : ('key, 'value) t -> 'key -> 'value -> unit
54
55 (** [remove directory key] Remove the last binding of [key]. *)
56 val remove : ('key, 'value) t -> 'key -> unit
57
58 (** [find_or_replace directory key value] Returns [value] binded to
59 [key] if already exists, else returns [None] and add a binding of
60 [key] to [value].*)
61 val find_or_replace : ('key, 'value) t -> 'key -> 'value ->
62 ('value * who) option Cps.t
63
64 (** [find_opt directory key] Returns the last binded value to [key] or
65 [None] if any value is binded to [key].*)
66 val find_opt : ('key, 'value) t -> 'key ->
67 ('value * who) option Cps.t
68
69 (** [find_all directory key] Find all value binded to [key].*)
70 val find_all : ('key, 'value) t -> 'key ->
71 ('value * who) list Cps.t
72
73 (** {6 Localizer interface} *)
74
75 (** [my_public_addr_opt] Returns your public [inet_addr]. (It's the
76 addresses use by the server directory for communicates with
77 you). Can return [None] if you are the server directory and any
78 client make a request to you. *)
79 val my_public_addr_opt : ('key, 'value) t -> Unix.inet_addr option Cps.t
80
81 (** Like [my_public_addr_opt] but in server case wait the first client
82 request for get the public address.*)
83 val my_public_addr : ('key, 'value) t -> Unix.inet_addr Cps.t
Something went wrong with that request. Please try again.