[vlc-commits] httpd: use linked list for hosts

Rémi Denis-Courmont git at videolan.org
Sun Jun 17 20:13:13 CEST 2018


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Jun 17 20:32:13 2018 +0300| [719eea4b24be881d1b689fd8e3cd180d50cbef73] | committer: Rémi Denis-Courmont

httpd: use linked list for hosts

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=719eea4b24be881d1b689fd8e3cd180d50cbef73
---

 src/network/httpd.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/src/network/httpd.c b/src/network/httpd.c
index 6cf7a710dc..b74fc05d1c 100644
--- a/src/network/httpd.c
+++ b/src/network/httpd.c
@@ -32,6 +32,7 @@
 
 #include <assert.h>
 
+#include <vlc_list.h>
 #include <vlc_network.h>
 #include <vlc_tls.h>
 #include <vlc_strings.h>
@@ -73,6 +74,7 @@ static void httpd_AppendData(httpd_stream_t *stream, uint8_t *p_data, int i_data
 struct httpd_host_t
 {
     struct vlc_common_members obj;
+    struct vlc_list node;
 
     /* ref count */
     unsigned    i_ref;
@@ -899,10 +901,8 @@ httpd_host_t *vlc_rtsp_HostNew(vlc_object_t *p_this)
 static struct httpd
 {
     vlc_mutex_t  mutex;
-
-    httpd_host_t **host;
-    int          i_host;
-} httpd = { VLC_STATIC_MUTEX, NULL, 0 };
+    struct vlc_list hosts;
+} httpd = { VLC_STATIC_MUTEX, VLC_LIST_INITIALIZER(&httpd.hosts) };
 
 static httpd_host_t *httpd_HostCreate(vlc_object_t *p_this,
                                        const char *hostvar,
@@ -926,9 +926,7 @@ static httpd_host_t *httpd_HostCreate(vlc_object_t *p_this,
     vlc_mutex_lock(&httpd.mutex);
 
     /* verify if it already exist */
-    for (int i = 0; i < httpd.i_host; i++) {
-        host = httpd.host[i];
-
+    vlc_list_foreach(host, &httpd.hosts, node) {
         /* cannot mix TLS and non-TLS hosts */
         if (host->port != port
          || (host->p_tls != NULL) != (p_tls != NULL))
@@ -980,7 +978,7 @@ static httpd_host_t *httpd_HostCreate(vlc_object_t *p_this,
     }
 
     /* now add it to httpd */
-    TAB_APPEND(httpd.i_host, httpd.host, host);
+    vlc_list_append(&host->node, &httpd.hosts);
     vlc_mutex_unlock(&httpd.mutex);
 
     vlc_UrlClean(&url);
@@ -1020,8 +1018,8 @@ void httpd_HostDelete(httpd_host_t *host)
         msg_Dbg(host, "httpd_HostDelete: host still in use");
         return;
     }
-    TAB_REMOVE(httpd.i_host, httpd.host, host);
 
+    vlc_list_remove(&host->node);
     vlc_cancel(host->thread);
     vlc_join(host->thread, NULL);
 



More information about the vlc-commits mailing list