/* Backend Connection ------------------------------------------------*/
+struct bereq {
+ unsigned magic;
+#define BEREQ_MAGIC 0x3b6d250c
+ TAILQ_ENTRY(bereq) list;
+ struct ws ws[1];
+ struct http http[1];
+};
+
struct vbe_conn {
unsigned magic;
#define VBE_CONN_MAGIC 0x0c5e6592
struct vbe_conn *VBE_GetFd(struct sess *sp);
void VBE_ClosedFd(struct worker *w, struct vbe_conn *vc, int already);
void VBE_RecycleFd(struct worker *w, struct vbe_conn *vc);
+struct bereq *vbe_new_bereq(void);
+void vbe_free_bereq(struct bereq *bereq);
/* cache_ban.c */
void BAN_Init(void);
/* A backend IP */
static TAILQ_HEAD(,vbe_conn) vbe_head = TAILQ_HEAD_INITIALIZER(vbe_head);
+static TAILQ_HEAD(,bereq) bereq_head = TAILQ_HEAD_INITIALIZER(bereq_head);
static MTX vbemtx;
/*--------------------------------------------------------------------*/
+struct bereq *
+vbe_new_bereq(void)
+{
+ struct bereq *bereq;
+ volatile unsigned space;
+
+ LOCK(&vbemtx);
+ bereq = TAILQ_FIRST(&bereq_head);
+ if (bereq != NULL)
+ TAILQ_REMOVE(&bereq_head, bereq, list);
+ UNLOCK(&vbemtx);
+ if (bereq == NULL) {
+ space = params->mem_workspace;
+ bereq = calloc(sizeof *bereq + space, 1);
+ if (bereq == NULL)
+ return (NULL);
+ bereq->magic = BEREQ_MAGIC;
+ WS_Init(bereq->ws, bereq + 1, space);
+ }
+ WS_Reset(bereq->ws);
+ return (bereq);
+}
+
+/*--------------------------------------------------------------------*/
+/* XXX: no backpressure on pool size */
+
+void
+vbe_free_bereq(struct bereq *bereq)
+{
+
+ LOCK(&vbemtx);
+ TAILQ_INSERT_HEAD(&bereq_head, bereq, list);
+ UNLOCK(&vbemtx);
+}
+
+/*--------------------------------------------------------------------*/
+
static struct vbe_conn *
vbe_new_conn(void)
{