summaryrefslogtreecommitdiff
path: root/src/tls_wrap.cc
diff options
context:
space:
mode:
authorFedor Indutny <fedor@indutny.com>2014-09-24 13:42:33 +0400
committerFedor Indutny <fedor@indutny.com>2014-09-26 08:21:36 +0400
commit2122a77f5177a039b80403a3772fdd14323e158a (patch)
treed996eb307c76ffa03c938376e26d40ed5282f5ba /src/tls_wrap.cc
parent9d957747222da95e7c55142d25f59466c07857dc (diff)
downloadnode-new-2122a77f5177a039b80403a3772fdd14323e158a.tar.gz
crypto: lower RSS usage for TLSCallbacks
Don't allocate any BIO buffers initially, do this on a first read from the TCP connection. Allocate different amount of data for initial read and for consequent reads: small buffer for hello+certificate, big buffer for better throughput. see #8416
Diffstat (limited to 'src/tls_wrap.cc')
-rw-r--r--src/tls_wrap.cc9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc
index c65492cf31..84bc87e0cc 100644
--- a/src/tls_wrap.cc
+++ b/src/tls_wrap.cc
@@ -192,6 +192,8 @@ void TLSCallbacks::InitSSL() {
if (is_server()) {
SSL_set_accept_state(ssl_);
} else if (is_client()) {
+ // Enough space for server response (hello, cert)
+ NodeBIO::FromBIO(enc_in_)->set_initial(kInitialClientBufferLength);
SSL_set_connect_state(ssl_);
} else {
// Unexpected
@@ -254,6 +256,7 @@ void TLSCallbacks::Receive(const FunctionCallbackInfo<Value>& args) {
wrap->DoAlloc(reinterpret_cast<uv_handle_t*>(stream), len, &buf);
size_t copy = buf.len > len ? len : buf.len;
memcpy(buf.base, data, copy);
+ buf.len = copy;
wrap->DoRead(stream, buf.len, &buf, UV_UNKNOWN_HANDLE);
data += copy;
@@ -615,8 +618,9 @@ void TLSCallbacks::AfterWrite(WriteWrap* w) {
void TLSCallbacks::DoAlloc(uv_handle_t* handle,
size_t suggested_size,
uv_buf_t* buf) {
- buf->base = NodeBIO::FromBIO(enc_in_)->PeekWritable(&suggested_size);
- buf->len = suggested_size;
+ size_t size = 0;
+ buf->base = NodeBIO::FromBIO(enc_in_)->PeekWritable(&size);
+ buf->len = size;
}
@@ -720,6 +724,7 @@ void TLSCallbacks::EnableHelloParser(const FunctionCallbackInfo<Value>& args) {
TLSCallbacks* wrap = Unwrap<TLSCallbacks>(args.Holder());
+ NodeBIO::FromBIO(wrap->enc_in_)->set_initial(kMaxHelloLength);
wrap->hello_parser_.Start(SSLWrap<TLSCallbacks>::OnClientHello,
OnClientHelloParseEnd,
wrap);