Commit 548d1b71 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Unify the recycle functionality of the acceptors, all three used the same

method.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@1683 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent abe959e2
......@@ -360,6 +360,7 @@ void vca_return_session(struct sess *sp);
void vca_close_session(struct sess *sp, const char *why);
void VCA_Prep(struct sess *sp);
void VCA_Init(void);
extern int vca_pipes[2];
/* cache_backend.c */
void VBE_Init(void);
......
......@@ -76,6 +76,8 @@ static struct linger linger;
static unsigned char need_sndtimeo, need_rcvtimeo, need_linger, need_test;
int vca_pipes[2];
static void
sock_test(int fd)
{
......@@ -255,7 +257,10 @@ vca_return_session(struct sess *sp)
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
AZ(sp->obj);
AZ(sp->vcl);
vca_act->recycle(sp);
if (sp->fd < 0)
SES_Delete(sp);
else
assert(sizeof sp == write(vca_pipes[1], &sp, sizeof sp));
}
......@@ -273,6 +278,7 @@ VCA_Init(void)
fprintf(stderr, "No acceptor in program\n");
exit (2);
}
AZ(pipe(vca_pipes));
vca_act->init();
AZ(pthread_create(&vca_thread_acct, NULL, vca_acct, NULL));
}
......@@ -32,12 +32,10 @@
struct sess;
typedef void acceptor_init_f(void);
typedef void acceptor_recycle_f(struct sess *);
struct acceptor {
const char *name;
acceptor_init_f *init;
acceptor_recycle_f *recycle;
};
#if defined(HAVE_EPOLL_CTL)
......
......@@ -48,7 +48,6 @@
static pthread_t vca_epoll_thread;
static int epfd = -1;
static int pipes[2];
static TAILQ_HEAD(,sess) sesshead = TAILQ_HEAD_INITIALIZER(sesshead);
......@@ -79,12 +78,12 @@ vca_main(void *arg)
epfd = epoll_create(16);
assert(epfd >= 0);
vca_add(pipes[0], pipes);
vca_add(vca_pipes[0], vca_pipes);
while (1) {
if (epoll_wait(epfd, &ev, 1, 100) > 0) {
if (ev.data.ptr == pipes) {
i = read(pipes[0], &sp, sizeof sp);
if (ev.data.ptr == vca_pipes) {
i = read(vca_pipes[0], &sp, sizeof sp);
assert(i == sizeof sp);
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
TAILQ_INSERT_TAIL(&sesshead, sp, list);
......@@ -119,28 +118,16 @@ vca_main(void *arg)
/*--------------------------------------------------------------------*/
static void
vca_epoll_recycle(struct sess *sp)
{
if (sp->fd < 0)
SES_Delete(sp);
else
assert(sizeof sp == write(pipes[1], &sp, sizeof sp));
}
static void
vca_epoll_init(void)
{
AZ(pipe(pipes));
AZ(pthread_create(&vca_epoll_thread, NULL, vca_main, NULL));
}
struct acceptor acceptor_epoll = {
.name = "epoll",
.init = vca_epoll_init,
.recycle = vca_epoll_recycle,
};
#endif /* defined(HAVE_EPOLL_CTL) */
......@@ -52,7 +52,6 @@ static pthread_t vca_kqueue_thread;
static int kq = -1;
static TAILQ_HEAD(,sess) sesshead = TAILQ_HEAD_INITIALIZER(sesshead);
static int pipes[2];
#define NKEV 100
......@@ -81,9 +80,9 @@ vca_kev(struct kevent *kp)
struct sess *ss[NKEV];
AN(kp->udata);
if (kp->udata == pipes) {
if (kp->udata == vca_pipes) {
j = 0;
i = read(pipes[0], ss, sizeof ss);
i = read(vca_pipes[0], ss, sizeof ss);
if (i == -1 && errno == EAGAIN)
return;
while (i >= sizeof ss[0]) {
......@@ -135,7 +134,7 @@ vca_kqueue_main(void *arg)
j = 0;
EV_SET(&ke[j++], 0, EVFILT_TIMER, EV_ADD, 0, 100, NULL);
EV_SET(&ke[j++], pipes[0], EVFILT_READ, EV_ADD, 0, 0, pipes);
EV_SET(&ke[j++], vca_pipes[0], EVFILT_READ, EV_ADD, 0, 0, vca_pipes);
AZ(kevent(kq, ke, j, NULL, 0, NULL));
nki = 0;
......@@ -172,25 +171,14 @@ vca_kqueue_main(void *arg)
/*--------------------------------------------------------------------*/
static void
vca_kqueue_recycle(struct sess *sp)
{
if (sp->fd < 0)
SES_Delete(sp);
else
assert(write(pipes[1], &sp, sizeof sp) == sizeof sp);
}
static void
vca_kqueue_init(void)
{
int i;
AZ(pipe(pipes));
i = fcntl(pipes[0], F_GETFL);
i = fcntl(vca_pipes[0], F_GETFL);
i |= O_NONBLOCK;
i = fcntl(pipes[0], F_SETFL, i);
i = fcntl(vca_pipes[0], F_SETFL, i);
AZ(pthread_create(&vca_kqueue_thread, NULL, vca_kqueue_main, NULL));
}
......@@ -198,7 +186,6 @@ vca_kqueue_init(void)
struct acceptor acceptor_kqueue = {
.name = "kqueue",
.init = vca_kqueue_init,
.recycle = vca_kqueue_recycle,
};
#endif /* defined(HAVE_KQUEUE) */
......@@ -51,8 +51,6 @@ static pthread_t vca_poll_thread;
static struct pollfd *pollfd;
static unsigned npoll;
static int pipes[2];
static TAILQ_HEAD(,sess) sesshead = TAILQ_HEAD_INITIALIZER(sesshead);
/*--------------------------------------------------------------------*/
......@@ -109,13 +107,13 @@ vca_main(void *arg)
(void)arg;
vca_poll(pipes[0]);
vca_poll(vca_pipes[0]);
while (1) {
v = poll(pollfd, npoll, 100);
if (v && pollfd[pipes[0]].revents) {
if (v && pollfd[vca_pipes[0]].revents) {
v--;
i = read(pipes[0], &sp, sizeof sp);
i = read(vca_pipes[0], &sp, sizeof sp);
assert(i == sizeof sp);
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
TAILQ_INSERT_TAIL(&sesshead, sp, list);
......@@ -152,27 +150,16 @@ vca_main(void *arg)
/*--------------------------------------------------------------------*/
static void
vca_poll_recycle(struct sess *sp)
{
if (sp->fd < 0)
SES_Delete(sp);
else
assert(sizeof sp == write(pipes[1], &sp, sizeof sp));
}
static void
vca_poll_init(void)
{
AZ(pipe(pipes));
AZ(pthread_create(&vca_poll_thread, NULL, vca_main, NULL));
}
struct acceptor acceptor_poll = {
.name = "poll",
.init = vca_poll_init,
.recycle = vca_poll_recycle,
};
#endif /* defined(HAVE_POLL) */
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