Browse Source

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 15 years ago
parent
commit
28e3132505
1 changed files with 4 additions and 4 deletions
  1. 4 4
      tcp_read.c

+ 4 - 4
tcp_read.c

@@ -1011,13 +1011,13 @@ repeat_1st_read:
 							con, con->id, atomic_get(&con->refcnt));
 							con, con->id, atomic_get(&con->refcnt));
 				goto read_error;
 				goto read_error;
 			}
 			}
+			read_flags=((
 #ifdef POLLRDHUP
 #ifdef POLLRDHUP
-			read_flags=(((events & POLLRDHUP) |
+						(events & POLLRDHUP) |
+#endif /* POLLRDHUP */
+						(events & (POLLHUP|POLLERR)) |
 							(con->flags & (F_CONN_EOF_SEEN|F_CONN_FORCE_EOF)))
 							(con->flags & (F_CONN_EOF_SEEN|F_CONN_FORCE_EOF)))
 						&& !(events & POLLPRI))? RD_CONN_FORCE_EOF: 0;
 						&& !(events & POLLPRI))? RD_CONN_FORCE_EOF: 0;
-#else /* POLLRDHUP */
-			read_flags=0;
-#endif /* POLLRDHUP */
 #ifdef USE_TLS
 #ifdef USE_TLS
 repeat_read:
 repeat_read:
 #endif /* USE_TLS */
 #endif /* USE_TLS */