-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmsgtest_target.c
More file actions
75 lines (66 loc) · 1.36 KB
/
msgtest_target.c
File metadata and controls
75 lines (66 loc) · 1.36 KB
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
#include <u.h>
#include <libc.h>
#include <msg.h>
#include "tags.h"
#include "msgnames.h"
#include "testing.h"
char *argv0;
void
usage(void){
fprint(2, "usage: %s [-S namesrv]\n", argv0);
exits("usage");
}
int
main(int argc, char *argv[])
{
char buffer[1024];
uintptr msgsz;
int failures = 0;
char *namesrv = nil;
int namepid;
msgenable();
argv0 = argv[0];
ARGBEGIN{
case 'S':
namesrv = strdup(EARGF(usage()));
break;
default:
usage();
break;
}ARGEND;
namepid = name_server(namesrv);
if(namepid < 0){
fprint(2, "error: no name server found: %r\n");
exits("no name server");
}
if(register_name(namepid, "msgtest_target") < 0){
fprint(2, "error: unable to register name: %r\n");
exits("register_name");
}
fprint(2, "pid %d: waiting for messages\n", getpid());
for(;failures < 10;){
msgsz = sys_msgwait();
if((intptr)msgsz < 0) {
failures++;
fprint(2, "msgwait failure: %r\n");
continue;
}
if(msgsz == 0) {
failures++;
fprint(2, "msgwait returned 0: %r\n");
continue;
}
if(msgsz > sizeof(buffer)) {
fprint(2, "message too big (msgsz > %d)\n", sizeof(buffer));
exits("buffer too small");
}
if((vlong)sys_msgrecv(&buffer[0], msgsz) < 0) {
failures++;
fprint(2, "msgrecv failure: %r\n");
continue;
}
tryexitmessage(&buffer[0], msgsz);
}
fprint(2, "too many failures\n");
exits("too many failures");
}