This repository has been archived by the owner on Jan 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 65
/
ex2.T
90 lines (78 loc) · 1.91 KB
/
ex2.T
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
// -*-c++-*-
/* $Id$ */
#include "tame.h"
#include "parseopt.h"
#include "arpc.h"
#include "ex_prot.h"
#include "tame_rpc.h"
#include "tame_connectors.h"
#if 0
static callbase *
foo (ptr<aclnt> c, u_int32_t rpc, const void *a, void *r, aclnt_cb cb)
{
return c->call (rpc, a, r, cb);
}
#endif
tamed static void
try_rpc (str h, int port, evb_t cb)
{
tvars {
bool ret (false);
int32_t fd, r1;
ptr<axprt_stream> x;
ptr<aclnt> cli;
ex_str_t r2, a2;
ex_struct_t r3;
clnt_stat e1, e2, e3;
callbase *cbase;
}
twait { tcpconnect (h, port, mkevent(fd)); }
if (fd < 0) {
warn ("%s:%d: connection failed: %m\n", h.cstr(), port);
} else {
x = axprt_stream::alloc (fd);
cli = aclnt::alloc (x, ex_prog_1);
a2 = "go hang a salami i'm a lasagna hog";
twait {
RPC::ex_prog_1::ex_random (cli, &r1, mkevent (e1));
RPC::ex_prog_1::ex_reverse (cli, a2, &r2, mkevent(e2));
// Calling can be more general than just (void)call() methods.
// Need to specify callbase* unfortunately; can't be inferred
// from the type of tame_rpc...
cbase = RPC::ex_prog_1::w_ex_struct<callbase *>
(wrap (tame_rpc::rcall, cli), &r3, mkevent(e3));
}
if (e1 || e2 || e3) {
warn << "at least 1 RPC failed!\n";
} else {
warn << "the results are in:\n"
<< "\trandom # = " << r1 << "\n"
<< "\treversed string = " << r2 << "\n"
<< "\tstupid stuct = { s = " << r3.s << "; u = " << r3.u << " }\n";
ret = true;
}
}
cb->trigger (true);
}
static void finish (bool rc)
{
exit (rc ? 0 : -1);
}
tamed static void
main2 (int argc, char **argv)
{
tvars {
bool rc;
int port;
}
if (argc != 3 || !convertint (argv[2], &port))
fatal << "usage: ex2 <hostname> <port>\n";
twait { try_rpc (argv[1], port, mkevent (rc)); }
finish (rc);
}
int main (int argc, char *argv[])
{
main2 (argc, argv);
amain ();
return 0;
}