Browse code

tcp: force eof after read if write side hangup

Even if POLLRDHUP is not supported, but we detected a write side close
(POLLHUP) or an error (POLLERR) or such an event was previously detected by
tcp_main (F_CONN_EOF_SEEN), force connection closing after reading all the data
in the socket buffer. In this case we can close() after the first short read
and we save an extra system call (a read() that returns 0).

Andrei Pelinescu-Onciul authored on 20/06/2010 17:40:55
Showing 1 changed files
... ...
@@ -1011,13 +1011,13 @@ repeat_1st_read:
1011 1011
 							con, con->id, atomic_get(&con->refcnt));
1012 1012
 				goto read_error;
1013 1013
 			}
1014
+			read_flags=((
1014 1015
 #ifdef POLLRDHUP
1015
-			read_flags=(((events & POLLRDHUP) |
1016
+						(events & POLLRDHUP) |
1017
+#endif /* POLLRDHUP */
1018
+						(events & (POLLHUP|POLLERR)) |
1016 1019
 							(con->flags & (F_CONN_EOF_SEEN|F_CONN_FORCE_EOF)))
1017 1020
 						&& !(events & POLLPRI))? RD_CONN_FORCE_EOF: 0;
1018
-#else /* POLLRDHUP */
1019
-			read_flags=0;
1020
-#endif /* POLLRDHUP */
1021 1021
 #ifdef USE_TLS
1022 1022
 repeat_read:
1023 1023
 #endif /* USE_TLS */