1 hdr,sys poll,socket,netinet/in
3 lib htons,htonl sys/types.h sys/socket.h netinet/in.h
4 lib getaddrinfo sys/types.h sys/socket.h netdb.h
5 typ fd_set sys/socket.h sys/select.h
6 tst pipe_socketpair note{ use socketpair() for peekable pipe() }end execute{
10 #include <sys/socket.h>
17 static void handler(sig)
29 static char msg[] = "hello world\n";
32 socketpair(AF_UNIX, SOCK_STREAM, 0, sfd) < 0 ||
33 shutdown(sfd[1], SHUT_RD) < 0 ||
34 shutdown(sfd[0], SHUT_WR) < 0)
36 if ((pid = fork()) < 0)
43 if (sfpkrd(pfd[0], buf, sizeof(buf), '\n', -1, 1) >= 0 ||
44 sfpkrd(sfd[0], buf, sizeof(buf), '\n', -1, 1) < 0)
51 write(pfd[1], msg, sizeof(msg) - 1);
52 write(sfd[1], msg, sizeof(msg) - 1);
57 signal(SIGPIPE, handler);
58 if (socketpair(AF_UNIX, SOCK_STREAM, 0, sfd) < 0 ||
59 shutdown(sfd[1], SHUT_RD) < 0 ||
60 shutdown(sfd[0], SHUT_WR) < 0)
63 write(sfd[1], msg, sizeof(msg) - 1);
67 tst socketpair_devfd note{ /dev/fd/N handles socketpair() }end execute{
70 #include <sys/types.h>
71 #include <sys/socket.h>
79 open("/dev/null", O_RDONLY);
80 if ((n = open("/dev/fd/0", O_RDONLY)) < 0)
83 if (socketpair(AF_UNIX, SOCK_STREAM, 0, sfd) < 0 ||
84 shutdown(sfd[0], 1) < 0 ||
85 shutdown(sfd[1], 0) < 0)
90 if ((n = open("/dev/fd/0", O_RDONLY)) < 0)
95 tst socketpair_shutdown_mode note{ fchmod() after socketpair() shutdown() }end execute{
97 #include <sys/types.h>
99 #include <sys/socket.h>
105 if (socketpair(AF_UNIX, SOCK_STREAM, 0, sfd) < 0 ||
106 shutdown(sfd[0], 1) < 0 ||
107 shutdown(sfd[1], 0) < 0)
109 if (fstat(sfd[0], &st0) < 0 || fstat(sfd[1], &st1) < 0)
111 if ((st0.st_mode & (S_IRUSR|S_IWUSR)) == S_IRUSR &&
112 (st1.st_mode & (S_IRUSR|S_IWUSR)) == S_IWUSR)
114 if (fchmod(sfd[0], S_IRUSR) < 0 ||
115 fstat(sfd[0], &st0) < 0 ||
116 (st0.st_mode & (S_IRUSR|S_IWUSR)) != S_IRUSR)
118 if (fchmod(sfd[1], S_IWUSR) < 0 ||
119 fstat(sfd[1], &st1) < 0 ||
120 (st1.st_mode & (S_IRUSR|S_IWUSR)) != S_IWUSR)
128 # define poll _SYS_poll
132 #endif /* _lib_poll */
137 # include <sys/poll.h>
138 # endif /* _sys_poll */
139 #endif /* _hdr_poll */
142 extern int poll(struct pollfd*,unsigned long,int);
143 #endif /* _lib_poll */
146 # define FD_ZERO(x) (*(x)=0)
147 # endif /* FD_ZERO */
149 # define FD_SET(n,x) (*(x)|=(1L<<(n)))
153 # endif /*_typ_fd_set */
154 #endif /* _lib_select */