[MEDIUM] use buffer_check_timeouts instead of stream_sock_check_timeouts()
It's more appropriate to use buffer_check_timeouts() to check for buffer
timeouts and si->shutw/shutr to shutdown the stream interfaces.
diff --git a/src/client.c b/src/client.c
index 32e90ba..547e215 100644
--- a/src/client.c
+++ b/src/client.c
@@ -174,6 +174,7 @@
s->si[0].err_type = SI_ET_NONE;
s->si[0].err_loc = NULL;
s->si[0].owner = t;
+ s->si[0].shutr = stream_sock_shutr;
s->si[0].shutw = stream_sock_shutw;
s->si[0].fd = cfd;
s->si[0].exp = TICK_ETERNITY;
@@ -183,6 +184,7 @@
s->si[1].err_type = SI_ET_NONE;
s->si[1].err_loc = NULL;
s->si[1].owner = t;
+ s->si[1].shutr = stream_sock_shutr;
s->si[1].shutw = stream_sock_shutw;
s->si[1].exp = TICK_ETERNITY;
s->si[1].fd = -1; /* just to help with debugging */
diff --git a/src/proto_http.c b/src/proto_http.c
index 0a09b2d..d5760ae 100644
--- a/src/proto_http.c
+++ b/src/proto_http.c
@@ -661,15 +661,29 @@
/* Check timeouts only during data phase for now */
if (unlikely(t->state & TASK_WOKEN_TIMER)) {
- if (s->rep->cons->state == SI_ST_EST) {
- stream_sock_data_check_timeouts(s->rep->cons->fd);
- if (tick_is_expired(s->rep->analyse_exp, now_ms))
- s->rep->flags |= BF_ANA_TIMEOUT;
+ buffer_check_timeouts(s->req);
+ buffer_check_timeouts(s->rep);
+
+ if (unlikely(s->req->flags & (BF_READ_TIMEOUT|BF_WRITE_TIMEOUT))) {
+ if (s->req->flags & BF_READ_TIMEOUT) {
+ buffer_shutw(s->req);
+ s->req->cons->shutr(s->req->prod);
+ }
+ if (s->req->flags & BF_WRITE_TIMEOUT) {
+ buffer_shutw(s->req);
+ s->req->cons->shutw(s->req->cons);
+ }
}
- if (s->req->cons->state == SI_ST_EST) {
- stream_sock_data_check_timeouts(s->req->cons->fd);
- if (tick_is_expired(s->req->analyse_exp, now_ms))
- s->req->flags |= BF_ANA_TIMEOUT;
+
+ if (unlikely(s->rep->flags & (BF_READ_TIMEOUT|BF_WRITE_TIMEOUT))) {
+ if (s->rep->flags & BF_READ_TIMEOUT) {
+ buffer_shutw(s->rep);
+ s->rep->cons->shutr(s->rep->prod);
+ }
+ if (s->rep->flags & BF_WRITE_TIMEOUT) {
+ buffer_shutw(s->rep);
+ s->rep->cons->shutw(s->rep->cons);
+ }
}
/* Note that we don't check nor indicate if we wake up because
* of a timeout on a stream interface.
diff --git a/src/stream_sock.c b/src/stream_sock.c
index 3cdf3f2..efc33a6 100644
--- a/src/stream_sock.c
+++ b/src/stream_sock.c
@@ -485,8 +485,8 @@
}
/*
- * This function performs a shutdown-write on a stream interface in a connected
- * state (it does nothing for other states). It either shuts the write side or
+ * This function performs a shutdown-write on a stream interface in a connected or
+ * init state (it does nothing for other states). It either shuts the write side
* closes the file descriptor and marks itself as closed. No buffer flags are
* changed, it's up to the caller to adjust them. The sole purpose of this
* function is to be called from the other stream interface to notify of a
@@ -496,7 +496,7 @@
*/
int stream_sock_shutw(struct stream_interface *si)
{
- if (si->state != SI_ST_EST)
+ if (si->state != SI_ST_EST && si->state != SI_ST_CON)
return 0;
if (si->ib->flags & BF_SHUTR) {
@@ -510,6 +510,30 @@
}
/*
+ * This function performs a shutdown-read on a stream interface in a connected or
+ * init state (it does nothing for other states). It either shuts the read side or
+ * closes the file descriptor and marks itself as closed. No buffer flags are
+ * changed, it's up to the caller to adjust them. The sole purpose of this
+ * function is to be called from the other stream interface to notify of a
+ * close_read, or by itself upon a full write leading to an empty buffer.
+ * It normally returns zero, unless it has completely closed the socket, in
+ * which case it returns 1.
+ */
+int stream_sock_shutr(struct stream_interface *si)
+{
+ if (si->state != SI_ST_EST && si->state != SI_ST_CON)
+ return 0;
+
+ if (si->ib->flags & BF_SHUTW) {
+ fd_delete(si->fd);
+ si->state = SI_ST_CLO;
+ return 1;
+ }
+ EV_FD_CLR(si->fd, DIR_RD);
+ return 0;
+}
+
+/*
* This function only has to be called once after a wakeup event during a data
* phase. It controls the file descriptor's status, as well as read and write
* timeouts.