Commit 32f589f2 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

tls: add a function for TCP Fast Open

parent e877f5a6
......@@ -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.
......
......@@ -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
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment