Search code examples
socketssslopenssltls1.3

Can SSL_write() and SSL_read() happen at the same time?


I think in operating system, read() and write() on the same socket could be separated and happen parallel in different threads. However in OpenSSL, the SSL_write() and SSL_read() seems not separately, because they both could issue read and write operations. So, if I am using a TLS based connection with OpenSSL, do I have to create a lock so that SSL_write() and SSL_read() never happens at the same time?


Solution

  • The OpenSSL documentation says:

    However it would not be thread safe to call BIO_write() from one thread while calling BIO_read() in another where both functions are passed the same BIO object

    SSL_read and SSL_write use BIO_read() and BIO_write() internally. So the same holds for SSL_read and SSL_write: do not use them from different threads without correct locking or synchronization.