[master] 9fec444 Give SES_Rx() a timeout argument, and take that bit of complexity out of http1_wait()
Poul-Henning Kamp
phk at FreeBSD.org
Mon Mar 23 22:32:12 CET 2015
commit 9fec4441ad54514be6cb06f80882cf148689aa13
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Mar 23 21:31:20 2015 +0000
Give SES_Rx() a timeout argument, and take that bit of complexity
out of http1_wait()
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index a26a383..15ac93e 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -985,17 +985,18 @@ task_func_t SES_Proto_Sess;
task_func_t SES_Proto_Req;
enum htc_status_e {
- HTC_S_EMPTY = -3,
+ HTC_S_EMPTY = -4,
+ HTC_S_TIMEOUT = -3,
HTC_S_OVERFLOW = -2,
- HTC_S_EOF = -1,
- HTC_S_OK = 0,
+ HTC_S_EOF = -1,
+ HTC_S_OK = 0,
HTC_S_COMPLETE = 1
};
void SES_RxInit(struct http_conn *htc, struct ws *ws,
unsigned maxbytes, unsigned maxhdr);
void SES_RxReInit(struct http_conn *htc);
-enum htc_status_e SES_Rx(struct http_conn *htc);
+enum htc_status_e SES_Rx(struct http_conn *htc, double tmo);
#define SESS_ATTR(UP, low, typ, len) \
int SES_Get_##low(const struct sess *sp, typ *dst); \
diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c
index ca0a539..b54fb0a 100644
--- a/bin/varnishd/cache/cache_session.c
+++ b/bin/varnishd/cache/cache_session.c
@@ -41,6 +41,7 @@
#include "config.h"
#include <errno.h>
+#include <poll.h>
#include <stdio.h>
#include <stdlib.h>
@@ -205,9 +206,10 @@ SES_RxReInit(struct http_conn *htc)
*/
enum htc_status_e
-SES_Rx(struct http_conn *htc)
+SES_Rx(struct http_conn *htc, double tmo)
{
- int i;
+ int i, j;
+ struct pollfd pfd[1];
CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC);
AN(htc->ws->r);
@@ -216,6 +218,17 @@ SES_Rx(struct http_conn *htc)
i = (htc->ws->r - htc->rxbuf_e) - 1; /* space for NUL */
if (i <= 0)
return (HTC_S_OVERFLOW);
+ if (tmo > 0.0) {
+ pfd[0].fd = htc->fd;
+ pfd[0].events = POLLIN;
+ pfd[0].revents = 0;
+ j = (int)floor(tmo * 1e3);
+ if (j == 0)
+ j++;
+ j = poll(pfd, 1, j);
+ if (j == 0)
+ return (HTC_S_TIMEOUT);
+ }
i = read(htc->fd, htc->rxbuf_e, i);
if (i <= 0)
return (HTC_S_EOF);
diff --git a/bin/varnishd/http1/cache_http1_fetch.c b/bin/varnishd/http1/cache_http1_fetch.c
index 855268b..bae29c5 100644
--- a/bin/varnishd/http1/cache_http1_fetch.c
+++ b/bin/varnishd/http1/cache_http1_fetch.c
@@ -153,7 +153,7 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo, const char *def_host)
first = 1;
do {
- hs = SES_Rx(htc);
+ hs = SES_Rx(htc, 0);
if (hs == HTC_S_OK)
hs = HTTP1_Complete(htc);
if (hs == HTC_S_OVERFLOW) {
diff --git a/bin/varnishd/http1/cache_http1_fsm.c b/bin/varnishd/http1/cache_http1_fsm.c
index 75ab85a..e17e2bd 100644
--- a/bin/varnishd/http1/cache_http1_fsm.c
+++ b/bin/varnishd/http1/cache_http1_fsm.c
@@ -34,7 +34,6 @@
#include "config.h"
#include <errno.h>
-#include <poll.h>
#include <stdio.h>
#include <stdlib.h>
@@ -52,8 +51,7 @@
static enum req_fsm_nxt
http1_wait(struct sess *sp, struct worker *wrk, struct req *req)
{
- int j, tmo;
- struct pollfd pfd[1];
+ int tmo;
double now, when;
enum sess_close why = SC_NULL;
enum htc_status_e hs;
@@ -71,19 +69,11 @@ http1_wait(struct sess *sp, struct worker *wrk, struct req *req)
assert(isnan(req->t_prev));
assert(isnan(req->t_req));
- tmo = (int)(1e3 * cache_param->timeout_linger);
+ tmo = (int)floor(1e3 * cache_param->timeout_linger);
while (1) {
- pfd[0].fd = sp->fd;
- pfd[0].events = POLLIN;
- pfd[0].revents = 0;
- j = poll(pfd, 1, tmo);
- assert(j >= 0);
+ hs = SES_Rx(req->htc, tmo * 1e3);
now = VTIM_real();
- if (j != 0)
- hs = SES_Rx(req->htc);
- else
- hs = HTC_S_OK; // XXX HTC_S_TIMEOUT ?
- if (hs == HTC_S_OK)
+ if (hs == HTC_S_OK || hs == HTC_S_TIMEOUT)
hs = HTTP1_Complete(req->htc);
if (hs == HTC_S_COMPLETE) {
/* Got it, run with it */
@@ -110,7 +100,7 @@ http1_wait(struct sess *sp, struct worker *wrk, struct req *req)
break;
}
when = sp->t_idle + cache_param->timeout_linger;
- tmo = (int)(1e3 * (when - now));
+ tmo = (int)floor(1e3 * (when - now));
if (when < now || tmo == 0) {
wrk->stats->sess_herd++;
SES_ReleaseReq(req);
@@ -126,7 +116,7 @@ http1_wait(struct sess *sp, struct worker *wrk, struct req *req)
/* Record first byte received time stamp */
req->t_first = now;
when = req->t_first + cache_param->timeout_req;
- tmo = (int)(1e3 * (when - now));
+ tmo = (int)floor(1e3 * (when - now));
if (when < now || tmo == 0) {
why = SC_RX_TIMEOUT;
break;
More information about the varnish-commit
mailing list