Release
[hcoop/domtool2.git] / src / connect.sml
CommitLineData
2b75bae8
CE
1(* HCoop Domtool (http://hcoop.sourceforge.net/)
2 * Copyright (c) 2014 Clinton Ebadi <clinton@unknownlamer.org>
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 *)
18
19structure Connect :> CONNECT = struct
20
21open MsgTypes
22
23fun requestDispatcherBio context =
24 OpenSSL.connect true (context, Domain.nodeIp Config.dispatcherName ^ ":" ^ Int.toString Config.dispatcherPort)
25
26fun requestWorkerBio (context, node) =
27 OpenSSL.connect true (context, Domain.nodeIp node ^ ":" ^ Int.toString Config.slavePort)
28
29fun commandWorker (context, node, message) =
30(* It might be worth making this context -> node -> message -> bool *)
31 let
32 val bio = requestWorkerBio (context, node)
33 in
34 Msg.send (bio, message);
35 (case Msg.recv bio of
36 NONE => (print "Slave closed connection unexpectedly\n";
37 false)
38 | SOME m =>
39 case m of
40 MsgOk => (print ("Slave " ^ node ^ " finished\n");
41 true)
42 | MsgError s => (print ("Slave " ^ node
43 ^ " returned error: " ^
44 s ^ "\n");
45 false)
46 | _ => (print ("Slave " ^ node
47 ^ " returned unexpected command\n");
48 false))
49 before OpenSSL.close bio
50 handle OpenSSL.OpenSSL s => (print ("OpenSSL error: " ^ s ^ "\n");
51 OpenSSL.close bio;
52 false
53 handle OpenSSL.OpenSSL _ => false)
54 end
55 handle OpenSSL.OpenSSL s => (print ("OpenSSL error: " ^ s ^ "\n");
56 false)
57
58end