@@ -35,14 +35,16 @@ namespace node {
35
35
using crypto::SecureContext;
36
36
using crypto::SSLWrap;
37
37
using v8::Context;
38
+ using v8::DontDelete;
38
39
using v8::EscapableHandleScope;
39
40
using v8::Exception;
40
41
using v8::Function;
41
42
using v8::FunctionCallbackInfo;
42
43
using v8::FunctionTemplate;
43
- using v8::Integer;
44
44
using v8::Local;
45
45
using v8::Object;
46
+ using v8::ReadOnly;
47
+ using v8::Signature;
46
48
using v8::String;
47
49
using v8::Value;
48
50
@@ -309,7 +311,6 @@ void TLSWrap::EncOut() {
309
311
310
312
// No data to write
311
313
if (BIO_pending (enc_out_) == 0 ) {
312
- UpdateWriteQueueSize ();
313
314
if (clear_in_->Length () == 0 )
314
315
InvokeQueued (0 );
315
316
return ;
@@ -555,17 +556,6 @@ bool TLSWrap::IsClosing() {
555
556
}
556
557
557
558
558
- uint32_t TLSWrap::UpdateWriteQueueSize (uint32_t write_queue_size) {
559
- HandleScope scope (env ()->isolate ());
560
- if (write_queue_size == 0 )
561
- write_queue_size = BIO_pending (enc_out_);
562
- object ()->Set (env ()->context (),
563
- env ()->write_queue_size_string (),
564
- Integer::NewFromUnsigned (env ()->isolate (),
565
- write_queue_size)).FromJust ();
566
- return write_queue_size;
567
- }
568
-
569
559
570
560
int TLSWrap::ReadStart () {
571
561
if (stream_ != nullptr )
@@ -612,9 +602,6 @@ int TLSWrap::DoWrite(WriteWrap* w,
612
602
// However, if there is any data that should be written to the socket,
613
603
// the callback should not be invoked immediately
614
604
if (BIO_pending (enc_out_) == 0 ) {
615
- // net.js expects writeQueueSize to be > 0 if the write isn't
616
- // immediately flushed
617
- UpdateWriteQueueSize (1 );
618
605
return stream_->DoWrite (w, bufs, count, send_handle);
619
606
}
620
607
}
@@ -666,7 +653,6 @@ int TLSWrap::DoWrite(WriteWrap* w,
666
653
667
654
// Try writing data immediately
668
655
EncOut ();
669
- UpdateWriteQueueSize ();
670
656
671
657
return 0 ;
672
658
}
@@ -938,12 +924,17 @@ int TLSWrap::SelectSNIContextCallback(SSL* s, int* ad, void* arg) {
938
924
#endif // SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
939
925
940
926
941
- void TLSWrap::UpdateWriteQueueSize (const FunctionCallbackInfo<Value>& args ) {
927
+ void TLSWrap::GetWriteQueueSize (const FunctionCallbackInfo<Value>& info ) {
942
928
TLSWrap* wrap;
943
- ASSIGN_OR_RETURN_UNWRAP (&wrap, args. Holder ());
929
+ ASSIGN_OR_RETURN_UNWRAP (&wrap, info. This ());
944
930
945
- uint32_t write_queue_size = wrap->UpdateWriteQueueSize ();
946
- args.GetReturnValue ().Set (write_queue_size);
931
+ if (wrap->clear_in_ == nullptr ) {
932
+ info.GetReturnValue ().Set (0 );
933
+ return ;
934
+ }
935
+
936
+ uint32_t write_queue_size = BIO_pending (wrap->enc_out_ );
937
+ info.GetReturnValue ().Set (write_queue_size);
947
938
}
948
939
949
940
@@ -966,14 +957,24 @@ void TLSWrap::Initialize(Local<Object> target,
966
957
t->InstanceTemplate ()->SetInternalFieldCount (1 );
967
958
t->SetClassName (tlsWrapString);
968
959
960
+ Local<FunctionTemplate> get_write_queue_size =
961
+ FunctionTemplate::New (env->isolate (),
962
+ GetWriteQueueSize,
963
+ env->as_external (),
964
+ Signature::New (env->isolate (), t));
965
+ t->PrototypeTemplate ()->SetAccessorProperty (
966
+ env->write_queue_size_string (),
967
+ get_write_queue_size,
968
+ Local<FunctionTemplate>(),
969
+ static_cast <PropertyAttribute>(ReadOnly | DontDelete));
970
+
969
971
AsyncWrap::AddWrapMethods (env, t, AsyncWrap::kFlagHasReset );
970
972
env->SetProtoMethod (t, " receive" , Receive);
971
973
env->SetProtoMethod (t, " start" , Start);
972
974
env->SetProtoMethod (t, " setVerifyMode" , SetVerifyMode);
973
975
env->SetProtoMethod (t, " enableSessionCallbacks" , EnableSessionCallbacks);
974
976
env->SetProtoMethod (t, " destroySSL" , DestroySSL);
975
977
env->SetProtoMethod (t, " enableCertCb" , EnableCertCb);
976
- env->SetProtoMethod (t, " updateWriteQueueSize" , UpdateWriteQueueSize);
977
978
978
979
StreamBase::AddMethods<TLSWrap>(env, t, StreamBase::kFlagHasWritev );
979
980
SSLWrap<TLSWrap>::AddMethods (env, t);
0 commit comments