2 * Copyright 2016 Jeremy Allison
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
23 #include <sys/param.h>
24 #include <sys/types.h>
26 #include <sys/socket.h>
36 extern char *__progname
;
41 int *sfds
= (int *)varg
;
46 for (i
= 0; i
< 5; i
++) {
51 iov
= (struct iovec
) {
53 .iov_len
= sizeof (buf
)
56 msg
= (struct msghdr
) {
61 ret
= recvmsg(sock
, &msg
, 0);
63 fprintf(stderr
, "server - recvmsg fail %s\n",
68 printf("SERVER: got HUP\n");
72 printf("SERVER:%s\n", (char *)msg
.msg_iov
->iov_base
);
88 /* Create socketpair */
89 ret
= socketpair(AF_UNIX
, sotype
, 0, sfds
);
91 fprintf(stderr
, "%s - socketpair fail %s\n",
92 __progname
, strerror(errno
));
96 /* Set up the server. It closes sfds[0] when done. */
97 ret
= pthread_create(NULL
, NULL
, server
, sfds
);
99 fprintf(stderr
, "%s - thread create fail %s\n",
100 __progname
, strerror(errno
));
106 /* "Server" is sfds[0], "client" is sfds[1] */
109 /* Send some messages */
110 for (i
= 0; i
< 3; i
++) {
115 memcpy(buf
, "TEST0", sizeof ("TEST0"));
118 printf("CLIENT:%s\n", buf
);
120 iov
= (struct iovec
) {
122 .iov_len
= sizeof (buf
),
125 msg
= (struct msghdr
) {
130 ret
= sendmsg(sock
, &msg
, 0);
133 fprintf(stderr
, "%s - sendmsg fail %s\n",
134 __progname
, strerror(errno
));
143 * Tell sever to terminate
145 if (sotype
== SOCK_STREAM
) {
146 printf("CLIENT: close\n");
149 printf("CLIENT: send 0\n");
150 send(sock
, "", 0, 0);
156 main(int argc
, char **argv
)
159 printf("%s SOCK_STREAM test...\n", argv
[0]);
160 runtest(SOCK_STREAM
);
162 printf("%s SOCK_DGRAM test...\n", argv
[0]);