Commit 9fec4441 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Give SES_Rx() a timeout argument, and take that bit of complexity

out of http1_wait()
parent 8e216d58
......@@ -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); \
......
......@@ -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);
......
......@@ -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) {
......
......@@ -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;
......
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