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

tls: introduce vlc_tls_SocketPair()

This creates a pair of mutually connected stream vlc_tls_t.
parent 72f0a2e6
......@@ -232,6 +232,11 @@ VLC_API void vlc_tls_Delete (vlc_tls_creds_t *);
*/
VLC_API vlc_tls_t *vlc_tls_SocketOpen(int fd);
/**
* Creates a connected pair of transport-layer sockets.
*/
VLC_API int vlc_tls_SocketPair(int family, int protocol, vlc_tls_t *[2]);
struct addrinfo;
/**
......
......@@ -445,6 +445,7 @@ vlc_tls_GetLine
vlc_tls_SocketOpen
vlc_tls_SocketOpenTCP
vlc_tls_SocketOpenTLS
vlc_tls_SocketPair
ToCharset
update_Check
update_Delete
......
......@@ -404,6 +404,32 @@ vlc_tls_t *vlc_tls_SocketOpen(int fd)
return vlc_tls_SocketAlloc(fd, NULL, 0);
}
int vlc_tls_SocketPair(int family, int protocol, vlc_tls_t *pair[2])
{
int fds[2];
if (vlc_socketpair(family, SOCK_STREAM, protocol, fds, true))
return -1;
for (size_t i = 0; i < 2; i++)
{
setsockopt(fds[i], SOL_SOCKET, SO_REUSEADDR,
&(int){ 1 }, sizeof (int));
pair[i] = vlc_tls_SocketAlloc(fds[i], NULL, 0);
if (unlikely(pair[i] == NULL))
{
net_Close(fds[i]);
if (i)
vlc_tls_SessionDelete(pair[0]);
else
net_Close(fds[1]);
return -1;
}
}
return 0;
}
/**
* Allocates an unconnected transport layer socket.
*/
......
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