From f145f667009b60e7da17d5b459533205202058dc Mon Sep 17 00:00:00 2001 From: Michael Kerrisk Date: Wed, 3 Feb 2016 14:18:21 +0100 Subject: [PATCH] select_tut.2: tfix Signed-off-by: Michael Kerrisk --- man2/select_tut.2 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/man2/select_tut.2 b/man2/select_tut.2 index ac9211a8a..aaa0fad6c 100644 --- a/man2/select_tut.2 +++ b/man2/select_tut.2 @@ -562,6 +562,7 @@ listen_socket(int listen_port) perror("socket"); return \-1; } + yes = 1; if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) == \-1) { @@ -569,6 +570,7 @@ listen_socket(int listen_port) close(s); return \-1; } + memset(&addr, 0, sizeof(addr)); addr.sin_port = htons(listen_port); addr.sin_family = AF_INET; @@ -577,6 +579,7 @@ listen_socket(int listen_port) close(s); return \-1; } + printf("accepting connections on port %d\\n", listen_port); listen(s, 10); return s; @@ -723,7 +726,7 @@ main(int argc, char *argv[]) } } - /* NB: read oob data before normal reads */ + /* NB: read OOB data before normal reads */ if (fd1 > 0) if (FD_ISSET(fd1, &er)) { @@ -782,14 +785,14 @@ main(int argc, char *argv[]) buf1_written += r; } - /* check if write data has caught read data */ + /* Check if write data has caught read data */ if (buf1_written == buf1_avail) buf1_written = buf1_avail = 0; if (buf2_written == buf2_avail) buf2_written = buf2_avail = 0; - /* one side has closed the connection, keep + /* One side has closed the connection, keep writing to the other side until empty */ if (fd1 < 0 && buf1_avail \- buf1_written == 0)