@@ -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
@@ -307,7 +309,6 @@ void TLSWrap::EncOut() {
307
309
308
310
// No data to write
309
311
if (BIO_pending (enc_out_) == 0 ) {
310
- UpdateWriteQueueSize ();
311
312
if (clear_in_->Length () == 0 )
312
313
InvokeQueued (0 );
313
314
return ;
@@ -553,17 +554,6 @@ bool TLSWrap::IsClosing() {
553
554
}
554
555
555
556
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
-
567
557
568
558
int TLSWrap::ReadStart () {
569
559
if (stream_ != nullptr )
@@ -610,9 +600,6 @@ int TLSWrap::DoWrite(WriteWrap* w,
610
600
// However, if there is any data that should be written to the socket,
611
601
// the callback should not be invoked immediately
612
602
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 );
616
603
return stream_->DoWrite (w, bufs, count, send_handle);
617
604
}
618
605
}
@@ -665,7 +652,6 @@ int TLSWrap::DoWrite(WriteWrap* w,
665
652
666
653
// Try writing data immediately
667
654
EncOut ();
668
- UpdateWriteQueueSize ();
669
655
670
656
return 0 ;
671
657
}
@@ -937,12 +923,17 @@ int TLSWrap::SelectSNIContextCallback(SSL* s, int* ad, void* arg) {
937
923
#endif // SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
938
924
939
925
940
- void TLSWrap::UpdateWriteQueueSize (const FunctionCallbackInfo<Value>& args ) {
926
+ void TLSWrap::GetWriteQueueSize (const FunctionCallbackInfo<Value>& info ) {
941
927
TLSWrap* wrap;
942
- ASSIGN_OR_RETURN_UNWRAP (&wrap, args. Holder ());
928
+ ASSIGN_OR_RETURN_UNWRAP (&wrap, info. This ());
943
929
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);
946
937
}
947
938
948
939
@@ -965,14 +956,24 @@ void TLSWrap::Initialize(Local<Object> target,
965
956
t->InstanceTemplate ()->SetInternalFieldCount (1 );
966
957
t->SetClassName (tlsWrapString);
967
958
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
+
968
970
AsyncWrap::AddWrapMethods (env, t, AsyncWrap::kFlagHasReset );
969
971
env->SetProtoMethod (t, " receive" , Receive);
970
972
env->SetProtoMethod (t, " start" , Start);
971
973
env->SetProtoMethod (t, " setVerifyMode" , SetVerifyMode);
972
974
env->SetProtoMethod (t, " enableSessionCallbacks" , EnableSessionCallbacks);
973
975
env->SetProtoMethod (t, " destroySSL" , DestroySSL);
974
976
env->SetProtoMethod (t, " enableCertCb" , EnableCertCb);
975
- env->SetProtoMethod (t, " updateWriteQueueSize" , UpdateWriteQueueSize);
976
977
977
978
StreamBase::AddMethods<TLSWrap>(env, t, StreamBase::kFlagHasWritev );
978
979
SSLWrap<TLSWrap>::AddMethods (env, t);
0 commit comments