[xiph-commits] r8187 - icecast/branches/kh/icecast/src

karl at motherfish-iii.xiph.org karl at motherfish-iii.xiph.org
Wed Nov 10 08:09:21 PST 2004


Author: karl
Date: 2004-11-10 08:09:20 -0800 (Wed, 10 Nov 2004)
New Revision: 8187

Modified:
   icecast/branches/kh/icecast/src/format.c
   icecast/branches/kh/icecast/src/fserve.c
   icecast/branches/kh/icecast/src/fserve.h
Log:
update file serve handler to utilise refbufs


Modified: icecast/branches/kh/icecast/src/format.c
===================================================================
--- icecast/branches/kh/icecast/src/format.c	2004-11-10 14:35:18 UTC (rev 8186)
+++ icecast/branches/kh/icecast/src/format.c	2004-11-10 16:09:20 UTC (rev 8187)
@@ -142,21 +142,25 @@
     int ret;
     const char *buf;
     unsigned int len;
-    refbuf_t * refbuf = client->refbuf;
+    refbuf_t *refbuf = client->refbuf;
 
-    if (refbuf == NULL)
+    if (refbuf->next == NULL && client->pos == refbuf->len)
         return 0;
+
+    /* move to the next buffer if we have finished with the current one */
+    if (refbuf->next && client->pos == refbuf->len)
+    {
+        client_set_queue (client, refbuf->next);
+        refbuf = client->refbuf;
+    }
+
     buf = refbuf->data + client->pos;
     len = refbuf->len - client->pos;
 
     ret = client_send_bytes (client, buf, len);
 
-    if (ret == len)
-    {
-        client_set_queue (client, refbuf->next);
-        if (client->refbuf == NULL)
-            client->write_to_client = source->format->write_buf_to_client;
-    }
+    if (ret > 0)
+        client->pos += ret;
 
     return ret;
 }

Modified: icecast/branches/kh/icecast/src/fserve.c
===================================================================
--- icecast/branches/kh/icecast/src/fserve.c	2004-11-10 14:35:18 UTC (rev 8186)
+++ icecast/branches/kh/icecast/src/fserve.c	2004-11-10 16:09:20 UTC (rev 8187)
@@ -244,13 +244,16 @@
 
         while (fclient)
         {
+            /* can we process this client */
             if (fclient->ready)
             {
-                /* we can process this client */
+                client_t *client = fclient->client;
+                refbuf_t *refbuf = client->refbuf;
                 fclient->ready = 0;
-                if(fclient->offset >= fclient->datasize) {
+                if (client->pos == refbuf->len)
+                {
                     /* Grab a new chunk */
-                    bytes = fread(fclient->buf, 1, BUFSIZE, fclient->file);
+                    bytes = fread (refbuf->data, 1, BUFSIZE, fclient->file);
                     if (bytes == 0)
                     {
                         fserve_t *to_go = fclient;
@@ -261,21 +264,14 @@
                         client_tree_changed = 1;
                         continue;
                     }
-                    fclient->offset = 0;
-                    fclient->datasize = bytes;
+                    refbuf->len = bytes;
+                    client->pos = 0;
                 }
 
                 /* Now try and send current chunk. */
-                sbytes = client_send_bytes (fclient->client, 
-                        &fclient->buf[fclient->offset], 
-                        fclient->datasize - fclient->offset);
+                sbytes = client->write_to_client (NULL, client);
 
-                /* TODO: remove clients if they take too long. */
-                if(sbytes > 0) {
-                    fclient->offset += sbytes;
-                }
-
-                if (fclient->client->con->error)
+                if (client->con->error)
                 {
                     fserve_t *to_go = fclient;
                     fclient = fclient->next;
@@ -339,20 +335,20 @@
     }
 }
 
-static void fserve_client_destroy(fserve_t *client)
+static void fserve_client_destroy(fserve_t *fclient)
 {
-    if(client) {
-        if(client->buf)
-            free(client->buf);
-        if(client->file)
-            fclose(client->file);
+    if (fclient)
+    {
+        if (fclient->file)
+            fclose (fclient->file);
 
-        if(client->client)
-            client_destroy(client->client);
-        free(client);
+        if (fclient->client)
+            client_destroy (fclient->client);
+        free (fclient);
     }
 }
 
+
 int fserve_client_create(client_t *httpclient, char *path)
 {
     fserve_t *client = calloc(1, sizeof(fserve_t));
@@ -371,10 +367,10 @@
     }
 
     client->client = httpclient;
-    client->offset = 0;
-    client->datasize = 0;
     client->ready = 0;
-    client->buf = malloc(BUFSIZE);
+    client_set_queue (httpclient, NULL);
+    httpclient->refbuf = refbuf_new (BUFSIZE);
+    httpclient->pos = BUFSIZE;
 
     global_lock();
     if(global.clients >= client_limit) {

Modified: icecast/branches/kh/icecast/src/fserve.h
===================================================================
--- icecast/branches/kh/icecast/src/fserve.h	2004-11-10 14:35:18 UTC (rev 8186)
+++ icecast/branches/kh/icecast/src/fserve.h	2004-11-10 16:09:20 UTC (rev 8187)
@@ -20,10 +20,7 @@
     client_t *client;
 
     FILE *file;
-    int offset;
-    int datasize;
     int ready;
-    unsigned char *buf;
     struct _fserve_t *next;
 } fserve_t;
 



More information about the commits mailing list