]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MEDIUM] use buffer_check_timeouts instead of stream_sock_check_timeouts()
authorWilly Tarreau <w@1wt.eu>
Thu, 4 Sep 2008 09:19:41 +0000 (11:19 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 2 Nov 2008 09:19:10 +0000 (10:19 +0100)
It's more appropriate to use buffer_check_timeouts() to check for buffer
timeouts and si->shutw/shutr to shutdown the stream interfaces.

include/proto/stream_sock.h
include/types/stream_interface.h
src/client.c
src/proto_http.c
src/stream_sock.c

index 45064bea9efeac22c4db45e404b98f485cc7ab4b..d005be56f7bf7aee293aa0b0facbcc0b01567c6f 100644 (file)
@@ -36,6 +36,7 @@ int stream_sock_write(int fd);
 int stream_sock_data_check_timeouts(int fd);
 int stream_sock_data_update(int fd);
 int stream_sock_data_finish(int fd);
+int stream_sock_shutr(struct stream_interface *si);
 int stream_sock_shutw(struct stream_interface *si);
 
 
index cd7fb706a296d9211533d05179ef0c6346c8348e..ba8d7a76ee1db839d5cb2f979f23ec032ef3955f 100644 (file)
@@ -62,6 +62,7 @@ struct stream_interface {
        void *owner;            /* generally a (struct task*) */
        int fd;                 /* file descriptor for a stream driver when known */
        unsigned int exp;       /* wake up time for connect, queue, turn-around, ... */
+       int (*shutr)(struct stream_interface *);  /* shutr function */
        int (*shutw)(struct stream_interface *);  /* shutw function */
        struct buffer *ib, *ob; /* input and output buffers */
        unsigned int err_type;  /* first error detected, one of SI_ET_* */
index 32e90ba4edeef344234d6c1cea22dc8ea42d3da0..547e215da2350861301671c3d3e6fff8da213bc8 100644 (file)
@@ -174,6 +174,7 @@ int event_accept(int fd) {
                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 @@ int event_accept(int fd) {
                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 */
index 0a09b2d1ebdb19a82c07f8899f952aab4d65c6cb..d5760aedd7f7fcb0b7962467b69491f3560d595e 100644 (file)
@@ -661,15 +661,29 @@ void process_session(struct task *t, int *next)
 
        /* 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.
index 3cdf3f270645caa55fdd3c09db6d0dc66e78961c..efc33a6ef880b65cb4bc086ba78b9c25821b5a5e 100644 (file)
@@ -485,8 +485,8 @@ int stream_sock_write(int fd) {
 }
 
 /*
- * 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_write(int fd) {
  */
 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) {
@@ -509,6 +509,30 @@ int stream_sock_shutw(struct stream_interface *si)
        return 0;
 }
 
+/*
+ * 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