-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnection.ml
50 lines (45 loc) · 1.87 KB
/
connection.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
(*
* Copyright (c) 2013-2014 Gregory Tsipenyuk <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)
open Core.Std
open Async.Std
(** handle client connection **)
(** need to address multiple client connections **)
(**
* send capability response to the client
* do pre-authentication if needed
* return either Authenticated or Notauthenticated state
**)
let init_connection w =
let resp = "* OK [CAPABILITY " ^ Configuration.capability ^ "] Imaplet ready.\r\n" in
Writer.write w resp ~len:(String.length(resp));
upon (Writer.flushed w) (fun() -> ());
States.State_Notauthenticated
let init_storage () =
let open IrminSrvIpc in
match Configuration.get_store with
| `Mbox | `Mailbox -> return None
| `Irminsule -> get_irmin_server_ipc ()
(**
* accepted client's connection
**)
let client_connect id connections r w =
init_storage () >>= fun str_ipc ->
let open Contexts in
let state = init_connection w in
let contexts =
({req_ctx = (Contextlist.create()); state_ctx = state; mbx_ctx = Amailbox.empty() }) in
let ipc_ctx = { connid = id; connections; logout_ctx = Condition.create(); net_r = r; net_w = w ; str_rw = str_ipc} in
State.handle_client_requests contexts ipc_ctx