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

tls: add separate callback for shutdown

parent 8bff13ad
......@@ -44,6 +44,7 @@ struct vlc_tls
ssize_t (*recv)(struct vlc_tls *, void *, size_t);
ssize_t (*send)(struct vlc_tls *, const void *, size_t);
int (*shutdown)(struct vlc_tls *, bool duplex);
void (*close)(vlc_tls_t *);
};
......@@ -88,6 +89,25 @@ VLC_API int vlc_tls_Read(vlc_tls_t *, void *buf, size_t len, bool waitall);
VLC_API char *vlc_tls_GetLine(vlc_tls_t *);
VLC_API int vlc_tls_Write(vlc_tls_t *, const void *buf, size_t len);
/**
* Terminates a TLS session.
*
* This sends the TLS session close notification to the other end, securely
* indicating that no further data will be sent. Data can still be received
* until a close notification is received from the other end.
*
* @param duplex whether to stop receiving data as well
* @retval 0 the session was terminated securely and cleanly
* (the underlying socket can be reused for other purposes)
* @return -1 the session was terminated locally, but either a notification
* could not be sent or received (the underlying socket cannot be
* reused and must be closed)
*/
static inline int vlc_tls_Shutdown(vlc_tls_t *tls, bool duplex)
{
return tls->shutdown(tls, duplex);
}
# define tls_Recv(a,b,c) vlc_tls_Read(a,b,c,false)
# define tls_Send(a,b,c) vlc_tls_Write(a,b,c)
......
......@@ -182,6 +182,14 @@ static ssize_t gnutls_Recv (vlc_tls_t *tls, void *buf, size_t length)
return (val < 0) ? gnutls_Error (tls, val) : val;
}
static int gnutls_Shutdown(vlc_tls_t *tls, bool duplex)
{
gnutls_session_t session = tls->sys;
int val = gnutls_bye(session, duplex ? GNUTLS_SHUT_RDWR : GNUTLS_SHUT_WR);
return (val < 0) ? gnutls_Error(tls, val) : 0;
}
/**
* Terminates a TLS session.
*
......@@ -192,7 +200,6 @@ static void gnutls_Close (vlc_tls_t *tls)
{
gnutls_session_t session = tls->sys;
gnutls_bye (session, GNUTLS_SHUT_RDWR);
gnutls_deinit (session);
}
......@@ -264,6 +271,7 @@ static int gnutls_SessionOpen(vlc_tls_creds_t *creds, vlc_tls_t *tls, int type,
tls->sys = session;
tls->send = gnutls_Send;
tls->recv = gnutls_Recv;
tls->shutdown = gnutls_Shutdown;
tls->close = gnutls_Close;
return VLC_SUCCESS;
......
......@@ -322,6 +322,11 @@ static ssize_t vlc_tls_DummySend(vlc_tls_t *tls, const void *buf, size_t len)
return send(tls->fd, buf, len, MSG_NOSIGNAL);
}
static int vlc_tls_DummyShutdown(vlc_tls_t *tls, bool duplex)
{
return shutdown(tls->fd, duplex ? SHUT_RDWR : SHUT_WR);
}
static void vlc_tls_DummyClose(vlc_tls_t *tls)
{
(void) tls;
......@@ -337,6 +342,7 @@ vlc_tls_t *vlc_tls_DummyCreate(vlc_object_t *obj, int fd)
session->fd = fd;
session->recv = vlc_tls_DummyReceive;
session->send = vlc_tls_DummySend;
session->shutdown = vlc_tls_DummyShutdown;
session->close = vlc_tls_DummyClose;
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