[Icecast-dev] [PATCH 20/31] connection: add parser to connection, and use read_headers changes.

Niv Sardi nsardi at smartjog.com
Fri Jul 30 07:54:42 PDT 2010


now we return as soon as we have a header, so if we want more
(that we can only know once we have actually parsed), we reenter later

Signed-off-by: Niv Sardi <nsardi at smartjog.com>
---
 src/connection.c |   22 ++++++++++++++--------
 1 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index 0e75fab..ab8dd4f 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -85,6 +85,7 @@
 typedef struct connection_queue_tag {
     connection_t *con;
     refbuf_t *refbuf;
+    http_parser_t *parser;
     struct connection_queue_tag *next;
 } connection_queue_t;
 
@@ -685,17 +686,20 @@ static int _connection_process (connection_queue_t *node) {
     }
 
     /* process normal HTTP headers */
-    parser = httpp_create_parser();
-    httpp_initialize(parser, NULL);
+    if (node->parser) {
+        parser = node->parser;
+    } else {
+        parser = node->parser = httpp_create_parser();
+        httpp_initialize(parser, NULL);
+    }
+
     err = httpp_parse (parser, header->data, hdrsize);
-    if (err == 0)
-    {
+    if (err == 0) {
         ERROR0("HTTP request parsing failed");
         return -EINVAL;
     }
 
-    if (httpp_getvar (parser, HTTPP_VAR_ERROR_MESSAGE))
-    {
+    if (httpp_getvar (parser, HTTPP_VAR_ERROR_MESSAGE)) {
         ERROR("Error(%s)", httpp_getvar(parser, HTTPP_VAR_ERROR_MESSAGE));
         return err;
     }
@@ -728,8 +732,10 @@ static int _connection_process (connection_queue_t *node) {
     }
 
     header->len -= hdrsize;
-    memmove(header->data, header->data + hdrsize, header->len);
-    client_set_queue (client, header);
+    if (header->len) {
+        memmove(header->data, header->data + hdrsize, header->len);
+        client_set_queue (client, header);
+    }
     refbuf_release(header);
 
     config = config_get_config();
-- 
1.7.1



More information about the Icecast-dev mailing list