4 * Simple IPC test. /tmp/cs1 -s in one window, /tmp/cs1 -c in another.
6 * $DragonFly: src/test/caps/caps1.c,v 1.1 2003/11/24 21:15:59 dillon Exp $
9 #include <libcaps/globaldata.h>
10 #include <sys/thread.h>
11 #include <sys/msgport.h>
12 #include <sys/msgport2.h>
13 #include <sys/thread2.h>
19 main(int ac
, char **av
)
23 struct lwkt_port replyport
;
24 struct lwkt_msg junkmsg
;
28 enum { UNKNOWN
, CLIENT
, SERVER
} mode
;
30 signal(SIGPIPE
, SIG_IGN
);
32 for (i
= 1; i
< ac
; ++i
) {
45 quietOpt
= (*ptr
) ? strtol(ptr
, NULL
, 0) : 1;
52 port
= caps_service("test", -1, 0666, 0);
54 printf("caps_service port %p\n", port
);
55 while ((msg
= lwkt_waitport(&port
->lport
, NULL
)) != NULL
) {
57 printf("received msg %p %08x\n", msg
, msg
->ms_flags
);
58 printf("replyport: %p %p\n",
59 msg
->ms_reply_port
, msg
->ms_reply_port
->mp_replyport
);
61 msg
->u
.ms_result
= ~msg
->u
.ms_result
;
62 lwkt_replymsg(msg
, 23);
66 lwkt_initport(&replyport
, curthread
);
67 port
= caps_client("test", -1, 0);
69 printf("caps_client port %p msg %p\n", port
, &junkmsg
);
71 printf("failed to connect\n");
75 lwkt_initmsg(&junkmsg
, &replyport
, 0);
76 junkmsg
.u
.ms_result
= i
;
77 junkmsg
.ms_msgsize
= sizeof(junkmsg
);
78 junkmsg
.ms_maxsize
= sizeof(junkmsg
);
79 lwkt_beginmsg(&port
->lport
, &junkmsg
);
80 if (caps_client_waitreply(port
, &junkmsg
) == NULL
) {
81 printf("client failed\n");
85 printf("reply: error=%d/23 res=%d/%d\n",
86 junkmsg
.ms_error
, ~junkmsg
.u
.ms_result
, i
);
87 } else if (quietOpt
== 1 && (i
& 65535) == 0) {
88 printf("reply: error=%d/23 res=%d/%d\n",
89 junkmsg
.ms_error
, ~junkmsg
.u
.ms_result
, i
);