r4161 - trunk/varnish-cache/lib/libvarnish

sky at projects.linpro.no sky at projects.linpro.no
Wed Jul 29 14:43:33 CEST 2009


Author: sky
Date: 2009-07-29 14:43:33 +0200 (Wed, 29 Jul 2009)
New Revision: 4161

Modified:
   trunk/varnish-cache/lib/libvarnish/tcp.c
Log:
On Solaris we occasionally get EBADF when we use the ioctl
to toggle blocking. This then results in the connects failing.

The way Solaris seems to want it to be done is using fcntl
over two syscalls. So make it so conditionally for Solaris.

Should fix #482 and #535

Compiled on Solaris and Victori tested a prelminary version
of the patch that solved it. Sadly test cases don't 
seem to run at all on my solaris dev zone.



Modified: trunk/varnish-cache/lib/libvarnish/tcp.c
===================================================================
--- trunk/varnish-cache/lib/libvarnish/tcp.c	2009-07-29 09:52:55 UTC (rev 4160)
+++ trunk/varnish-cache/lib/libvarnish/tcp.c	2009-07-29 12:43:33 UTC (rev 4161)
@@ -57,6 +57,11 @@
 
 #include "libvarnish.h"
 
+/* Solaris can't use the ioctl" */
+#ifdef __sun
+#include <fcntl.h>
+#endif
+
 /*--------------------------------------------------------------------*/
 
 void
@@ -127,22 +132,23 @@
  * us to do two syscalls, one to get and one to set, the latter of
  * which mucks about a bit before it ends up calling ioctl(FIONBIO),
  * at least on FreeBSD.
+ *
+ * On some platforms we need to use fcntl because the ioctl is unreliable
+ * The one that we know this is the case for is solaris.
  */
 
-/* 
- * XXXXX -- Artur after debugging with victory
- * This needs to rewrotten to use fcntl on solaris
- * since the ioctl breaks connects.
- * How to know we are on solaris?
-*/
-
 void
 TCP_blocking(int sock)
 {
 	int i;
 
+#ifdef __sun
+	i = fcntl (sock, F_GETFL,0);
+	fcntl(sock, F_SETFL, i & ~O_NONBLOCK);
+#else
 	i = 0;
 	AZ(ioctl(sock, FIONBIO, &i));
+#endif
 }
 
 void
@@ -150,8 +156,13 @@
 {
 	int i;
 
+#ifdef __sun
+	i = fcntl (sock, F_GETFL,0);
+	fcntl(sock, F_SETFL, i | O_NONBLOCK);
+#else
 	i = 1;
 	AZ(ioctl(sock, FIONBIO, &i));
+#endif
 }
 
 /*--------------------------------------------------------------------



More information about the varnish-commit mailing list