From c8e7ecd8f0f2fde10b0a751de9e720376f11a073 Mon Sep 17 00:00:00 2001 From: phk Date: Thu, 20 Sep 2007 08:22:59 +0000 Subject: [PATCH] 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. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1965 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache.h | 3 +++ varnish-cache/bin/varnishd/cache_backend.c | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index 0c3e1f61..347260fe 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -400,7 +400,10 @@ struct backend *VBE_NewBackend(struct backend_method *method); 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; diff --git a/varnish-cache/bin/varnishd/cache_backend.c b/varnish-cache/bin/varnishd/cache_backend.c index da8ecc1c..cdf34fa7 100644 --- a/varnish-cache/bin/varnishd/cache_backend.c +++ b/varnish-cache/bin/varnishd/cache_backend.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -106,7 +107,22 @@ VBE_TryConnect(struct sess *sp, struct addrinfo *ai) 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. -- 2.39.5