summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnatoli Papirovski <apapirovski@mac.com>2017-10-05 16:16:20 -0400
committerAnatoli Papirovski <apapirovski@mac.com>2017-10-21 09:48:36 -0400
commitaaf2a1c2264fffd6eea82fe3778f41ac046e6349 (patch)
tree0174f50a01102dfc140cd27bf8b32f3ae93efa7a /src
parentfe13e0077f5923e327465c9cd00d344cefee800f (diff)
downloadandroid-node-v8-aaf2a1c2264fffd6eea82fe3778f41ac046e6349.tar.gz
android-node-v8-aaf2a1c2264fffd6eea82fe3778f41ac046e6349.tar.bz2
android-node-v8-aaf2a1c2264fffd6eea82fe3778f41ac046e6349.zip
tls: properly track writeQueueSize during writes
Make writeQueueSize represent the actual size of the write queue within the TLS socket. Add tls test to confirm that bufferSize works as expected. PR-URL: https://github.com/nodejs/node/pull/15791 Fixes: https://github.com/nodejs/node/issues/15005 Refs: https://github.com/nodejs/node/pull/15006 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/tls_wrap.cc24
-rw-r--r--src/tls_wrap.h1
2 files changed, 23 insertions, 2 deletions
diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc
index 738bd04071..0da332f16e 100644
--- a/src/tls_wrap.cc
+++ b/src/tls_wrap.cc
@@ -42,6 +42,7 @@ using v8::Exception;
using v8::Function;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
+using v8::Integer;
using v8::Local;
using v8::Object;
using v8::String;
@@ -297,6 +298,7 @@ void TLSWrap::EncOut() {
// No data to write
if (BIO_pending(enc_out_) == 0) {
+ UpdateWriteQueueSize();
if (clear_in_->Length() == 0)
InvokeQueued(0);
return;
@@ -551,6 +553,18 @@ bool TLSWrap::IsClosing() {
}
+uint32_t TLSWrap::UpdateWriteQueueSize(uint32_t write_queue_size) {
+ HandleScope scope(env()->isolate());
+ if (write_queue_size == 0)
+ write_queue_size = BIO_pending(enc_out_);
+ object()->Set(env()->context(),
+ env()->write_queue_size_string(),
+ Integer::NewFromUnsigned(env()->isolate(),
+ write_queue_size)).FromJust();
+ return write_queue_size;
+}
+
+
int TLSWrap::ReadStart() {
return stream_->ReadStart();
}
@@ -591,8 +605,12 @@ int TLSWrap::DoWrite(WriteWrap* w,
ClearOut();
// However, if there is any data that should be written to the socket,
// the callback should not be invoked immediately
- if (BIO_pending(enc_out_) == 0)
+ if (BIO_pending(enc_out_) == 0) {
+ // net.js expects writeQueueSize to be > 0 if the write isn't
+ // immediately flushed
+ UpdateWriteQueueSize(1);
return stream_->DoWrite(w, bufs, count, send_handle);
+ }
}
// Queue callback to execute it on next tick
@@ -642,13 +660,15 @@ int TLSWrap::DoWrite(WriteWrap* w,
// Try writing data immediately
EncOut();
+ UpdateWriteQueueSize();
return 0;
}
void TLSWrap::OnAfterWriteImpl(WriteWrap* w, void* ctx) {
- // Intentionally empty
+ TLSWrap* wrap = static_cast<TLSWrap*>(ctx);
+ wrap->UpdateWriteQueueSize();
}
diff --git a/src/tls_wrap.h b/src/tls_wrap.h
index fe3abe04f5..8d75d6fcc9 100644
--- a/src/tls_wrap.h
+++ b/src/tls_wrap.h
@@ -132,6 +132,7 @@ class TLSWrap : public AsyncWrap,
AsyncWrap* GetAsyncWrap() override;
bool IsIPCPipe() override;
+ uint32_t UpdateWriteQueueSize(uint32_t write_queue_size = 0);
// Resource implementation
static void OnAfterWriteImpl(WriteWrap* w, void* ctx);