@@ -35,14 +35,16 @@ namespace node {
3535using crypto::SecureContext;
3636using crypto::SSLWrap;
3737using v8::Context;
38+ using v8::DontDelete;
3839using v8::EscapableHandleScope;
3940using v8::Exception;
4041using v8::Function;
4142using v8::FunctionCallbackInfo;
4243using v8::FunctionTemplate;
43- using v8::Integer;
4444using v8::Local;
4545using v8::Object;
46+ using v8::ReadOnly;
47+ using v8::Signature;
4648using v8::String;
4749using v8::Value;
4850
@@ -307,7 +309,6 @@ void TLSWrap::EncOut() {
307309
308310 // No data to write
309311 if (BIO_pending (enc_out_) == 0 ) {
310- UpdateWriteQueueSize ();
311312 if (clear_in_->Length () == 0 )
312313 InvokeQueued (0 );
313314 return ;
@@ -553,17 +554,6 @@ bool TLSWrap::IsClosing() {
553554}
554555
555556
556- uint32_t TLSWrap::UpdateWriteQueueSize (uint32_t write_queue_size) {
557- HandleScope scope (env ()->isolate ());
558- if (write_queue_size == 0 )
559- write_queue_size = BIO_pending (enc_out_);
560- object ()->Set (env ()->context (),
561- env ()->write_queue_size_string (),
562- Integer::NewFromUnsigned (env ()->isolate (),
563- write_queue_size)).FromJust ();
564- return write_queue_size;
565- }
566-
567557
568558int TLSWrap::ReadStart () {
569559 if (stream_ != nullptr )
@@ -610,9 +600,6 @@ int TLSWrap::DoWrite(WriteWrap* w,
610600 // However, if there is any data that should be written to the socket,
611601 // the callback should not be invoked immediately
612602 if (BIO_pending (enc_out_) == 0 ) {
613- // net.js expects writeQueueSize to be > 0 if the write isn't
614- // immediately flushed
615- UpdateWriteQueueSize (1 );
616603 return stream_->DoWrite (w, bufs, count, send_handle);
617604 }
618605 }
@@ -665,7 +652,6 @@ int TLSWrap::DoWrite(WriteWrap* w,
665652
666653 // Try writing data immediately
667654 EncOut ();
668- UpdateWriteQueueSize ();
669655
670656 return 0 ;
671657}
@@ -937,12 +923,17 @@ int TLSWrap::SelectSNIContextCallback(SSL* s, int* ad, void* arg) {
937923#endif // SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
938924
939925
940- void TLSWrap::UpdateWriteQueueSize (const FunctionCallbackInfo<Value>& args ) {
926+ void TLSWrap::GetWriteQueueSize (const FunctionCallbackInfo<Value>& info ) {
941927 TLSWrap* wrap;
942- ASSIGN_OR_RETURN_UNWRAP (&wrap, args. Holder ());
928+ ASSIGN_OR_RETURN_UNWRAP (&wrap, info. This ());
943929
944- uint32_t write_queue_size = wrap->UpdateWriteQueueSize ();
945- args.GetReturnValue ().Set (write_queue_size);
930+ if (wrap->clear_in_ == nullptr ) {
931+ info.GetReturnValue ().Set (0 );
932+ return ;
933+ }
934+
935+ uint32_t write_queue_size = BIO_pending (wrap->enc_out_ );
936+ info.GetReturnValue ().Set (write_queue_size);
946937}
947938
948939
@@ -965,14 +956,24 @@ void TLSWrap::Initialize(Local<Object> target,
965956 t->InstanceTemplate ()->SetInternalFieldCount (1 );
966957 t->SetClassName (tlsWrapString);
967958
959+ Local<FunctionTemplate> get_write_queue_size =
960+ FunctionTemplate::New (env->isolate (),
961+ GetWriteQueueSize,
962+ env->as_external (),
963+ Signature::New (env->isolate (), t));
964+ t->PrototypeTemplate ()->SetAccessorProperty (
965+ env->write_queue_size_string (),
966+ get_write_queue_size,
967+ Local<FunctionTemplate>(),
968+ static_cast <PropertyAttribute>(ReadOnly | DontDelete));
969+
968970 AsyncWrap::AddWrapMethods (env, t, AsyncWrap::kFlagHasReset );
969971 env->SetProtoMethod (t, " receive" , Receive);
970972 env->SetProtoMethod (t, " start" , Start);
971973 env->SetProtoMethod (t, " setVerifyMode" , SetVerifyMode);
972974 env->SetProtoMethod (t, " enableSessionCallbacks" , EnableSessionCallbacks);
973975 env->SetProtoMethod (t, " destroySSL" , DestroySSL);
974976 env->SetProtoMethod (t, " enableCertCb" , EnableCertCb);
975- env->SetProtoMethod (t, " updateWriteQueueSize" , UpdateWriteQueueSize);
976977
977978 StreamBase::AddMethods<TLSWrap>(env, t, StreamBase::kFlagHasWritev );
978979 SSLWrap<TLSWrap>::AddMethods (env, t);
0 commit comments