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

tls: fix/rationalize closing the session vs closing the socket

parent 3d204990
...@@ -47,7 +47,7 @@ struct vlc_tls ...@@ -47,7 +47,7 @@ struct vlc_tls
int (*shutdown)(struct vlc_tls *, bool duplex); int (*shutdown)(struct vlc_tls *, bool duplex);
void (*close)(struct vlc_tls *); void (*close)(struct vlc_tls *);
void *p; struct vlc_tls *p;
}; };
/** /**
...@@ -162,11 +162,14 @@ static inline int vlc_tls_Shutdown(vlc_tls_t *tls, bool duplex) ...@@ -162,11 +162,14 @@ static inline int vlc_tls_Shutdown(vlc_tls_t *tls, bool duplex)
*/ */
static inline void vlc_tls_Close(vlc_tls_t *session) static inline void vlc_tls_Close(vlc_tls_t *session)
{ {
int fd = vlc_tls_GetFD(session); do
{
vlc_tls_SessionDelete(session); vlc_tls_t *p = session->p;
shutdown(fd, SHUT_RDWR);
net_Close(fd); vlc_tls_SessionDelete(session);
session = p;
}
while (session != NULL);
} }
/** TLS credentials (certificate, private and trust settings) */ /** TLS credentials (certificate, private and trust settings) */
...@@ -263,7 +266,7 @@ vlc_tls_ClientSessionCreateFD(vlc_tls_creds_t *crd, int fd, const char *host, ...@@ -263,7 +266,7 @@ vlc_tls_ClientSessionCreateFD(vlc_tls_creds_t *crd, int fd, const char *host,
vlc_tls_t *tls = vlc_tls_ClientSessionCreate(crd, sock, host, srv, lp, p); vlc_tls_t *tls = vlc_tls_ClientSessionCreate(crd, sock, host, srv, lp, p);
if (unlikely(tls == NULL)) if (unlikely(tls == NULL))
vlc_tls_SessionDelete(sock); free(sock);
else else
tls->p = sock; tls->p = sock;
return tls; return tls;
......
...@@ -155,17 +155,10 @@ static vlc_tls_t *vlc_tls_SessionCreate(vlc_tls_creds_t *crd, ...@@ -155,17 +155,10 @@ static vlc_tls_t *vlc_tls_SessionCreate(vlc_tls_creds_t *crd,
void vlc_tls_SessionDelete (vlc_tls_t *session) void vlc_tls_SessionDelete (vlc_tls_t *session)
{ {
do int canc = vlc_savecancel();
{ session->close(session);
int canc = vlc_savecancel(); vlc_restorecancel(canc);
session->close(session); free(session);
vlc_restorecancel(canc);
vlc_tls_t *sock = session->p;
free(session);
session = sock;
}
while (session != NULL);
} }
static void cleanup_tls(void *data) static void cleanup_tls(void *data)
...@@ -186,6 +179,8 @@ vlc_tls_t *vlc_tls_ClientSessionCreate(vlc_tls_creds_t *crd, vlc_tls_t *sock, ...@@ -186,6 +179,8 @@ vlc_tls_t *vlc_tls_ClientSessionCreate(vlc_tls_creds_t *crd, vlc_tls_t *sock,
if (session == NULL) if (session == NULL)
return NULL; return NULL;
session->p = sock;
int canc = vlc_savecancel(); int canc = vlc_savecancel();
mtime_t deadline = mdate (); mtime_t deadline = mdate ();
deadline += var_InheritInteger (crd, "ipv4-timeout") * 1000; deadline += var_InheritInteger (crd, "ipv4-timeout") * 1000;
...@@ -379,13 +374,9 @@ static int vlc_tls_SocketShutdown(vlc_tls_t *tls, bool duplex) ...@@ -379,13 +374,9 @@ static int vlc_tls_SocketShutdown(vlc_tls_t *tls, bool duplex)
static void vlc_tls_SocketClose(vlc_tls_t *tls) static void vlc_tls_SocketClose(vlc_tls_t *tls)
{ {
#if 0
int fd = (intptr_t)tls->sys; int fd = (intptr_t)tls->sys;
net_Close(fd); net_Close(fd);
#else
(void) tls;
#endif
} }
vlc_tls_t *vlc_tls_SocketOpen(vlc_object_t *obj, int fd) vlc_tls_t *vlc_tls_SocketOpen(vlc_object_t *obj, int fd)
......
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