aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Kerrisk <mtk.manpages@gmail.com>2016-02-03 14:36:49 +0100
committerMichael Kerrisk <mtk.manpages@gmail.com>2016-02-03 14:37:40 +0100
commit65842010f33a6d2629e7e821e43e7d10c1c570e5 (patch)
tree0c0d379f4b9dff20f16f7a1b9c9c50fdd2f96e66
parent894d620ae2ddfa50991ba9813083a90251a22c83 (diff)
downloadman-pages-65842010f33a6d2629e7e821e43e7d10c1c570e5.tar.gz
select_tut.2: Simplify 'if' logic in in example program
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
-rw-r--r--man2/select_tut.2102
1 files changed, 48 insertions, 54 deletions
diff --git a/man2/select_tut.2 b/man2/select_tut.2
index d12450a97e..53097a79d6 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 */