2 * Copyright (c) 2007 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * $DragonFly: src/test/syslink/test1.c,v 1.1 2007/05/28 05:28:12 dillon Exp $
36 #include <sys/types.h>
37 #include <sys/syslink.h>
38 #include <sys/syslink_msg.h>
42 static void reader(int fd
);
43 static void writer(int fd
);
46 main(int ac
, char **av
)
48 union syslink_info_all info
;
52 bzero(&info
, sizeof(info
));
53 if (syslink(SYSLINK_CMD_NEW
, &info
.head
, sizeof(info
)) < 0) {
57 printf("fds %d %d\n", info
.cmd_new
.fds
[0], info
.cmd_new
.fds
[1]);
59 reader(info
.cmd_new
.fds
[0]);
61 writer(info
.cmd_new
.fds
[1]);
63 while (wait(NULL
) > 0)
72 union syslink_small_msg cmd
;
73 union syslink_small_msg rep
;
77 bzero(&cmd
, sizeof(cmd
));
78 cmd
.msg
.sm_bytes
= sizeof(struct syslink_msg
);
79 cmd
.msg
.sm_proto
= SMPROTO_BSDVFS
;
80 cmd
.msg
.sm_head
.se_cmd
= 0;
81 cmd
.msg
.sm_head
.se_bytes
= sizeof(cmd
.msg
.sm_head
);
84 n
= write(fd
, &cmd
, cmd
.msg
.sm_bytes
);
86 printf("write error %s\n", strerror(errno
));
88 printf("write n = %d %lld\n", n
, cmd
.msg
.sm_msgid
);
91 printf("write n = %d %lld\n", n
, cmd
.msg
.sm_msgid
);
92 n
= read(fd
, &rep
, sizeof(rep
));
93 printf("read-reply %d %lld\n", n
, rep
.msg
.sm_msgid
);
102 union syslink_small_msg cmd
;
103 union syslink_small_msg rep
;
106 bzero(&rep
, sizeof(rep
));
107 rep
.msg
.sm_bytes
= sizeof(struct syslink_msg
);
108 rep
.msg
.sm_proto
= SMPROTO_BSDVFS
| SM_PROTO_REPLY
;
109 rep
.msg
.sm_msgid
= 1;
110 rep
.msg
.sm_head
.se_cmd
= 0;
111 rep
.msg
.sm_head
.se_bytes
= sizeof(rep
.msg
.sm_head
);
114 n
= read(fd
, &cmd
, sizeof(cmd
));
115 if (n
< 0 && errno
== ENOSPC
) {
116 printf("no space\n");
120 printf("read error %s\n", strerror(errno
));
122 printf("read n = %d\n", n
);
123 rep
.msg
.sm_msgid
= cmd
.msg
.sm_msgid
;
124 n
= write(fd
, &rep
, rep
.msg
.sm_bytes
);
126 printf("reply error %s\n", strerror(errno
));
128 printf("reply ok\n");