[Sheepdog] [PATCH] fix a bug in rx() when read() returns 0 but connection is not marked as closed.

Li Wenpeng levin108 at gmail.com
Tue Apr 24 09:59:41 CEST 2012


From: levin li <xingke.lwp at taobao.com>

if read() returns 0,it means connection closed, but previous
read() may set errno to EAGAIN, in which case rx() would just
return 0 without set connection state as C_IO_CLOSED

Signed-off-by: levin li <xingke.lwp at taobao.com>
---
 lib/net.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/lib/net.c b/lib/net.c
index 260ae38..8ac7c9e 100644
--- a/lib/net.c
+++ b/lib/net.c
@@ -70,7 +70,12 @@ int rx(struct connection *conn, enum conn_state next_state)
 	int ret;
 
 	ret = read(conn->fd, conn->rx_buf, conn->rx_length);
-	if (!ret || ret < 0) {
+	if (!ret) {
+		conn->c_rx_state = C_IO_CLOSED;
+		return 0;
+	}
+
+	if (ret < 0) {
 		if (errno != EAGAIN)
 			conn->c_rx_state = C_IO_CLOSED;
 		return 0;
-- 
1.7.1




More information about the sheepdog mailing list