From f036751b28aa3c40a696f06317f65f72560bed45 Mon Sep 17 00:00:00 2001 From: phk Date: Mon, 8 Oct 2007 08:14:09 +0000 Subject: [PATCH] More acceptor work: Make HTC_Rx() return a distinct value for overflow/blast. Teach vca_handover() to handle HTC_Rx() return status Use HTC_Rx/vca_handover this way in all three acceptors. Eliminate vca_pollsession() Teach CNT_First() about HTC_Rx states. Log which acceptor we use in shmlog git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2084 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache_acceptor.c | 41 ++++++++----------- varnish-cache/bin/varnishd/cache_acceptor.h | 2 - .../bin/varnishd/cache_acceptor_epoll.c | 12 ++---- .../bin/varnishd/cache_acceptor_kqueue.c | 9 +--- .../bin/varnishd/cache_acceptor_poll.c | 9 ++-- varnish-cache/bin/varnishd/cache_center.c | 20 +++++---- varnish-cache/bin/varnishd/cache_httpconn.c | 8 +++- 7 files changed, 43 insertions(+), 58 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache_acceptor.c b/varnish-cache/bin/varnishd/cache_acceptor.c index 4ef5a3db..bfb62e9a 100644 --- a/varnish-cache/bin/varnishd/cache_acceptor.c +++ b/varnish-cache/bin/varnishd/cache_acceptor.c @@ -53,7 +53,6 @@ #include "cache.h" #include "cache_acceptor.h" - static struct acceptor *vca_acceptors[] = { #if defined(HAVE_KQUEUE) &acceptor_kqueue, @@ -204,34 +203,25 @@ vca_acct(void *arg) /*--------------------------------------------------------------------*/ void -vca_handover(struct sess *sp, int bad) +vca_handover(struct sess *sp, int status) { - if (bad) { - vca_close_session(sp, - bad == 1 ? "overflow" : "no request"); + switch (status) { + case -2: + vca_close_session(sp, "blast"); + SES_Delete(sp); + break; + case -1: + vca_close_session(sp, "no request"); SES_Delete(sp); - return; + break; + case 1: + sp->step = STP_RECV; + WRK_QueueSession(sp); + break; + default: + INCOMPL(); } - sp->step = STP_RECV; - WRK_QueueSession(sp); -} - -/*--------------------------------------------------------------------*/ - -int -vca_pollsession(struct sess *sp) -{ - int i; - - i = HTC_Rx(sp->htc); - /* XXX: fix retval */ - if (i == 0) /* more needed */ - return (-1); - if (i == 1) /* Yes, done */ - return (0); - vca_close_session(sp, "err/poll"); - return (1); } /*--------------------------------------------------------------------*/ @@ -280,4 +270,5 @@ VCA_Init(void) AZ(pipe(vca_pipes)); vca_act->init(); AZ(pthread_create(&vca_thread_acct, NULL, vca_acct, NULL)); + VSL(SLT_Debug, 0, "Acceptor is %s", vca_act->name); } diff --git a/varnish-cache/bin/varnishd/cache_acceptor.h b/varnish-cache/bin/varnishd/cache_acceptor.h index ce62bc5c..155347b7 100644 --- a/varnish-cache/bin/varnishd/cache_acceptor.h +++ b/varnish-cache/bin/varnishd/cache_acceptor.h @@ -52,5 +52,3 @@ extern struct acceptor acceptor_poll; /* vca_acceptor.c */ void vca_handover(struct sess *sp, int bad); -int vca_pollsession(struct sess *sp); - diff --git a/varnish-cache/bin/varnishd/cache_acceptor_epoll.c b/varnish-cache/bin/varnishd/cache_acceptor_epoll.c index 0b9dd32c..6ffd9c26 100644 --- a/varnish-cache/bin/varnishd/cache_acceptor_epoll.c +++ b/varnish-cache/bin/varnishd/cache_acceptor_epoll.c @@ -90,15 +90,11 @@ vca_main(void *arg) vca_add(sp->fd, sp); } else { CAST_OBJ_NOTNULL(sp, ev.data.ptr, SESS_MAGIC); - i = vca_pollsession(sp); - if (i >= 0) { + i = HTC_Rx(sp->htc); + if (i != 0) VTAILQ_REMOVE(&sesshead, sp, list); - if (sp->fd != -1) - vca_del(sp->fd); - if (i == 0) - vca_handover(sp, i); - else - SES_Delete(sp); + vca_del(sp->fd); + vca_handover(sp, i); } } } diff --git a/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c b/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c index b83aaa55..b98f4b99 100644 --- a/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c +++ b/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c @@ -102,13 +102,8 @@ vca_kev(const struct kevent *kp) if (i == 0) return; /* more needed */ VTAILQ_REMOVE(&sesshead, sp, list); - if (i > 0) { - vca_kq_sess(sp, EV_DELETE); - vca_handover(sp, i); - } else { - vca_close_session(sp, "err/poll"); - SES_Delete(sp); - } + vca_kq_sess(sp, EV_DELETE); + vca_handover(sp, i); return; } else if (kp->flags == EV_EOF) { VTAILQ_REMOVE(&sesshead, sp, list); diff --git a/varnish-cache/bin/varnishd/cache_acceptor_poll.c b/varnish-cache/bin/varnishd/cache_acceptor_poll.c index 2853f70d..8a2587c8 100644 --- a/varnish-cache/bin/varnishd/cache_acceptor_poll.c +++ b/varnish-cache/bin/varnishd/cache_acceptor_poll.c @@ -131,15 +131,12 @@ vca_main(void *arg) fd = sp->fd; if (pollfd[fd].revents) { v--; - i = vca_pollsession(sp); - if (i < 0) + i = HTC_Rx(sp->htc); + if (i == 0) continue; VTAILQ_REMOVE(&sesshead, sp, list); vca_unpoll(fd); - if (i == 0) - vca_handover(sp, i); - else - SES_Delete(sp); + vca_handover(sp, i); continue; } if (sp->t_open > deadline) diff --git a/varnish-cache/bin/varnishd/cache_center.c b/varnish-cache/bin/varnishd/cache_center.c index 8f307b15..3462555a 100644 --- a/varnish-cache/bin/varnishd/cache_center.c +++ b/varnish-cache/bin/varnishd/cache_center.c @@ -370,17 +370,21 @@ cnt_first(struct sess *sp) do i = HTC_Rx(sp->htc); while (i == 0); - if (i == 1) { + switch (i) { + case 1: sp->step = STP_RECV; - return (0); - } - if (i == -1) + break; + case -1: + vca_close_session(sp, "error"); + sp->step = STP_DONE; + break; + case -2: vca_close_session(sp, "blast"); - else if (i == 2) - vca_close_session(sp, "silent"); - else + sp->step = STP_DONE; + break; + default: INCOMPL(); - sp->step = STP_DONE; + } return (0); } diff --git a/varnish-cache/bin/varnishd/cache_httpconn.c b/varnish-cache/bin/varnishd/cache_httpconn.c index c0fd04cf..2129e59d 100644 --- a/varnish-cache/bin/varnishd/cache_httpconn.c +++ b/varnish-cache/bin/varnishd/cache_httpconn.c @@ -126,6 +126,7 @@ HTC_Reinit(struct http_conn *htc) /*-------------------------------------------------------------------- * Receive more HTTP protocol bytes * Returns: + * -2 overflow * -1 error * 0 more needed * 1 got complete HTTP header @@ -138,9 +139,12 @@ HTC_Rx(struct http_conn *htc) CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC); i = (htc->ws->r - htc->rxbuf.e) - 1; /* space for NUL */ - if (i > 0) - i = read(htc->fd, htc->rxbuf.e, i); if (i <= 0) { + WS_ReleaseP(htc->ws, htc->rxbuf.b); + return (-2); + } + i = read(htc->fd, htc->rxbuf.e, i); + if (i < 0) { WS_ReleaseP(htc->ws, htc->rxbuf.b); return (-1); } -- 2.39.5