Re: Access SSL connection in multiple threads
Hi Flo, On Sep 28, 2011, at 5:37 PM, Flo Wohlfart wrote: > Is it safe to call SSL_write() in thread B, while thread A is blocking > at DTLSv1_listen() for the same SSL connection? > > Here comes an example for better understanding: > > THREAD A: > ... > while (DTLSv1_listen(ssl, &client_addr) <= 0); > pthread_mutex_lock(&mutex); > /* handle connection */ > pthread_mutex_unlock(&mutex); > ... > > THREAD B: > ... > pthread_mutex_lock(&mutex); > SSL_write(ssl, buffer, len); > pthread_mutex_unlock(&mutex); > ... This will not work, because the SSL object used for DTLSv1_listen() is not connected to any client. There is nothing SSL_write() could send to. DTLSv1_listen() will hold the SSL object until it is connected. Then you can use it with as many threads as you like, as long as you handle locking issues. Best regards Robin __ OpenSSL Project http://www.openssl.org User Support Mailing Listopenssl-users@openssl.org Automated List Manager majord...@openssl.org
Access SSL connection in multiple threads
Hi, I am writing an application, which uses DTLS over UDP. As I read in the OpenSSL-dev mailinglist (http://www.mail-archive.com/openssl-dev@openssl.org/msg28844.html) threads are recommended when handling multiple DTLS connections. In my case, however, when using threads, an SSL connection has to be accessed by multiple threads. So I am thinking about introducing a mutex for each SSL connection to prevent concurrent access by multiple threads. Is it safe to call SSL_write() in thread B, while thread A is blocking at DTLSv1_listen() for the same SSL connection? Here comes an example for better understanding: THREAD A: ... while (DTLSv1_listen(ssl, &client_addr) <= 0); pthread_mutex_lock(&mutex); /* handle connection */ pthread_mutex_unlock(&mutex); ... THREAD B: ... pthread_mutex_lock(&mutex); SSL_write(ssl, buffer, len); pthread_mutex_unlock(&mutex); ... I am using OpenSSL 1.0.0d on Linux, patched with the DTLS bugfixes from http://sctp.fh-muenster.de/dtls-patches.html __ OpenSSL Project http://www.openssl.org User Support Mailing Listopenssl-users@openssl.org Automated List Manager majord...@openssl.org