[100365] trunk/base/src/darwintracelib1.0/darwintrace.c

cal at macports.org cal at macports.org
Sun Dec 9 09:15:30 PST 2012


Revision: 100365
          https://trac.macports.org/changeset/100365
Author:   cal at macports.org
Date:     2012-12-09 09:15:30 -0800 (Sun, 09 Dec 2012)
Log Message:
-----------
darwintrace: loop around first recv(2), too

Sometimes, I saw "!!! received %zd, but should have been %zd", which
means the size of the buffer to be read wasn't read completely in the
first call to recv(2). Wrapping this in a loop, too, should fix this.

Modified Paths:
--------------
    trunk/base/src/darwintracelib1.0/darwintrace.c

Modified: trunk/base/src/darwintracelib1.0/darwintrace.c
===================================================================
--- trunk/base/src/darwintracelib1.0/darwintrace.c	2012-12-09 17:09:47 UTC (rev 100364)
+++ trunk/base/src/darwintracelib1.0/darwintrace.c	2012-12-09 17:15:30 UTC (rev 100365)
@@ -550,19 +550,21 @@
 		size_t recv_len = 0, received;
 		char *recv_buf;
 		
-		ssize_t t;
-		if (-1 == (t = recv(__darwintrace_fd, &recv_len, sizeof(recv_len), 0))) {
-			debug_printf("error reading data from socket %d: %s\n", __darwintrace_fd, strerror(errno));
-			if (__darwintrace_debug)
-				fprintf(__darwintrace_debug, "darwintrace: error reading data from socket %d: %s\n", __darwintrace_fd, strerror(errno));
-			abort();
+		received = 0;
+		while (received < sizeof(recv_len)) {
+			ssize_t local_received = recv(__darwintrace_fd, ((char *) &recv_len) + received, sizeof(recv_len) - received, 0);
+			if (local_received == -1) {
+				debug_printf("error reading data from socket %d: %s\n", __darwintrace_fd, strerror(errno));
+				if (__darwintrace_debug)
+					fprintf(__darwintrace_debug, "darwintrace: error reading data from socket %d: %s\n", __darwintrace_fd, strerror(errno));
+				abort();
+			}
+			received += local_received;
 		}
-		if (t != sizeof(recv_len)) {
-			debug_printf("!!! received %zd, but should have been %zd\n", t, sizeof(recv_len));
-		}
 		if (recv_len == 0) {
 			return 0;
 		}
+
 		recv_buf = malloc(recv_len + 1);
 		recv_buf[recv_len] = '\0';
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20121209/ae20957b/attachment.html>


More information about the macports-changes mailing list