r3083 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Tue Aug 12 14:28:38 CEST 2008


Author: phk
Date: 2008-08-12 14:28:38 +0200 (Tue, 12 Aug 2008)
New Revision: 3083

Modified:
   trunk/varnish-cache/bin/varnishd/cache_backend.c
   trunk/varnish-cache/bin/varnishd/common.h
   trunk/varnish-cache/bin/varnishd/tcp.c
Log:
Make a central TCP_close() function that accepts the two errno's which
indicate that our partner gave up on us.



Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend.c	2008-08-12 10:29:22 UTC (rev 3082)
+++ trunk/varnish-cache/bin/varnishd/cache_backend.c	2008-08-12 12:28:38 UTC (rev 3083)
@@ -242,7 +242,7 @@
 
 	LOCK(&bp->mtx);
 	bp->refcount++;
-	UNLOCK(&sp->backend->mtx);
+	UNLOCK(&bp->mtx);
 
 	s = -1;
 	assert(bp->ipv6 != NULL || bp->ipv4 != NULL);
@@ -257,7 +257,7 @@
 		s = VBE_TryConnect(sp, PF_INET6, bp->ipv6, bp->ipv6len);
 
 	if (s < 0) {
-		LOCK(&sp->backend->mtx);
+		LOCK(&bp->mtx);
 		bp->refcount--;		/* Only keep ref on success */
 		UNLOCK(&bp->mtx);
 	}
@@ -317,16 +317,13 @@
 VBE_ClosedFd(struct worker *w, struct vbe_conn *vc)
 {
 	struct backend *b;
-	int i;
 
 	CHECK_OBJ_NOTNULL(vc, VBE_CONN_MAGIC);
 	CHECK_OBJ_NOTNULL(vc->backend, BACKEND_MAGIC);
 	b = vc->backend;
 	assert(vc->fd >= 0);
 	WSL(w, SLT_BackendClose, vc->fd, "%s", vc->backend->vcl_name);
-	i = close(vc->fd);
-	assert(i == 0 || errno == ECONNRESET || errno == ENOTCONN);
-	vc->fd = -1;
+	TCP_close(&vc->fd);
 	VBE_DropRef(vc->backend);
 	vc->backend = NULL;
 	VBE_ReleaseConn(vc);

Modified: trunk/varnish-cache/bin/varnishd/common.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/common.h	2008-08-12 10:29:22 UTC (rev 3082)
+++ trunk/varnish-cache/bin/varnishd/common.h	2008-08-12 12:28:38 UTC (rev 3083)
@@ -54,6 +54,7 @@
 void TCP_nonblocking(int sock);
 #ifdef SOL_SOCKET
 int TCP_connect(int s, const struct sockaddr *name, socklen_t namelen, int msec);
+void TCP_close(int *s);
 #endif
 
 #define TRUST_ME(ptr)	((void*)(uintptr_t)(ptr))

Modified: trunk/varnish-cache/bin/varnishd/tcp.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/tcp.c	2008-08-12 10:29:22 UTC (rev 3082)
+++ trunk/varnish-cache/bin/varnishd/tcp.c	2008-08-12 12:28:38 UTC (rev 3083)
@@ -192,3 +192,17 @@
 	TCP_blocking(s);
 	return (0);
 }
+
+/*--------------------------------------------------------------------
+ * When closing a TCP connection, a couple of errno's are legit, we
+ * can't be held responsible for the other end wanting to talk to us.
+ */
+
+void
+TCP_close(int *s)
+{
+	assert (close(*s) == 0 ||
+	    errno == ECONNRESET ||
+	    errno == ENOTCONN);
+	*s = -1;
+}




More information about the varnish-commit mailing list