[sr-dev] git:andrei/tcp_tls_changes: tcp: force eof after read if write side hangup

Andrei Pelinescu-Onciul andrei at iptel.org
Mon Jun 21 16:02:10 CEST 2010


Module: sip-router
Branch: andrei/tcp_tls_changes
Commit: 28e313250503d6f8d06ebab15c8421c40e7f0fe4
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=28e313250503d6f8d06ebab15c8421c40e7f0fe4

Author: Andrei Pelinescu-Onciul <andrei at iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei at iptel.org>
Date:   Sun Jun 20 19:40:55 2010 +0200

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

---

 tcp_read.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/tcp_read.c b/tcp_read.c
index 4881844..2d42cb9 100644
--- a/tcp_read.c
+++ b/tcp_read.c
@@ -1011,13 +1011,13 @@ repeat_1st_read:
 							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 */
 #ifdef USE_TLS
 repeat_read:
 #endif /* USE_TLS */




More information about the sr-dev mailing list