11 #include "msg_vstream.h"
18 #define FIFO "/tmp/test-fifo"
20 static const char *progname
;
22 static void print_fstat(int fd
)
26 if (fstat(fd
, &st
) < 0)
27 msg_fatal("fstat: %m");
28 vstream_printf("fd %d\n", fd
);
29 vstream_printf("dev %ld\n", (long) st
.st_dev
);
30 vstream_printf("ino %ld\n", (long) st
.st_ino
);
31 vstream_fflush(VSTREAM_OUT
);
34 static NORETURN
usage(void)
36 msg_fatal("usage: %s [-p] [-n count] [-v]", progname
);
39 int main(int argc
, char **argv
)
50 msg_vstream_init(argv
[0], VSTREAM_ERR
);
55 while ((ch
= GETOPT(argc
, argv
, "pn:v")) > 0) {
63 if ((count
= atoi(optarg
)) < 1)
71 server_fd
= stream_listen(FIFO
, 0, 0);
72 if (readable(server_fd
))
73 msg_fatal("server fd is readable after create");
78 for (i
= 0; i
< count
; i
++) {
79 msg_info("connect attempt %d", i
);
80 if ((client_fd
= stream_connect(FIFO
, 0, 0)) < 0)
81 msg_fatal("open %s as client: %m", FIFO
);
82 if (readable(server_fd
))
83 msg_info("server fd is readable after client open");
84 if (close(client_fd
) < 0)
85 msg_fatal("close client fd: %m");
91 for (i
= 0; i
< count
; i
++) {
92 msg_info("receive attempt %d", i
);
93 if (!readable(server_fd
)) {
94 msg_info("wait for server fd to become readable");
95 read_wait(server_fd
, -1);
97 if ((fd
= stream_accept(server_fd
)) < 0)
98 msg_fatal("receive fd: %m");
102 msg_fatal("close received fd: %m");
104 if (close(server_fd
) < 0)
105 msg_fatal("close server fd");
109 int main(int argc
, char **argv
)