TLS layer: c->rtls to optimise recvd TLS data #2523
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The reason for this PR is to minimise the amount of data copies for the TLS case. TLDR: raw data is now received in the
c->rtls
IO buffer, and can be accessed directly.So, receive path:
stack receives new raw data -> c->rtls -> (TLS decrypt) -> c->recv
Note that the send path does not have the same. Apparently, TLS implementation can just encrypt data (
mg_tls_send()
) data on-the-fly.Right now, the builtin receive path looks like this:
This PR unifies receive path to all TLS implementations by creating
c->rtls
IO buffer for the raw, encrypted data.This change required OpenSSL implementation be changed, because OpenSSL accessed an underlying socket descriptor directly. Instead, OpenSSL must use our own low-level send/recv primitives for the low level IO - just like mbedTLS does. So, OpenSSL code was refactored: a custom BIO is created that implements the IO rather that relying on the socket. Theoretically, it makes it possible to use OpenSSL with the builtin stack - which is unlikely anyways.