diff --git a/man2/select_tut.2 b/man2/select_tut.2 index d12450a97..53097a79d 100644 --- a/man2/select_tut.2 +++ b/man2/select_tut.2 @@ -730,62 +730,56 @@ main(int argc, char *argv[]) /* NB: read OOB data before normal reads */ - if (fd1 > 0) - if (FD_ISSET(fd1, &exceptfds)) { - char c; + if (fd1 > 0 && FD_ISSET(fd1, &exceptfds)) { + char c; - nbytes = recv(fd1, &c, 1, MSG_OOB); - if (nbytes < 1) - SHUT_FD1; - else - send(fd2, &c, 1, MSG_OOB); - } - if (fd2 > 0) - if (FD_ISSET(fd2, &exceptfds)) { - char c; + nbytes = recv(fd1, &c, 1, MSG_OOB); + if (nbytes < 1) + SHUT_FD1; + else + send(fd2, &c, 1, MSG_OOB); + } + if (fd2 > 0 && FD_ISSET(fd2, &exceptfds)) { + char c; - nbytes = recv(fd2, &c, 1, MSG_OOB); - if (nbytes < 1) - SHUT_FD2; - else - send(fd1, &c, 1, MSG_OOB); - } - if (fd1 > 0) - if (FD_ISSET(fd1, &readfds)) { - nbytes = read(fd1, buf1 + buf1_avail, - BUF_SIZE \- buf1_avail); - if (nbytes < 1) - SHUT_FD1; - else - buf1_avail += nbytes; - } - if (fd2 > 0) - if (FD_ISSET(fd2, &readfds)) { - nbytes = read(fd2, buf2 + buf2_avail, - BUF_SIZE \- buf2_avail); - if (nbytes < 1) - SHUT_FD2; - else - buf2_avail += nbytes; - } - if (fd1 > 0) - if (FD_ISSET(fd1, &writefds)) { - nbytes = write(fd1, buf2 + buf2_written, - buf2_avail \- buf2_written); - if (nbytes < 1) - SHUT_FD1; - else - buf2_written += nbytes; - } - if (fd2 > 0) - if (FD_ISSET(fd2, &writefds)) { - nbytes = write(fd2, buf1 + buf1_written, - buf1_avail \- buf1_written); - if (nbytes < 1) - SHUT_FD2; - else - buf1_written += nbytes; - } + nbytes = recv(fd2, &c, 1, MSG_OOB); + if (nbytes < 1) + SHUT_FD2; + else + send(fd1, &c, 1, MSG_OOB); + } + if (fd1 > 0 && FD_ISSET(fd1, &readfds)) { + nbytes = read(fd1, buf1 + buf1_avail, + BUF_SIZE \- buf1_avail); + if (nbytes < 1) + SHUT_FD1; + else + buf1_avail += nbytes; + } + if (fd2 > 0 && FD_ISSET(fd2, &readfds)) { + nbytes = read(fd2, buf2 + buf2_avail, + BUF_SIZE \- buf2_avail); + if (nbytes < 1) + SHUT_FD2; + else + buf2_avail += nbytes; + } + if (fd1 > 0 && FD_ISSET(fd1, &writefds)) { + nbytes = write(fd1, buf2 + buf2_written, + buf2_avail \- buf2_written); + if (nbytes < 1) + SHUT_FD1; + else + buf2_written += nbytes; + } + if (fd2 > 0 && FD_ISSET(fd2, &writefds)) { + nbytes = write(fd2, buf1 + buf1_written, + buf1_avail \- buf1_written); + if (nbytes < 1) + SHUT_FD2; + else + buf1_written += nbytes; + } /* Check if write data has caught read data */