[MEDIUM] buffers: add BF_EMPTY and BF_FULL to remove dependency on req/rep->l

It is not always convenient to run checks on req->l in functions to
check if a buffer is empty or full. Now the stream_sock functions
set flags BF_EMPTY and BF_FULL according to the buffer contents. Of
course, functions which touch the buffer contents adjust the flags
too.
diff --git a/src/buffers.c b/src/buffers.c
index fa6b8a9..f7e672d 100644
--- a/src/buffers.c
+++ b/src/buffers.c
@@ -49,6 +49,12 @@
 	if (buf->r == buf->data + BUFSIZE)
 		buf->r = buf->data;
 
+	buf->flags &= ~(BF_EMPTY|BF_FULL);
+	if (buf->l == 0)
+		buf->flags |= BF_EMPTY;
+	if (buf->l >= buf->rlim - buf->data)
+		buf->flags |= BF_FULL;
+
 	return -1;
 }
 
@@ -74,8 +80,14 @@
 	buf->total += chunk->len;
 	if (buf->r == buf->data + BUFSIZE)
 		buf->r = buf->data;
-	chunk->len = 0;
 
+	buf->flags &= ~(BF_EMPTY|BF_FULL);
+	if (buf->l == 0)
+		buf->flags |= BF_EMPTY;
+	if (buf->l >= buf->rlim - buf->data)
+		buf->flags |= BF_FULL;
+
+	chunk->len = 0;
 	return -1;
 }
 
@@ -110,6 +122,12 @@
 	if (b->lr > pos) b->lr += delta;
 	b->l += delta;
 
+	b->flags &= ~(BF_EMPTY|BF_FULL);
+	if (b->l == 0)
+		b->flags |= BF_EMPTY;
+	if (b->l >= b->rlim - b->data)
+		b->flags |= BF_FULL;
+
 	return delta;
 }
 
@@ -145,6 +163,12 @@
 	if (b->lr > pos) b->lr += delta;
 	b->l += delta;
 
+	b->flags &= ~(BF_EMPTY|BF_FULL);
+	if (b->l == 0)
+		b->flags |= BF_EMPTY;
+	if (b->l >= b->rlim - b->data)
+		b->flags |= BF_FULL;
+
 	return delta;
 }
 
@@ -183,6 +207,12 @@
 	if (b->lr > pos) b->lr += delta;
 	b->l += delta;
 
+	b->flags &= ~(BF_EMPTY|BF_FULL);
+	if (b->l == 0)
+		b->flags |= BF_EMPTY;
+	if (b->l >= b->rlim - b->data)
+		b->flags |= BF_FULL;
+
 	return delta;
 }