Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 4 Jun 2011 16:01:30 +0000 (UTC)
From:      Maxim Sobolev <sobomax@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r222688 - head/sbin/hastd
Message-ID:  <201106041601.p54G1Ut7016697@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: sobomax
Date: Sat Jun  4 16:01:30 2011
New Revision: 222688
URL: http://svn.freebsd.org/changeset/base/222688

Log:
  Read from the socket using the same max buffer size as we use while
  sending. What happens otherwise is that the sender splits all the
  traffic into 32k chunks, while the receiver is waiting for the whole
  packet. Then for a certain packet sizes, particularly 66607 bytes in
  my case, the communication stucks to secondary is expecting to
  read one chunk of 66607 bytes, while primary is sending two chunks
  of 32768 bytes and third chunk of 1071. Probably due to TCP windowing
  and buffering the final chunk gets stuck somewhere, so neither server
  not client can make any progress.
  
  This patch also protect from short reads, as according to the manual
  page there are some cases when MSG_WAITALL can give less data than
  expected.
  
  MFC after:	3 days

Modified:
  head/sbin/hastd/proto_common.c

Modified: head/sbin/hastd/proto_common.c
==============================================================================
--- head/sbin/hastd/proto_common.c	Sat Jun  4 15:22:01 2011	(r222687)
+++ head/sbin/hastd/proto_common.c	Sat Jun  4 16:01:30 2011	(r222688)
@@ -194,6 +194,8 @@ int
 proto_common_recv(int sock, unsigned char *data, size_t size, int *fdp)
 {
 	ssize_t done;
+	size_t total_done, recvsize;
+	unsigned char *dp;
 
 	PJDLOG_ASSERT(sock >= 0);
 
@@ -210,9 +212,19 @@ proto_common_recv(int sock, unsigned cha
 	PJDLOG_ASSERT(data != NULL);
 	PJDLOG_ASSERT(size > 0);
 
+	total_done = 0;
+	dp = data;
 	do {
-		done = recv(sock, data, size, MSG_WAITALL);
-	} while (done == -1 && errno == EINTR);
+		recvsize = size - total_done;
+		recvsize = recvsize < MAX_SEND_SIZE ? recvsize : MAX_SEND_SIZE;
+		done = recv(sock, dp, recvsize, MSG_WAITALL);
+		if (done == -1 && errno == EINTR)
+			continue;
+		if (done <= 0)
+			break;
+		total_done += done;
+		dp += done;
+	} while (total_done < size);
 	if (done == 0) {
 		return (ENOTCONN);
 	} else if (done < 0) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201106041601.p54G1Ut7016697>