[sheepdog] [PATCH 2/2] sheep: set keepalive in server-side socket fd

Yunkai Zhang yunkai.me at gmail.com
Wed Jun 13 05:38:33 CEST 2012


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

It's important to set keepalive option in server-side socket fd, this
can help the server to clear deaded connection quickly when its client
crashed for unexpected reason (eg: client reboot or be killed).

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

diff --git a/sheep/sdnet.c b/sheep/sdnet.c
index 3ae260e..f7eb6c8 100644
--- a/sheep/sdnet.c
+++ b/sheep/sdnet.c
@@ -772,6 +772,12 @@ static void listen_handler(int listen_fd, int events, void *data)
 		return;
 	}
 
+	ret = set_keepalive(fd);
+	if (ret) {
+		close(fd);
+		return;
+	}
+
 	ret = set_nodelay(fd);
 	if (ret) {
 		close(fd);
-- 
1.7.10.2




More information about the sheepdog mailing list