[sheepdog] [PATCH 1/4] sheep: priority to process EPOLLERR/EPOLLHUP event

Yunkai Zhang yunkai.me at gmail.com
Sat Jun 23 15:40:32 CEST 2012


From: Yunkai Zhang <qiushu.zyk at taobao.com>

When EPOLLERR/EPOLLHUP events occur,  other events(eg: EPOLLIN) may be
inclued at the same time, but we should priority to process them as the
connection was destroyed.

Signed-off-by: Yunkai Zhang <qiushu.zyk at taobao.com>
---
 sheep/sdnet.c |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/sheep/sdnet.c b/sheep/sdnet.c
index 34d65cf..f69ec98 100644
--- a/sheep/sdnet.c
+++ b/sheep/sdnet.c
@@ -660,18 +660,21 @@ static void client_handler(int fd, int events, void *data)
 {
 	struct client_info *ci = (struct client_info *)data;
 
+	if (events & (EPOLLERR | EPOLLHUP))
+	    goto err;
+
 	if (events & EPOLLIN)
 		client_rx_handler(ci);
 
 	if (events & EPOLLOUT)
 		client_tx_handler(ci);
 
-	if ((events & (EPOLLERR | EPOLLHUP))
-		|| is_conn_dead(&ci->conn)) {
+	if (is_conn_dead(&ci->conn)) {
 		if (!(ci->conn.events & EPOLLIN))
 			list_del(&ci->conn.blocking_siblings);
-
-		dprintf("closed connection %d\n", fd);
+err:
+		dprintf("closed connection %d, %s:%d\n", fd,
+			ci->conn.ipstr, ci->conn.port);
 		unregister_event(fd);
 		client_decref(ci);
 	}
-- 
1.7.10.2




More information about the sheepdog mailing list