Commit c21cab75 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

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: http://www.varnish-cache.org/svn/trunk/varnish-cache@1965 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent bca3f901
...@@ -400,7 +400,10 @@ struct backend *VBE_NewBackend(struct backend_method *method); ...@@ -400,7 +400,10 @@ struct backend *VBE_NewBackend(struct backend_method *method);
struct vbe_conn *VBE_NewConn(void); struct vbe_conn *VBE_NewConn(void);
void VBE_ReleaseConn(struct vbe_conn *); void VBE_ReleaseConn(struct vbe_conn *);
void VBE_UpdateHealth(struct sess *sp, struct vbe_conn *, int); 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_TryConnect(struct sess *sp, struct addrinfo *ai);
int VBE_CheckFd(int fd);
/* cache_backend_simple.c */ /* cache_backend_simple.c */
extern struct backend_method backend_method_simple; extern struct backend_method backend_method_simple;
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <poll.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <netdb.h> #include <netdb.h>
...@@ -106,7 +107,22 @@ VBE_TryConnect(struct sess *sp, struct addrinfo *ai) ...@@ -106,7 +107,22 @@ VBE_TryConnect(struct sess *sp, struct addrinfo *ai)
return (s); 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. * Get a http structure for talking to the backend.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment