[vlc-commits] tls: add a function for TCP Fast Open
Rémi Denis-Courmont
git at videolan.org
Sat Mar 4 18:56:02 CET 2017
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Mar 4 16:12:08 2017 +0200| [32f589f2446049c8a361e9072e6ab6b5e2da0eb9] | committer: Rémi Denis-Courmont
tls: add a function for TCP Fast Open
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=32f589f2446049c8a361e9072e6ab6b5e2da0eb9
---
include/vlc_tls.h | 14 +++++++++++++-
src/libvlccore.sym | 1 +
src/network/tls.c | 25 +++++++++++++++----------
3 files changed, 29 insertions(+), 11 deletions(-)
diff --git a/include/vlc_tls.h b/include/vlc_tls.h
index eb554eb..0a32f26 100644
--- a/include/vlc_tls.h
+++ b/include/vlc_tls.h
@@ -288,8 +288,20 @@ struct addrinfo;
/**
* Creates a transport-layer stream from a struct addrinfo.
+ *
+ * This function tries to allocate a socket using the specified addrinfo
+ * structure. Normally, the vlc_tls_SocketOpenTCP() function takes care of
+ * this. But in some cases, it cannot be used, notably:
+ * - if the remote destination is not resolved (directly) from getaddrinfo(),
+ * - if the socket type is not SOCK_STREAM,
+ * - if the transport protocol is not TCP (IPPROTO_TCP), or
+ * - if TCP Fast Open should be attempted.
+ *
+ * @param ai a filled addrinfo structure (the ai_next member is ignored)
+ * @param defer_connect whether to attempt a TCP Fast Open connection or not
*/
-vlc_tls_t *vlc_tls_SocketOpenAddrInfo(const struct addrinfo *);
+VLC_API vlc_tls_t *vlc_tls_SocketOpenAddrInfo(const struct addrinfo *ai,
+ bool defer_connect);
/**
* Creates a transport-layer TCP stream from a name and port.
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 343638d..e6bd54b 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -443,6 +443,7 @@ vlc_tls_Read
vlc_tls_Write
vlc_tls_GetLine
vlc_tls_SocketOpen
+vlc_tls_SocketOpenAddrInfo
vlc_tls_SocketOpenTCP
vlc_tls_SocketOpenTLS
vlc_tls_SocketPair
diff --git a/src/network/tls.c b/src/network/tls.c
index 21ca2fd..d7962ad 100644
--- a/src/network/tls.c
+++ b/src/network/tls.c
@@ -537,16 +537,25 @@ static ssize_t vlc_tls_ConnectWrite(vlc_tls_t *tls,
return vlc_tls_SocketWrite(tls, iov, count);
}
-vlc_tls_t *vlc_tls_SocketOpenAddrInfo(const struct addrinfo *restrict info)
+vlc_tls_t *vlc_tls_SocketOpenAddrInfo(const struct addrinfo *restrict info,
+ bool defer_connect)
{
vlc_tls_t *sock = vlc_tls_SocketAddrInfo(info);
if (sock == NULL)
return NULL;
- if (vlc_tls_Connect(sock))
+ if (defer_connect)
+ { /* The socket is not connected yet.
+ * The connection will be triggered on the first send. */
+ sock->writev = vlc_tls_ConnectWrite;
+ }
+ else
{
- vlc_tls_SessionDelete(sock);
- sock = NULL;
+ if (vlc_tls_Connect(sock))
+ {
+ vlc_tls_SessionDelete(sock);
+ sock = NULL;
+ }
}
return sock;
}
@@ -576,7 +585,7 @@ vlc_tls_t *vlc_tls_SocketOpenTCP(vlc_object_t *obj, const char *name,
/* TODO: implement RFC6555 */
for (const struct addrinfo *p = res; p != NULL; p = p->ai_next)
{
- vlc_tls_t *tls = vlc_tls_SocketOpenAddrInfo(p);
+ vlc_tls_t *tls = vlc_tls_SocketOpenAddrInfo(p, false);
if (tls == NULL)
{
msg_Err(obj, "connection error: %s", vlc_strerror_c(errno));
@@ -613,17 +622,13 @@ vlc_tls_t *vlc_tls_SocketOpenTLS(vlc_tls_creds_t *creds, const char *name,
for (const struct addrinfo *p = res; p != NULL; p = p->ai_next)
{
- vlc_tls_t *tcp = vlc_tls_SocketAddrInfo(p);
+ vlc_tls_t *tcp = vlc_tls_SocketOpenAddrInfo(p, true);
if (tcp == NULL)
{
msg_Err(creds, "socket error: %s", vlc_strerror_c(errno));
continue;
}
- /* The socket is not connected yet.
- * The connection will be triggered on the first send. */
- tcp->writev = vlc_tls_ConnectWrite;
-
vlc_tls_t *tls = vlc_tls_ClientSessionCreate(creds, tcp, name, service,
alpn, alp);
if (tls != NULL)
More information about the vlc-commits
mailing list