瀏覽代碼

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).

(cherry picked from commit 28e313250503d6f8d06ebab15c8421c40e7f0fe4)
Andrei Pelinescu-Onciul 15 年之前
父節點
當前提交
8fafff8a11
共有 1 個文件被更改,包括 4 次插入4 次删除
  1. 4 4
      tcp_read.c

+ 4 - 4
tcp_read.c

@@ -970,13 +970,13 @@ again:
 							con, con->id, atomic_get(&con->refcnt));
 				goto read_error;
 			}
+			read_flags=((
 #ifdef POLLRDHUP
-			read_flags=(((events & POLLRDHUP) | 
+						(events & POLLRDHUP) |
+#endif /* POLLRDHUP */
+						(events & (POLLHUP|POLLERR)) |
 							(con->flags & (F_CONN_EOF_SEEN|F_CONN_FORCE_EOF)))
 						&& !(events & POLLPRI))? RD_CONN_FORCE_EOF: 0;
-#else /* POLLRDHUP */
-			read_flags=0;
-#endif /* POLLRDHUP */
 			resp=tcp_read_req(con, &ret, &read_flags);
 			if (unlikely(resp<0)){
 read_error: