>From 018a9311011d7d88a427341a10670487fc0b08ae Mon Sep 17 00:00:00 2001
From: Nils Goroll <nils.goroll@uplex.de>
Date: Wed, 12 Oct 2011 20:17:33 +0200
Subject: [PATCH] Avoid panicking if setsockopt(SO_RCVTIMEO) fails with EINVAL on Solaris

---
 lib/libvarnish/vtcp.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/lib/libvarnish/vtcp.c b/lib/libvarnish/vtcp.c
index 10c3664..c0f7a95 100644
--- a/lib/libvarnish/vtcp.c
+++ b/lib/libvarnish/vtcp.c
@@ -265,7 +265,13 @@ VTCP_set_read_timeout(int s, double seconds)
 	timeout.tv_sec = (int)floor(seconds);
 	timeout.tv_usec = (int)(1e6 * (seconds - timeout.tv_sec));
 #ifdef SO_RCVTIMEO_WORKS
-	AZ(setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof timeout));
+	/* 
+	 * Solaris bug (present at least in snv_151 and older): If this fails
+	 * with EINVAL, the socket is half-closed (SS_CANTSENDMORE) and the
+	 * timeout does not get set. Needs to be fixed in Solaris, there is
+	 * nothing we can do about this.
+	 */
+	VTCP_Assert(setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof timeout));
 #else
 	(void)s;
 #endif
-- 
1.5.6.5

