r1965 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Thu Sep 20 10:22:59 CEST 2007


Author: phk
Date: 2007-09-20 10:22:59 +0200 (Thu, 20 Sep 2007)
New Revision: 1965

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_backend.c
Log:
Add a convenience function more for backend methods:

VBE_CheckFd(): Check that a filedescriptor is reusable.

Right now we simply poll it with a zero timeout, and if there are
any events, we can't reuse it.

This check may need refinement down the road.

One option would be to attempt to write a CRNL onto the fd and see
that it works.



Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2007-09-20 08:16:01 UTC (rev 1964)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2007-09-20 08:22:59 UTC (rev 1965)
@@ -400,7 +400,10 @@
 struct vbe_conn *VBE_NewConn(void);
 void VBE_ReleaseConn(struct vbe_conn *);
 void VBE_UpdateHealth(struct sess *sp, struct vbe_conn *, int);
+
+/* convenience functions for backend methods */
 int VBE_TryConnect(struct sess *sp, struct addrinfo *ai);
+int VBE_CheckFd(int fd);
 
 /* cache_backend_simple.c */
 extern struct backend_method	backend_method_simple;

Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend.c	2007-09-20 08:16:01 UTC (rev 1964)
+++ trunk/varnish-cache/bin/varnishd/cache_backend.c	2007-09-20 08:22:59 UTC (rev 1965)
@@ -35,6 +35,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <poll.h>
 
 #include <sys/socket.h>
 #include <netdb.h>
@@ -106,8 +107,23 @@
 	return (s);
 }
 
+/*--------------------------------------------------------------------
+ * Check that there is still something at the far end of a given fd.
+ * We poll the fd with instant timeout, if there are any events we can't
+ * use it (backends are not allowed to pipeline).
+ */
 
+int
+VBE_CheckFd(int fd)
+{
+	struct pollfd pfd;
 
+	pfd.fd = fd;
+	pfd.events = POLLIN;
+	pfd.revents = 0;
+	return(poll(&pfd, 1, 0) == 0);
+}
+
 /*--------------------------------------------------------------------
  * Get a http structure for talking to the backend.
  */




More information about the varnish-commit mailing list