[MEDIUM] buffers: add BF_READ_ATTACHED and BF_ANA_TIMEOUT

Those two flags will be used to wake up analysers only when
needed.
diff --git a/include/types/buffers.h b/include/types/buffers.h
index c35ef37..b04daaf 100644
--- a/include/types/buffers.h
+++ b/include/types/buffers.h
@@ -54,8 +54,6 @@
 #define BF_READ_TIMEOUT   0x000004  /* timeout while waiting for producer */
 #define BF_READ_ERROR     0x000008  /* unrecoverable error on producer side */
 #define BF_READ_ACTIVITY  (BF_READ_NULL|BF_READ_PARTIAL|BF_READ_ERROR)
-#define BF_READ_STATUS    (BF_READ_NULL|BF_READ_PARTIAL|BF_READ_ERROR|BF_READ_TIMEOUT)
-#define BF_CLEAR_READ     (~BF_READ_STATUS)
 
 #define BF_FULL           0x000010  /* buffer cannot accept any more data (l >= rlim-data) */
 #define BF_SHUTR          0x000020  /* producer has already shut down */
@@ -67,8 +65,6 @@
 #define BF_WRITE_TIMEOUT  0x000400  /* timeout while waiting for consumer */
 #define BF_WRITE_ERROR    0x000800  /* unrecoverable error on consumer side */
 #define BF_WRITE_ACTIVITY (BF_WRITE_NULL|BF_WRITE_PARTIAL|BF_WRITE_ERROR)
-#define BF_WRITE_STATUS   (BF_WRITE_NULL|BF_WRITE_PARTIAL|BF_WRITE_ERROR|BF_WRITE_TIMEOUT)
-#define BF_CLEAR_WRITE    (~BF_WRITE_STATUS)
 
 #define BF_EMPTY          0x001000  /* buffer is empty */
 #define BF_SHUTW          0x002000  /* consumer has already shut down */
@@ -84,14 +80,21 @@
  * buffer.
  */
 #define BF_HIJACK         0x040000  /* the producer is temporarily replaced */
+#define BF_ANA_TIMEOUT    0x080000  /* the analyser timeout has expired */
+#define BF_READ_ATTACHED  0x100000  /* the read side is attached for the first time */
+
+/* Use these masks to clear the flags before going back to lower layers */
+#define BF_CLEAR_READ     (~(BF_READ_NULL|BF_READ_PARTIAL|BF_READ_ERROR|BF_READ_ATTACHED))
+#define BF_CLEAR_WRITE    (~(BF_WRITE_NULL|BF_WRITE_PARTIAL|BF_WRITE_ERROR))
+#define BF_CLEAR_TIMEOUT  (~(BF_READ_TIMEOUT|BF_WRITE_TIMEOUT|BF_ANA_TIMEOUT))
 
 /* Masks which define input bits for stream interfaces and stream analysers */
-#define BF_MASK_INTERFACE_I     (BF_FULL|BF_HIJACK|BF_READ_ENA|BF_READ_STATUS|BF_SHUTR_NOW|BF_SHUTR|BF_SHUTW)
-#define BF_MASK_INTERFACE_O     (BF_EMPTY|BF_HIJACK|BF_WRITE_ENA|BF_WRITE_STATUS|BF_SHUTW_NOW|BF_SHUTR|BF_SHUTW)
+#define BF_MASK_INTERFACE_I     (BF_FULL|BF_HIJACK|BF_READ_ENA|BF_READ_ACTIVITY|BF_READ_TIMEOUT|BF_SHUTR_NOW|BF_SHUTR|BF_SHUTW)
+#define BF_MASK_INTERFACE_O     (BF_EMPTY|BF_HIJACK|BF_WRITE_ENA|BF_WRITE_ACTIVITY|BF_WRITE_TIMEOUT|BF_SHUTW_NOW|BF_SHUTR|BF_SHUTW)
 #define BF_MASK_INTERFACE       (BF_MASK_INTF_I | BF_MASK_INTF_O)
 
-#define BF_MASK_ANALYSER        (BF_FULL|BF_READ_STATUS|BF_SHUTR|BF_WRITE_ERROR)
-#define BF_MASK_HIJACKER        (BF_FULL|BF_WRITE_STATUS|BF_WRITE_TIMEOUT|BF_SHUTW)
+#define BF_MASK_ANALYSER        (BF_FULL|BF_READ_ACTIVITY|BF_READ_TIMEOUT|BF_ANA_TIMEOUT|BF_SHUTR|BF_READ_ATTACHED|BF_WRITE_ERROR)
+#define BF_MASK_HIJACKER        (BF_FULL|BF_WRITE_ACTIVITY|BF_WRITE_TIMEOUT|BF_SHUTW)
 
 
 /* Analysers (buffer->analysers).
diff --git a/src/client.c b/src/client.c
index aed9415..953e41e 100644
--- a/src/client.c
+++ b/src/client.c
@@ -342,6 +342,8 @@
 		s->req->cons = &s->si[1];
 		s->si[0].ib = s->si[1].ob = s->req;
 
+		s->req->flags |= BF_READ_ATTACHED; /* the producer is already connected */
+
 		if (p->mode == PR_MODE_HTTP) /* reserve some space for header rewriting */
 			s->req->rlim -= MAXREWRITE;
 
diff --git a/src/proto_http.c b/src/proto_http.c
index b32c042..31c9879 100644
--- a/src/proto_http.c
+++ b/src/proto_http.c
@@ -869,8 +869,8 @@
 		if (s->req->cons->state == SI_ST_EST)
 			stream_sock_data_finish(s->req->cons->fd);
 
-		s->req->flags &= BF_CLEAR_READ & BF_CLEAR_WRITE;
-		s->rep->flags &= BF_CLEAR_READ & BF_CLEAR_WRITE;
+		s->req->flags &= BF_CLEAR_READ & BF_CLEAR_WRITE & BF_CLEAR_TIMEOUT;
+		s->rep->flags &= BF_CLEAR_READ & BF_CLEAR_WRITE & BF_CLEAR_TIMEOUT;
 		s->si[0].prev_state = s->si[0].state;
 		s->si[1].prev_state = s->si[1].state;
 
@@ -3683,8 +3683,7 @@
 			 */
 		}
 
-		if (!rep->analysers)
-			buffer_write_ena(t->rep);
+		rep->flags |= BF_READ_ATTACHED; /* producer is now attached */
 		req->wex = TICK_ETERNITY;
 		return 0;
 	}