[vlc-commits] http: improve tunnel coverage
Rémi Denis-Courmont
git at videolan.org
Sun Mar 20 19:54:04 CET 2016
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Mar 20 20:53:31 2016 +0200| [9fcfba7662200f69d6027fea375249578bbd0227] | committer: Rémi Denis-Courmont
http: improve tunnel coverage
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=9fcfba7662200f69d6027fea375249578bbd0227
---
modules/access/http/tunnel.c | 53 +++++++++++++++++--------------------
modules/access/http/tunnel_test.c | 4 +++
2 files changed, 28 insertions(+), 29 deletions(-)
diff --git a/modules/access/http/tunnel.c b/modules/access/http/tunnel.c
index 52bd001..eb5ef3a 100644
--- a/modules/access/http/tunnel.c
+++ b/modules/access/http/tunnel.c
@@ -115,9 +115,7 @@ static int vlc_tls_ProxyShutdown(vlc_tls_t *tls, bool duplex)
static void vlc_tls_ProxyClose(vlc_tls_t *tls)
{
- struct vlc_http_msg *msg = tls->p;
-
- vlc_http_msg_destroy(msg); /* <- sock is destroyed there too */
+ (void) tls;
}
vlc_tls_t *vlc_https_connect_proxy(vlc_tls_creds_t *creds,
@@ -160,28 +158,9 @@ vlc_tls_t *vlc_https_connect_proxy(vlc_tls_creds_t *creds,
assert(!ptwo); /* HTTP/2 proxy not supported yet */
- struct vlc_http_conn *conn = /*ptwo ? vlc_h2_conn_create(sock)
- :*/ vlc_h1_conn_create(sock, false);
- if (unlikely(conn == NULL))
- {
- vlc_tls_Close(sock);
- return NULL;
- }
-
- struct vlc_http_msg *resp = vlc_http_tunnel_open(conn, hostname, port);
-
- /* TODO: reuse connection to HTTP/2 proxy */
- vlc_http_conn_release(conn);
-
- if (resp == NULL)
- return NULL;
-
struct vlc_tls *psock = malloc(sizeof (*psock));
if (unlikely(psock == NULL))
- {
- vlc_http_msg_destroy(resp); /* <- sock is destroyed there too */
- return NULL;
- }
+ goto error;
psock->obj = VLC_OBJECT(creds);
psock->sys = sock;
@@ -190,21 +169,37 @@ vlc_tls_t *vlc_https_connect_proxy(vlc_tls_creds_t *creds,
psock->writev = vlc_tls_ProxyWrite;
psock->shutdown = vlc_tls_ProxyShutdown;
psock->close = vlc_tls_ProxyClose;
- psock->p = resp;
+ psock->p = NULL;
+
+ struct vlc_http_conn *conn = /*ptwo ? vlc_h2_conn_create(psock)
+ :*/ vlc_h1_conn_create(psock, false);
+ if (unlikely(conn == NULL))
+ {
+ vlc_tls_Close(psock);
+ goto error;
+ }
+
+ struct vlc_http_msg *resp = vlc_http_tunnel_open(conn, hostname, port);
+
+ /* TODO: reuse connection to HTTP/2 proxy */
+ vlc_http_conn_release(conn); /* psock is destroyed there too */
+
+ if (resp == NULL)
+ goto error;
vlc_tls_t *tls;
const char *alpn[] = { "h2", "http/1.1", NULL };
char *alp;
- tls = vlc_tls_ClientSessionCreate(creds, psock, hostname, "https",
+ tls = vlc_tls_ClientSessionCreate(creds, sock, hostname, "https",
alpn + !*two, &alp);
if (tls == NULL)
- {
- vlc_tls_Close(psock);
- return NULL;
- }
+ goto error;
*two = (alp != NULL) && !strcmp(alp, "h2");
free(alp);
return tls;
+error:
+ vlc_tls_Close(sock);
+ return NULL;
}
diff --git a/modules/access/http/tunnel_test.c b/modules/access/http/tunnel_test.c
index 7e59980..e68f668 100644
--- a/modules/access/http/tunnel_test.c
+++ b/modules/access/http/tunnel_test.c
@@ -81,6 +81,8 @@ static void proxy_client_process(int fd)
shutdown(fd, SHUT_WR);
}
+static unsigned connection_count = 0;
+
static void *proxy_thread(void *data)
{
int lfd = (intptr_t)data;
@@ -94,6 +96,7 @@ static void *proxy_thread(void *data)
int canc = vlc_savecancel();
proxy_client_process(cfd);
close(cfd);
+ connection_count++;
vlc_restorecancel(canc);
}
vlc_assert_unreachable();
@@ -165,6 +168,7 @@ int main(void)
vlc_cancel(th);
vlc_join(th, NULL);
+ assert(connection_count > 0);
free(url);
close(lfd);
}
More information about the vlc-commits
mailing list