1 #include <u.h>
2 #include <libc.h>
3 #include <auth.h>
4 #include <fcall.h>
5 #include "../boot/boot.h"
6
7 static Fcall hdr;
8
9 static void
rpc(int fd,int type)10 rpc(int fd, int type)
11 {
12 int n, l;
13 char buf[128], *p;
14
15 hdr.type = type;
16 hdr.tag = NOTAG;
17 n = convS2M(&hdr, buf);
18 if(write(fd, buf, n) != n)
19 fatal("write rpc");
20
21 print("...");
22 p = buf;
23 l = 0;
24 while(l < 3) {
25 n = read(fd, p, 3);
26 if(n <= 0)
27 fatal("read rpc");
28 if(n == 2 && l == 0 && buf[0] == 'O' && buf[1] == 'K')
29 continue;
30 p += n;
31 l += n;
32 }
33 if(convM2S(buf, &hdr, n) == 0){
34 print("%ux %ux %ux\n", buf[0], buf[1], buf[2]);
35 fatal("rpc format");
36 }
37 if(hdr.tag != NOTAG)
38 fatal("rpc tag not NOTAG");
39 if(hdr.type == Rerror){
40 print("error %s;", hdr.ename);
41 fatal("remote error");
42 }
43 if(hdr.type != type+1)
44 fatal("not reply");
45 }
46
47 void
nop(int fd)48 nop(int fd)
49 {
50 print("nop");
51 rpc(fd, Tnop);
52 }
53