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

tls: rename dummy socket functions

parent 79f332e2
...@@ -194,14 +194,16 @@ static inline int vlc_tls_SessionHandshake (vlc_tls_creds_t *crd, ...@@ -194,14 +194,16 @@ static inline int vlc_tls_SessionHandshake (vlc_tls_creds_t *crd,
VLC_API void vlc_tls_Delete (vlc_tls_creds_t *); VLC_API void vlc_tls_Delete (vlc_tls_creds_t *);
/** /**
* Fakes a TLS session. * Creates a transport-layer stream from a socket.
* *
* Creates a dummy TLS session structure from a socket file descriptor. Data * Creates a transport-layer I/O stream from a socket file descriptor.
* will be sent and received directly through the socket. This can be used * Data will be sent and received directly through the socket. This can be used
* either to share common code between non-TLS and TLS cases, or for testing * either to share common code between non-TLS and TLS cases, or for testing
* purposes. * purposes.
*
* This function is not a cancellation point.
*/ */
VLC_API vlc_tls_t *vlc_tls_DummyCreate(vlc_object_t *obj, int fd); VLC_API vlc_tls_t *vlc_tls_SocketOpen(vlc_object_t *obj, int fd);
/** @} */ /** @} */
......
...@@ -47,7 +47,7 @@ static void conn_create(void) ...@@ -47,7 +47,7 @@ static void conn_create(void)
if (vlc_socketpair(PF_LOCAL, SOCK_STREAM, 0, fds, false)) if (vlc_socketpair(PF_LOCAL, SOCK_STREAM, 0, fds, false))
assert(!"socketpair"); assert(!"socketpair");
struct vlc_tls *tls = vlc_tls_DummyCreate(NULL, fds[1]); struct vlc_tls *tls = vlc_tls_SocketOpen(NULL, fds[1]);
assert(tls != NULL); assert(tls != NULL);
external_fd = fds[0]; external_fd = fds[0];
......
...@@ -93,7 +93,7 @@ static void conn_create(void) ...@@ -93,7 +93,7 @@ static void conn_create(void)
if (vlc_socketpair(PF_LOCAL, SOCK_STREAM, 0, fds, false)) if (vlc_socketpair(PF_LOCAL, SOCK_STREAM, 0, fds, false))
assert(!"socketpair"); assert(!"socketpair");
struct vlc_tls *tls = vlc_tls_DummyCreate(NULL, fds[1]); struct vlc_tls *tls = vlc_tls_SocketOpen(NULL, fds[1]);
assert(tls != NULL); assert(tls != NULL);
external_fd = fds[0]; external_fd = fds[0];
......
...@@ -115,7 +115,7 @@ vlc_tls_t *vlc_http_connect(vlc_object_t *obj, const char *name, unsigned port) ...@@ -115,7 +115,7 @@ vlc_tls_t *vlc_http_connect(vlc_object_t *obj, const char *name, unsigned port)
if (fd == -1) if (fd == -1)
return NULL; return NULL;
vlc_tls_t *tls = vlc_tls_DummyCreate(obj, fd); vlc_tls_t *tls = vlc_tls_SocketOpen(obj, fd);
if (tls == NULL) if (tls == NULL)
net_Close(fd); net_Close(fd);
return tls; return tls;
......
...@@ -436,7 +436,7 @@ vlc_tls_SessionDelete ...@@ -436,7 +436,7 @@ vlc_tls_SessionDelete
vlc_tls_Read vlc_tls_Read
vlc_tls_Write vlc_tls_Write
vlc_tls_GetLine vlc_tls_GetLine
vlc_tls_DummyCreate vlc_tls_SocketOpen
ToCharset ToCharset
update_Check update_Check
update_Delete update_Delete
......
...@@ -317,13 +317,13 @@ error: ...@@ -317,13 +317,13 @@ error:
return NULL; return NULL;
} }
static int vlc_tls_DummyGetFD(vlc_tls_t *tls) static int vlc_tls_SocketGetFD(vlc_tls_t *tls)
{ {
return (intptr_t)tls->sys; return (intptr_t)tls->sys;
} }
static ssize_t vlc_tls_DummyReceive(vlc_tls_t *tls, struct iovec *iov, static ssize_t vlc_tls_SocketRead(vlc_tls_t *tls, struct iovec *iov,
unsigned count) unsigned count)
{ {
int fd = (intptr_t)tls->sys; int fd = (intptr_t)tls->sys;
struct msghdr msg = struct msghdr msg =
...@@ -334,8 +334,8 @@ static ssize_t vlc_tls_DummyReceive(vlc_tls_t *tls, struct iovec *iov, ...@@ -334,8 +334,8 @@ static ssize_t vlc_tls_DummyReceive(vlc_tls_t *tls, struct iovec *iov,
return recvmsg(fd, &msg, 0); return recvmsg(fd, &msg, 0);
} }
static ssize_t vlc_tls_DummySend(vlc_tls_t *tls, const struct iovec *iov, static ssize_t vlc_tls_SocketWrite(vlc_tls_t *tls, const struct iovec *iov,
unsigned count) unsigned count)
{ {
int fd = (intptr_t)tls->sys; int fd = (intptr_t)tls->sys;
const struct msghdr msg = const struct msghdr msg =
...@@ -346,18 +346,24 @@ static ssize_t vlc_tls_DummySend(vlc_tls_t *tls, const struct iovec *iov, ...@@ -346,18 +346,24 @@ static ssize_t vlc_tls_DummySend(vlc_tls_t *tls, const struct iovec *iov,
return sendmsg(fd, &msg, MSG_NOSIGNAL); return sendmsg(fd, &msg, MSG_NOSIGNAL);
} }
static int vlc_tls_DummyShutdown(vlc_tls_t *tls, bool duplex) static int vlc_tls_SocketShutdown(vlc_tls_t *tls, bool duplex)
{ {
int fd = (intptr_t)tls->sys; int fd = (intptr_t)tls->sys;
return shutdown(fd, duplex ? SHUT_RDWR : SHUT_WR); return shutdown(fd, duplex ? SHUT_RDWR : SHUT_WR);
} }
static void vlc_tls_DummyClose(vlc_tls_t *tls) static void vlc_tls_SocketClose(vlc_tls_t *tls)
{ {
#if 0
int fd = (intptr_t)tls->sys;
net_Close(fd);
#else
(void) tls; (void) tls;
#endif
} }
vlc_tls_t *vlc_tls_DummyCreate(vlc_object_t *obj, int fd) vlc_tls_t *vlc_tls_SocketOpen(vlc_object_t *obj, int fd)
{ {
vlc_tls_t *session = malloc(sizeof (*session)); vlc_tls_t *session = malloc(sizeof (*session));
if (unlikely(session == NULL)) if (unlikely(session == NULL))
...@@ -365,10 +371,10 @@ vlc_tls_t *vlc_tls_DummyCreate(vlc_object_t *obj, int fd) ...@@ -365,10 +371,10 @@ vlc_tls_t *vlc_tls_DummyCreate(vlc_object_t *obj, int fd)
session->obj = obj; session->obj = obj;
session->sys = (void *)(intptr_t)fd; session->sys = (void *)(intptr_t)fd;
session->get_fd = vlc_tls_DummyGetFD; session->get_fd = vlc_tls_SocketGetFD;
session->readv = vlc_tls_DummyReceive; session->readv = vlc_tls_SocketRead;
session->writev = vlc_tls_DummySend; session->writev = vlc_tls_SocketWrite;
session->shutdown = vlc_tls_DummyShutdown; session->shutdown = vlc_tls_SocketShutdown;
session->close = vlc_tls_DummyClose; session->close = vlc_tls_SocketClose;
return session; return session;
} }
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