1N/Alib select,poll,socket
1N/Atst pipe_socketpair note{ use socketpair() for peekable pipe() }end execute{
1N/A static void handler(sig)
1N/A static char msg[] = "hello world\n";
1N/A if (pipe(pfd) < 0 ||
1N/A socketpair(AF_UNIX, SOCK_STREAM, 0, sfd) < 0 ||
1N/A shutdown(sfd[1], SHUT_RD) < 0 ||
1N/A shutdown(sfd[0], SHUT_WR) < 0)
1N/A if ((pid = fork()) < 0)
1N/A if (sfpkrd(pfd[0], buf, sizeof(buf), '\n', -1, 1) >= 0 ||
1N/A sfpkrd(sfd[0], buf, sizeof(buf), '\n', -1, 1) < 0)
1N/A write(pfd[1], msg, sizeof(msg) - 1);
1N/A write(sfd[1], msg, sizeof(msg) - 1);
1N/A signal(SIGPIPE, handler);
1N/A if (socketpair(AF_UNIX, SOCK_STREAM, 0, sfd) < 0 ||
1N/A shutdown(sfd[1], SHUT_RD) < 0 ||
1N/A shutdown(sfd[0], SHUT_WR) < 0)
1N/A write(sfd[1], msg, sizeof(msg) - 1);
1N/Atst socketpair_devfd note{
/dev/fd/N handles socketpair() }end execute{
1N/A if (socketpair(AF_UNIX, SOCK_STREAM, 0, sfd) < 0 ||
1N/A shutdown(sfd[0], 1) < 0 ||
1N/A shutdown(sfd[1], 0) < 0)
1N/Atst socketpair_shutdown_mode note{ fchmod() after socketpair() shutdown() }end execute{
1N/A if (socketpair(AF_UNIX, SOCK_STREAM, 0, sfd) < 0 ||
1N/A shutdown(sfd[0], 1) < 0 ||
1N/A shutdown(sfd[1], 0) < 0)
1N/A if (fstat(sfd[0], &st0) < 0 || fstat(sfd[1], &st1) < 0)
1N/A if (fchmod(sfd[0], S_IRUSR) < 0 ||
1N/A fstat(sfd[0], &st0) < 0 ||
1N/A if (fchmod(sfd[1], S_IWUSR) < 0 ||
1N/A fstat(sfd[1], &st1) < 0 ||
1N/A # define poll _SYS_poll
1N/A #endif /* _lib_poll */
1N/A # endif /* _sys_poll */
1N/A #endif /* _hdr_poll */
1N/A extern int poll(struct pollfd*,unsigned long,int);
1N/A #endif /* _lib_poll */
1N/A # define FD_ZERO(x) (*(x)=0)
1N/A # endif /* FD_ZERO */
1N/A # define FD_SET(n,x) (*(x)|=(1L<<(n)))
1N/A # endif /* FD_SET */
1N/A # ifndef _typ_fd_set
1N/A typedef long fd_set;
1N/A # endif /*_typ_fd_set */
1N/A #endif /* _lib_select */