[vlc-commits] tls: fix/rationalize closing the session vs closing the socket

Rémi Denis-Courmont git at videolan.org
Thu Feb 23 20:08:28 CET 2017


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Feb 23 20:54:30 2017 +0200| [7c6fe437851825dea8bef053d0b9f99dc8108ac8] | committer: Rémi Denis-Courmont

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

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=7c6fe437851825dea8bef053d0b9f99dc8108ac8
---

 include/vlc_tls.h | 17 ++++++++++-------
 src/network/tls.c | 21 ++++++---------------
 2 files changed, 16 insertions(+), 22 deletions(-)

diff --git a/include/vlc_tls.h b/include/vlc_tls.h
index 99c5b65..2e5da35 100644
--- a/include/vlc_tls.h
+++ b/include/vlc_tls.h
@@ -47,7 +47,7 @@ struct vlc_tls
     int (*shutdown)(struct vlc_tls *, bool duplex);
     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)
  */
 static inline void vlc_tls_Close(vlc_tls_t *session)
 {
-    int fd = vlc_tls_GetFD(session);
-
-    vlc_tls_SessionDelete(session);
-    shutdown(fd, SHUT_RDWR);
-    net_Close(fd);
+    do
+    {
+        vlc_tls_t *p = session->p;
+
+        vlc_tls_SessionDelete(session);
+        session = p;
+    }
+    while (session != NULL);
 }
 
 /** TLS credentials (certificate, private and trust settings) */
@@ -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);
     if (unlikely(tls == NULL))
-        vlc_tls_SessionDelete(sock);
+        free(sock);
     else
         tls->p = sock;
     return tls;
diff --git a/src/network/tls.c b/src/network/tls.c
index 0912a1e..393db5b 100644
--- a/src/network/tls.c
+++ b/src/network/tls.c
@@ -155,17 +155,10 @@ static vlc_tls_t *vlc_tls_SessionCreate(vlc_tls_creds_t *crd,
 
 void vlc_tls_SessionDelete (vlc_tls_t *session)
 {
-    do
-    {
-        int canc = vlc_savecancel();
-        session->close(session);
-        vlc_restorecancel(canc);
-
-        vlc_tls_t *sock = session->p;
-        free(session);
-        session = sock;
-    }
-    while (session != NULL);
+    int canc = vlc_savecancel();
+    session->close(session);
+    vlc_restorecancel(canc);
+    free(session);
 }
 
 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,
     if (session == NULL)
         return NULL;
 
+    session->p = sock;
+
     int canc = vlc_savecancel();
     mtime_t deadline = mdate ();
     deadline += var_InheritInteger (crd, "ipv4-timeout") * 1000;
@@ -379,13 +374,9 @@ static int vlc_tls_SocketShutdown(vlc_tls_t *tls, bool duplex)
 
 static void vlc_tls_SocketClose(vlc_tls_t *tls)
 {
-#if 0
     int fd = (intptr_t)tls->sys;
 
     net_Close(fd);
-#else
-    (void) tls;
-#endif
 }
 
 vlc_tls_t *vlc_tls_SocketOpen(vlc_object_t *obj, int fd)



More information about the vlc-commits mailing list