diff options
author | Anatoli Papirovski <apapirovski@mac.com> | 2017-12-11 17:55:17 -0500 |
---|---|---|
committer | Anatoli Papirovski <apapirovski@mac.com> | 2017-12-18 09:58:02 -0500 |
commit | d36e1b4fed57b34d93e70d3408d753e00b8ed754 (patch) | |
tree | 03e0a12b194453231ad7391ff16b2c7cf3a489f2 /src/tls_wrap.cc | |
parent | 68c63a9fa362138bed852714862ac37b85c06adb (diff) | |
download | android-node-v8-d36e1b4fed57b34d93e70d3408d753e00b8ed754.tar.gz android-node-v8-d36e1b4fed57b34d93e70d3408d753e00b8ed754.tar.bz2 android-node-v8-d36e1b4fed57b34d93e70d3408d753e00b8ed754.zip |
net,src: refactor writeQueueSize tracking
Currently, writeQueueSize is never used in C++ and barely used
within JS. Instead of constantly updating the value on the JS
object, create a getter that will retrieve the most up-to-date
value from C++.
For the vast majority of cases though, create a new prop on
Socket.prototype[kLastWriteQueueSize] using a Symbol. Use this
to track the current write size, entirely in JS land.
PR-URL: https://github.com/nodejs/node/pull/17650
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'src/tls_wrap.cc')
-rw-r--r-- | src/tls_wrap.cc | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc index c661a0ac32..b2ef5184e0 100644 --- a/src/tls_wrap.cc +++ b/src/tls_wrap.cc @@ -35,14 +35,16 @@ namespace node { using crypto::SecureContext; using crypto::SSLWrap; using v8::Context; +using v8::DontDelete; using v8::EscapableHandleScope; using v8::Exception; using v8::Function; using v8::FunctionCallbackInfo; using v8::FunctionTemplate; -using v8::Integer; using v8::Local; using v8::Object; +using v8::ReadOnly; +using v8::Signature; using v8::String; using v8::Value; @@ -309,7 +311,6 @@ void TLSWrap::EncOut() { // No data to write if (BIO_pending(enc_out_) == 0) { - UpdateWriteQueueSize(); if (clear_in_->Length() == 0) InvokeQueued(0); return; @@ -555,17 +556,6 @@ 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() { if (stream_ != nullptr) @@ -612,9 +602,6 @@ int TLSWrap::DoWrite(WriteWrap* w, // 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) { - // net.js expects writeQueueSize to be > 0 if the write isn't - // immediately flushed - UpdateWriteQueueSize(1); return stream_->DoWrite(w, bufs, count, send_handle); } } @@ -666,7 +653,6 @@ int TLSWrap::DoWrite(WriteWrap* w, // Try writing data immediately EncOut(); - UpdateWriteQueueSize(); return 0; } @@ -938,12 +924,17 @@ int TLSWrap::SelectSNIContextCallback(SSL* s, int* ad, void* arg) { #endif // SSL_CTRL_SET_TLSEXT_SERVERNAME_CB -void TLSWrap::UpdateWriteQueueSize(const FunctionCallbackInfo<Value>& args) { +void TLSWrap::GetWriteQueueSize(const FunctionCallbackInfo<Value>& info) { TLSWrap* wrap; - ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); + ASSIGN_OR_RETURN_UNWRAP(&wrap, info.This()); - uint32_t write_queue_size = wrap->UpdateWriteQueueSize(); - args.GetReturnValue().Set(write_queue_size); + if (wrap->clear_in_ == nullptr) { + info.GetReturnValue().Set(0); + return; + } + + uint32_t write_queue_size = BIO_pending(wrap->enc_out_); + info.GetReturnValue().Set(write_queue_size); } @@ -966,6 +957,17 @@ void TLSWrap::Initialize(Local<Object> target, t->InstanceTemplate()->SetInternalFieldCount(1); t->SetClassName(tlsWrapString); + Local<FunctionTemplate> get_write_queue_size = + FunctionTemplate::New(env->isolate(), + GetWriteQueueSize, + env->as_external(), + Signature::New(env->isolate(), t)); + t->PrototypeTemplate()->SetAccessorProperty( + env->write_queue_size_string(), + get_write_queue_size, + Local<FunctionTemplate>(), + static_cast<PropertyAttribute>(ReadOnly | DontDelete)); + AsyncWrap::AddWrapMethods(env, t, AsyncWrap::kFlagHasReset); env->SetProtoMethod(t, "receive", Receive); env->SetProtoMethod(t, "start", Start); @@ -973,7 +975,6 @@ void TLSWrap::Initialize(Local<Object> target, env->SetProtoMethod(t, "enableSessionCallbacks", EnableSessionCallbacks); env->SetProtoMethod(t, "destroySSL", DestroySSL); env->SetProtoMethod(t, "enableCertCb", EnableCertCb); - env->SetProtoMethod(t, "updateWriteQueueSize", UpdateWriteQueueSize); StreamBase::AddMethods<TLSWrap>(env, t, StreamBase::kFlagHasWritev); SSLWrap<TLSWrap>::AddMethods(env, t); |