[vlc-commits] https: add vlc_http_connect()

Rémi Denis-Courmont git at videolan.org
Sat Dec 19 13:06:49 CET 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Dec 19 13:42:04 2015 +0200| [c8f672ffe5f10b5d80191bc2d3b92ae1e7493637] | committer: Rémi Denis-Courmont

https: add vlc_http_connect()

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

 modules/access/http/connmgr.c   |   46 +++++++++++++++++++++++++++++++++++++++
 modules/access/http/transport.c |   29 ++++++++++++++++++------
 modules/access/http/transport.h |    3 +++
 3 files changed, 71 insertions(+), 7 deletions(-)

diff --git a/modules/access/http/connmgr.c b/modules/access/http/connmgr.c
index 2546f9b..318483e 100644
--- a/modules/access/http/connmgr.c
+++ b/modules/access/http/connmgr.c
@@ -84,6 +84,52 @@ static vlc_tls_t *vlc_https_connect_i11e(vlc_tls_creds_t *creds,
     return res;
 }
 
+struct vlc_http_connecting
+{
+    vlc_object_t *obj;
+    const char *host;
+    unsigned port;
+    vlc_sem_t done;
+};
+
+static void *vlc_http_connect_thread(void *data)
+{
+    struct vlc_http_connecting *c = data;
+    vlc_tls_t *tls;
+
+    tls = vlc_http_connect(c->obj, c->host, c->port);
+    vlc_sem_post(&c->done);
+    return tls;
+}
+
+/** Interruptible vlc_http_connect() */
+static vlc_tls_t *vlc_http_connect_i11e(vlc_object_t *obj,
+                                        const char *host, unsigned port)
+{
+    struct vlc_http_connecting c;
+    vlc_thread_t th;
+
+    c.obj = obj;
+    c.host = host;
+    c.port = port;
+    vlc_sem_init(&c.done, 0);
+
+    if (vlc_clone(&th, vlc_http_connect_thread, &c, VLC_THREAD_PRIORITY_INPUT))
+        return NULL;
+
+    void *res;
+
+    if (vlc_sem_wait_i11e(&c.done))
+        vlc_cancel(th);
+    vlc_join(th, &res);
+    vlc_sem_destroy(&c.done);
+
+    if (res == VLC_THREAD_CANCELED)
+        res = NULL;
+    return res;
+}
+
+
 struct vlc_http_mgr
 {
     vlc_object_t *obj;
diff --git a/modules/access/http/transport.c b/modules/access/http/transport.c
index 0a9a738..38f9309 100644
--- a/modules/access/http/transport.c
+++ b/modules/access/http/transport.c
@@ -96,25 +96,40 @@ static int vlc_tcp_connect(vlc_object_t *obj, const char *name, unsigned port)
 
     vlc_cleanup_pop();
     freeaddrinfo(res);
+
+#ifndef _WIN32
+    fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
+#else
+    ioctlsocket(fd, FIONBIO, &(unsigned long){ 1 });
+#endif
     return fd;
 }
 
+vlc_tls_t *vlc_http_connect(vlc_object_t *obj, const char *name, unsigned port)
+{
+    if (port == 0)
+        port = 80;
+
+    int fd = vlc_tcp_connect(obj, name, port);
+    if (fd == -1)
+        return NULL;
+
+    vlc_tls_t *tls = vlc_tls_DummyCreate(obj, fd);
+    if (tls == NULL)
+        net_Close(fd);
+    return tls;
+}
+
 vlc_tls_t *vlc_https_connect(vlc_tls_creds_t *creds, const char *name,
                              unsigned port, bool *restrict two)
 {
     if (port == 0)
         port = 443;
 
-    int fd = vlc_tcp_connect(VLC_OBJECT(creds), name, port);
+    int fd = vlc_tcp_connect(creds->p_parent, name, port);
     if (fd == -1)
         return NULL;
 
-#ifndef _WIN32
-    fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
-#else
-    ioctlsocket(fd, FIONBIO, &(unsigned long){ 1 });
-#endif
-
     /* TLS with ALPN */
     const char *alpn[] = { "h2", "http/1.1", NULL };
     char *alp;
diff --git a/modules/access/http/transport.h b/modules/access/http/transport.h
index bb6aa584..00c23a7 100644
--- a/modules/access/http/transport.h
+++ b/modules/access/http/transport.h
@@ -24,11 +24,14 @@
 #include <stddef.h>
 #include <stdbool.h>
 
+struct vlc_object_t;
 struct vlc_tls;
 struct vlc_tls_creds;
 
 struct vlc_tls *vlc_https_connect(struct vlc_tls_creds *creds,
                                   const char *name, unsigned port,
                                   bool *restrict two);
+struct vlc_tls *vlc_http_connect(struct vlc_object_t *obj,
+                                 const char *name, unsigned port);
 
 #endif



More information about the vlc-commits mailing list