[vlc-commits] tls: allow overriding the poll event mask
Rémi Denis-Courmont
git at videolan.org
Sun Nov 18 16:57:08 CET 2018
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Nov 17 21:34:47 2018 +0200| [c070f110f737300baa81ff309af0fbcfd340c366] | committer: Rémi Denis-Courmont
tls: allow overriding the poll event mask
This introduces the vlc_tls_GetPollFD() helper, which returns the
transport stream's underlying file descriptor and (potentially)
overrides the event mask.
This will be necessary to support TLS 0-RTT data payload, whereby the
first data send will actually perform the three-way TLS handshake.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c070f110f737300baa81ff309af0fbcfd340c366
---
include/vlc_tls.h | 11 +++++++++--
modules/access/http/chunked_test.c | 3 ++-
modules/access/http/h2output_test.c | 3 ++-
modules/access/http/tunnel.c | 4 ++--
modules/misc/gnutls.c | 4 ++--
modules/misc/securetransport.c | 4 ++--
src/network/stream.c | 19 +++++++++++++------
7 files changed, 32 insertions(+), 16 deletions(-)
diff --git a/include/vlc_tls.h b/include/vlc_tls.h
index 5243412b1e..3f5848e77d 100644
--- a/include/vlc_tls.h
+++ b/include/vlc_tls.h
@@ -48,7 +48,7 @@ typedef struct vlc_tls
struct vlc_tls_operations
{
- int (*get_fd)(struct vlc_tls *);
+ int (*get_fd)(struct vlc_tls *, short *events);
ssize_t (*readv)(struct vlc_tls *, struct iovec *, unsigned);
ssize_t (*writev)(struct vlc_tls *, const struct iovec *, unsigned);
int (*shutdown)(struct vlc_tls *, bool duplex);
@@ -188,9 +188,16 @@ VLC_API vlc_tls_t *vlc_tls_ServerSessionCreate(vlc_tls_creds_t *creds,
*/
VLC_API void vlc_tls_SessionDelete (vlc_tls_t *);
+static inline int vlc_tls_GetPollFD(vlc_tls_t *tls, short *events)
+{
+ return tls->ops->get_fd(tls, events);
+}
+
static inline int vlc_tls_GetFD(vlc_tls_t *tls)
{
- return tls->ops->get_fd(tls);
+ short events = 0;
+
+ return vlc_tls_GetPollFD(tls, &events);
}
/**
diff --git a/modules/access/http/chunked_test.c b/modules/access/http/chunked_test.c
index 6740d84094..d6d5c374d0 100644
--- a/modules/access/http/chunked_test.c
+++ b/modules/access/http/chunked_test.c
@@ -39,9 +39,10 @@ static const char *stream_content;
static size_t stream_length;
static bool stream_bad;
-static int fd_callback(struct vlc_tls *tls)
+static int fd_callback(struct vlc_tls *tls, short *restrict events)
{
(void) tls;
+ (void) events;
return -1;
}
diff --git a/modules/access/http/h2output_test.c b/modules/access/http/h2output_test.c
index 3530f5969f..6d61ac9a6c 100644
--- a/modules/access/http/h2output_test.c
+++ b/modules/access/http/h2output_test.c
@@ -41,9 +41,10 @@ static bool send_failure = false;
static bool expect_hello = true;
static vlc_sem_t rx;
-static int fd_callback(vlc_tls_t *tls)
+static int fd_callback(vlc_tls_t *tls, short *restrict events)
{
(void) tls;
+ (void) events;
return fileno(stderr); /* should be writable (at least most of the time) */
}
diff --git a/modules/access/http/tunnel.c b/modules/access/http/tunnel.c
index 6ad53a0e25..570b6a9dca 100644
--- a/modules/access/http/tunnel.c
+++ b/modules/access/http/tunnel.c
@@ -94,11 +94,11 @@ typedef struct vlc_tls_proxy
vlc_tls_t *sock;
} vlc_tls_proxy_t;
-static int vlc_tls_ProxyGetFD(vlc_tls_t *tls)
+static int vlc_tls_ProxyGetFD(vlc_tls_t *tls, short *restrict events)
{
vlc_tls_proxy_t *proxy = (vlc_tls_proxy_t *)tls;
- return vlc_tls_GetFD(proxy->sock);
+ return vlc_tls_GetPollFD(proxy->sock, events);
}
static ssize_t vlc_tls_ProxyRead(vlc_tls_t *tls, struct iovec *iov,
diff --git a/modules/misc/gnutls.c b/modules/misc/gnutls.c
index 56541af94b..87bd5c049b 100644
--- a/modules/misc/gnutls.c
+++ b/modules/misc/gnutls.c
@@ -133,12 +133,12 @@ static ssize_t vlc_gnutls_writev(gnutls_transport_ptr_t ptr,
return sock->ops->writev(sock, iov, iovcnt);
}
-static int gnutls_GetFD(vlc_tls_t *tls)
+static int gnutls_GetFD(vlc_tls_t *tls, short *restrict events)
{
vlc_tls_gnutls_t *priv = (vlc_tls_gnutls_t *)tls;
vlc_tls_t *sock = gnutls_transport_get_ptr(priv->session);
- return vlc_tls_GetFD(sock);
+ return vlc_tls_GetPollFD(sock, events);
}
static ssize_t gnutls_Recv(vlc_tls_t *tls, struct iovec *iov, unsigned count)
diff --git a/modules/misc/securetransport.c b/modules/misc/securetransport.c
index 68d91eeb81..18ae16eeab 100644
--- a/modules/misc/securetransport.c
+++ b/modules/misc/securetransport.c
@@ -507,12 +507,12 @@ static int st_Handshake (vlc_tls_creds_t *crd, vlc_tls_t *session,
}
}
-static int st_GetFD (vlc_tls_t *session)
+static int st_GetFD (vlc_tls_t *session, short *restrict events)
{
vlc_tls_st_t *sys = (vlc_tls_st_t *)session;
vlc_tls_t *sock = sys->sock;
- return vlc_tls_GetFD(sock);
+ return vlc_tls_GetPollFD(sock, events);
}
/**
diff --git a/src/network/stream.c b/src/network/stream.c
index 7d53a6266e..33d27d06aa 100644
--- a/src/network/stream.c
+++ b/src/network/stream.c
@@ -170,45 +170,52 @@ typedef struct vlc_tls_socket
struct sockaddr peer[];
} vlc_tls_socket_t;
-static int vlc_tls_SocketGetFD(vlc_tls_t *tls)
+static int vlc_tls_SocketGetFD(vlc_tls_t *tls, short *restrict events)
{
vlc_tls_socket_t *sock = (struct vlc_tls_socket *)tls;
+ (void) events;
return sock->fd;
}
static ssize_t vlc_tls_SocketRead(vlc_tls_t *tls, struct iovec *iov,
unsigned count)
{
+ vlc_tls_socket_t *sock = (struct vlc_tls_socket *)tls;
struct msghdr msg =
{
.msg_iov = iov,
.msg_iovlen = count,
};
- return recvmsg(vlc_tls_SocketGetFD(tls), &msg, 0);
+ return recvmsg(sock->fd, &msg, 0);
}
static ssize_t vlc_tls_SocketWrite(vlc_tls_t *tls, const struct iovec *iov,
unsigned count)
{
+ vlc_tls_socket_t *sock = (struct vlc_tls_socket *)tls;
const struct msghdr msg =
{
.msg_iov = (struct iovec *)iov,
.msg_iovlen = count,
};
- return sendmsg(vlc_tls_SocketGetFD(tls), &msg, MSG_NOSIGNAL);
+ return sendmsg(sock->fd, &msg, MSG_NOSIGNAL);
}
static int vlc_tls_SocketShutdown(vlc_tls_t *tls, bool duplex)
{
- return shutdown(vlc_tls_SocketGetFD(tls), duplex ? SHUT_RDWR : SHUT_WR);
+ vlc_tls_socket_t *sock = (struct vlc_tls_socket *)tls;
+
+ return shutdown(sock->fd, duplex ? SHUT_RDWR : SHUT_WR);
}
static void vlc_tls_SocketClose(vlc_tls_t *tls)
{
- net_Close(vlc_tls_SocketGetFD(tls));
+ vlc_tls_socket_t *sock = (struct vlc_tls_socket *)tls;
+
+ net_Close(sock->fd);
free(tls);
}
@@ -365,7 +372,7 @@ static ssize_t vlc_tls_ConnectWrite(vlc_tls_t *tls,
};
ssize_t ret;
- ret = sendmsg(vlc_tls_SocketGetFD(tls), &msg, MSG_NOSIGNAL|MSG_FASTOPEN);
+ ret = sendmsg(sock->fd, &msg, MSG_NOSIGNAL|MSG_FASTOPEN);
if (ret >= 0)
{ /* Fast open in progress */
return ret;
More information about the vlc-commits
mailing list