connect to, but a connection to a backend, this makes it possible
for the directors to choose another backend, if connection to the
first backend fails.
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3120
d4fa192b-c00b-0410-8231-
f00ffab90ce4
/* cache_backend_cfg.c */
void VBE_Init(void);
void VBE_DropRef(struct backend *);
-void VBE_SelectBackend(struct sess *sp);
struct backend *VBE_AddBackend(struct cli *cli, const struct vrt_backend *vb);
/* cache_backend_poll.c */
return (s);
}
-/*--------------------------------------------------------------------*/
+/*--------------------------------------------------------------------
+ * Get a connection to whatever backend the director think this session
+ * should contact.
+ */
struct vbe_conn *
VBE_GetFd(struct sess *sp)
{
- struct backend *bp;
- struct vbe_conn *vc;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
- VBE_SelectBackend(sp);
+ CHECK_OBJ_NOTNULL(sp->director, DIRECTOR_MAGIC);
+
+ if (sp->director->getfd != NULL)
+ return (sp->director->getfd(sp));
+
+ sp->backend = sp->director->choose(sp);
+ CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC);
+ return (VBE_GetVbe(sp));
+}
+
+/*--------------------------------------------------------------------
+ * Get a connection to a particular backend.
+ */
+
+struct vbe_conn *
+VBE_GetVbe(const struct sess *sp)
+{
+ struct backend *bp;
+ struct vbe_conn *vc;
+
bp = sp->backend;
CHECK_OBJ_NOTNULL(bp, BACKEND_MAGIC);
*/
struct vbp_target;
+struct vbe_conn;
struct vrt_backend_probe;
-/* -------------------------------------------------------------------
+/*--------------------------------------------------------------------
* A director is a piece of code which selects one of possibly multiple
* backends to use.
*/
+typedef struct vbe_conn *vdi_getfd_f(struct sess *sp);
typedef struct backend *vdi_choose_f(struct sess *sp);
typedef void vdi_fini_f(struct director *d);
#define DIRECTOR_MAGIC 0x3336351d
const char *name;
vdi_choose_f *choose;
+ vdi_getfd_f *getfd;
vdi_fini_f *fini;
void *priv;
};
-/* Backend indstance */
+/*--------------------------------------------------------------------
+ * An instance of a backend from a VCL program.
+ */
+
struct backend {
unsigned magic;
#define BACKEND_MAGIC 0x64c4c7c6
/* cache_backend.c */
void VBE_ReleaseConn(struct vbe_conn *vc);
+struct vbe_conn *VBE_GetVbe(const struct sess *sp);
/* cache_backend_cfg.c */
extern MTX VBE_mtx;
*/
static VTAILQ_HEAD(, backend) backends = VTAILQ_HEAD_INITIALIZER(backends);
-/*--------------------------------------------------------------------*/
-
-void
-VBE_SelectBackend(struct sess *sp)
-{
- struct backend *bp;
-
- CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
- CHECK_OBJ_NOTNULL(sp->director, DIRECTOR_MAGIC);
- bp = sp->director->choose(sp);
- CHECK_OBJ_NOTNULL(bp, BACKEND_MAGIC);
- sp->backend = bp;
-}
/*--------------------------------------------------------------------
*/