From: Nikos Mavrogiannopoulos Date: Tue, 27 Jan 2015 12:06:10 +0000 (+0100) Subject: Added gnutls_record_is_async() X-Git-Tag: gnutls_3_4_0~333 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2232822aabe473d124f924d64ff52981d685fd41;p=thirdparty%2Fgnutls.git Added gnutls_record_is_async() That function indicates whether gnutls_record_recv() and gnutls_record_send() can be used independently and in parallel. --- diff --git a/lib/gnutls_record.c b/lib/gnutls_record.c index 4058fa843b..931e97fdc8 100644 --- a/lib/gnutls_record.c +++ b/lib/gnutls_record.c @@ -1512,6 +1512,29 @@ gnutls_record_discard_queued(gnutls_session_t session) return ret; } +/** + * gnutls_record_is_async: + * @session: is a #gnutls_session_t structure. + * + * This will indicate whether the DTLS session is in asynchronous mode, + * i.e., handshake data may still be received and retransmitted. During + * that time gnutls_record_send() and gnutls_record_recv() must be only be + * used in the same process or thread (see gnutls_record_send() for more information). + * + * In a TLS session this function always returns zero. + * + * Returns: Non-zero if the session is in async mode, or zero otherwise. + * + * Since: 3.4.0 + **/ +unsigned +gnutls_record_is_async(gnutls_session_t session) +{ + if (IS_DTLS(session) && _dtls_is_async(session) && _dtls_async_timer_active(session)) + return 1; + return 0; +} + /** * gnutls_record_recv_packet: * @session: is a #gnutls_session_t structure. @@ -1570,6 +1593,12 @@ gnutls_record_recv_packet(gnutls_session_t session, * mode, and will refuse to send data over the MTU size by returning * %GNUTLS_E_LARGE_PACKET. * + * This function can be used in parallel with gnutls_record_recv() in a + * multi-thread or multi-process scenario if TLS is in use, or in DTLS + * when gnutls_record_is_async() returns zero (that will happen few seconds after + * the handshake is terminated). In all cases, each process or thread must + * be restricted to use one of the send or recv functions. + * * Returns: The number of bytes sent, or a negative error code. The * number of bytes sent might be less than @data_size. The maximum * number of bytes this function can send in a single call depends diff --git a/lib/includes/gnutls/gnutls.h.in b/lib/includes/gnutls/gnutls.h.in index c8e3fc26b0..4cd8463809 100644 --- a/lib/includes/gnutls/gnutls.h.in +++ b/lib/includes/gnutls/gnutls.h.in @@ -933,6 +933,7 @@ void gnutls_record_cork(gnutls_session_t session); #define GNUTLS_RECORD_WAIT 1 int gnutls_record_uncork(gnutls_session_t session, unsigned int flags); size_t gnutls_record_discard_queued(gnutls_session_t session); +unsigned gnutls_record_is_async(gnutls_session_t session); typedef struct { size_t low; diff --git a/lib/libgnutls.map b/lib/libgnutls.map index 57da7f7329..fbf34b159d 100644 --- a/lib/libgnutls.map +++ b/lib/libgnutls.map @@ -1016,6 +1016,7 @@ GNUTLS_3_4 gnutls_pkcs11_get_raw_issuer_by_dn; gnutls_x509_trust_list_get_issuer_by_dn; gnutls_system_recv_timeout; + gnutls_record_is_async; local: *; };