r2637 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Mon May 26 10:38:00 CEST 2008


Author: phk
Date: 2008-05-26 10:38:00 +0200 (Mon, 26 May 2008)
New Revision: 2637

Modified:
   trunk/varnish-cache/bin/varnishd/cache_fetch.c
   trunk/varnish-cache/bin/varnishd/common.h
   trunk/varnish-cache/bin/varnishd/tcp.c
Log:
Add TCP_blocking() and TCP_nonblocking() and use them instead of
fondling fcntl(2) directly.


Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_fetch.c	2008-05-26 08:36:18 UTC (rev 2636)
+++ trunk/varnish-cache/bin/varnishd/cache_fetch.c	2008-05-26 08:38:00 UTC (rev 2637)
@@ -65,9 +65,7 @@
 	sp->obj->len = cl;
 	p = st->ptr;
 
-	i = fcntl(htc->fd, F_GETFL);		/* XXX ? */
-	i &= ~O_NONBLOCK;
-	i = fcntl(htc->fd, F_SETFL, i);
+	TCP_blocking(htc->fd);
 
 	while (cl > 0) {
 		i = HTC_Read(htc, p, cl);
@@ -211,9 +209,7 @@
 	struct storage *st;
 	unsigned v;
 
-	i = fcntl(htc->fd, F_GETFL);		/* XXX ? */
-	i &= ~O_NONBLOCK;
-	i = fcntl(htc->fd, F_SETFL, i);
+	TCP_blocking(htc->fd);
 
 	p = NULL;
 	v = 0;

Modified: trunk/varnish-cache/bin/varnishd/common.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/common.h	2008-05-26 08:36:18 UTC (rev 2636)
+++ trunk/varnish-cache/bin/varnishd/common.h	2008-05-26 08:38:00 UTC (rev 2637)
@@ -44,5 +44,7 @@
 void TCP_name(const struct sockaddr *addr, unsigned l, char *abuf, unsigned alen, char *pbuf, unsigned plen);
 void TCP_myname(int sock, char *abuf, unsigned alen, char *pbuf, unsigned plen);
 int TCP_filter_http(int sock);
+void TCP_blocking(int sock);
+void TCP_nonblocking(int sock);
 
 #define TRUST_ME(ptr)	((void*)(uintptr_t)(ptr))

Modified: trunk/varnish-cache/bin/varnishd/tcp.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/tcp.c	2008-05-26 08:36:18 UTC (rev 2636)
+++ trunk/varnish-cache/bin/varnishd/tcp.c	2008-05-26 08:38:00 UTC (rev 2637)
@@ -37,6 +37,7 @@
 #include <netinet/in.h>
 
 #include <errno.h>
+#include <fcntl.h>
 #include <netdb.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -110,3 +111,29 @@
 	return (0);
 #endif
 }
+
+/*--------------------------------------------------------------------*/
+
+void
+TCP_blocking(int sock)
+{
+	int i;
+
+	i = fcntl(sock, F_GETFL);
+	assert(i != -1);
+	i &= ~O_NONBLOCK;
+	i = fcntl(sock, F_SETFL, i);
+	assert(i != -1);
+}
+
+void
+TCP_nonblocking(int sock)
+{
+	int i;
+
+	i = fcntl(sock, F_GETFL);
+	assert(i != -1);
+	i |= O_NONBLOCK;
+	i = fcntl(sock, F_SETFL, i);
+	assert(i != -1);
+}




More information about the varnish-commit mailing list