]> err.no Git - varnish/commitdiff
Unify the recycle functionality of the acceptors, all three used the same
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 13 Jul 2007 07:21:46 +0000 (07:21 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 13 Jul 2007 07:21:46 +0000 (07:21 +0000)
method.

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1683 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache.h
varnish-cache/bin/varnishd/cache_acceptor.c
varnish-cache/bin/varnishd/cache_acceptor.h
varnish-cache/bin/varnishd/cache_acceptor_epoll.c
varnish-cache/bin/varnishd/cache_acceptor_kqueue.c
varnish-cache/bin/varnishd/cache_acceptor_poll.c

index 99d012e7e1ef7927772d445f99356e7bdd045f37..e430213064af1bc8126aff427ef8440ca953e344 100644 (file)
@@ -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);
index 26bb66961322de66501bb5afc4b444d3e4536ff1..b30da4d7158fd8436bcf7efada275d295fb1882e 100644 (file)
@@ -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));
 }
index d578a63b873b67873a84e1e487ed06daee0a58c4..ce62bc5c60d9703e85bff4c775bf0d2f22897dff 100644 (file)
 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)
index b12f5e2f167549ab5bec241aea63f43099df153b..ec9fed1d10269375cfcefe376eae01047ec6f487 100644 (file)
@@ -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) */
index 5da41ff2fd846eeaa62f881074dc290c22c8680b..92edd145106f1b87e2d20b4b989130f493ab0a92 100644 (file)
@@ -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) */
index 03f8004b3bf7fc63d168c1e7c89ce6efdae5260e..1e2bda2145d29f492d8609ee21c766e0689150f2 100644 (file)
@@ -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) */