Add CAM_NEW_TRAN_CODE as a kernel option.
[dragonfly.git] / test / caps / client.c
blobed160502e0518cd719aa3d154fcf8a9b5acf146f
1 /*
2 * $DragonFly: src/test/caps/client.c,v 1.3 2004/03/31 20:27:34 dillon Exp $
3 */
4 #include <sys/types.h>
5 #include <sys/time.h>
6 #include <sys/caps.h>
7 #include <sys/errno.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <unistd.h>
13 int
14 main(int ac, char **av)
16 int cid;
17 int n;
18 int count = 0;
19 long long xcount = 0;
20 int lostit = 0;
21 int didfork = 0;
22 int which = 0;
23 char buf[256];
24 struct caps_msgid msgid;
25 off_t msgcid;
26 caps_gen_t gen = 0;
27 caps_gen_t ngen;
29 cid = caps_sys_client("test", getuid(), getgid(), 0, CAPF_ANYCLIENT);
30 for (;;) {
31 errno = 0;
32 if (cid >= 0) {
33 msgcid = caps_sys_put(cid, "xyz", 3);
34 ngen = caps_sys_getgen(cid);
36 if (cid < 0 || (msgcid < 0 && errno == ENOTCONN)) {
37 if (lostit == 0)
38 printf("%d client forked or lost connection, reconnecting\n", which);
39 lostit = 1;
40 caps_sys_close(cid);
41 cid = caps_sys_client("test", getuid(), getgid(), 0,
42 CAPF_ANYCLIENT | CAPF_WAITSVC);
43 continue;
45 if (lostit) {
46 printf("%d client resume on reconnect after lost connection\n", which);
47 lostit = 0;
49 if (ngen != gen) {
50 printf("%d client: note generation change %lld\n", which, ngen);
51 gen = ngen;
53 #ifdef DEBUG
54 printf("msgcid = %016llx %d\n", msgcid, errno);
55 #endif
56 n = caps_sys_wait(cid, buf, sizeof(buf), &msgid, NULL);
57 #ifdef DEBUG
58 printf("n = %d msgid=%016llx state=%d errno=%d\n", n, msgid.c_id, msgid.c_state, errno);
59 if (n > 0)
60 printf("REPLY: %*.*s\n", n, n, buf);
61 #endif
62 ++count;
63 ++xcount;
64 if ((count & 65535) == 0)
65 printf("%d %lld\n", which, xcount);
66 if (count == 100000000)
67 count = 0;
68 if (count == 1000 && didfork == 0 && which < 10) {
69 if (fork() == 0) {
70 usleep(100000);
71 ++which;
72 } else {
73 printf("forked pid %d client #%d\n", (int)getpid(), which + 1);
74 didfork = 1;
78 return(0);