| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 81da708 commit 25ce458
14 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -460,11 +460,6 @@ TLSSocket.prototype._init = function(socket, wrap) { | |||
| 460 | 460 | var options = this._tlsOptions; | |
| 461 | 461 | var ssl = this._handle; | |
| 462 | 462 | ||
| 463 | - // lib/net.js expect this value to be non-zero if write hasn't been flushed | ||
| 464 | - // immediately. After the handshake is done this will represent the actual | ||
| 465 | - // write queue size | ||
| 466 | - ssl.writeQueueSize = 1; | ||
| 467 | - | ||
| 468 | 463 | this.server = options.server; | |
| 469 | 464 | ||
| 470 | 465 | // For clients, we will always have either a given ca list or be using | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -48,6 +48,8 @@ const { nextTick } = require('internal/process/next_tick'); | |||
| 48 | 48 | const errors = require('internal/errors'); | |
| 49 | 49 | const dns = require('dns'); | |
| 50 | 50 | ||
| 51 | + const kLastWriteQueueSize = Symbol('lastWriteQueueSize'); | ||
| 52 | + | ||
| 51 | 53 | // `cluster` is only used by `listenInCluster` so for startup performance | |
| 52 | 54 | // reasons it's lazy loaded. | |
| 53 | 55 | var cluster = null; | |
@@ -198,6 +200,7 @@ function Socket(options) { | |||
| 198 | 200 | this._handle = null; | |
| 199 | 201 | this._parent = null; | |
| 200 | 202 | this._host = null; | |
| 203 | + this[kLastWriteQueueSize] = 0; | ||
| 201 | 204 | ||
| 202 | 205 | if (typeof options === 'number') | |
| 203 | 206 | options = { fd: options }; // Legacy interface. | |
@@ -401,12 +404,14 @@ Socket.prototype.setTimeout = function(msecs, callback) { | |||
| 401 | 404 | ||
| 402 | 405 | ||
| 403 | 406 | Socket.prototype._onTimeout = function() { | |
| 404 | - if (this._handle) { | ||
| 405 | - // `.prevWriteQueueSize` !== `.updateWriteQueueSize()` means there is | ||
| 407 | + const handle = this._handle; | ||
| 408 | + const lastWriteQueueSize = this[kLastWriteQueueSize]; | ||
| 409 | + if (lastWriteQueueSize > 0 && handle) { | ||
| 410 | + // `lastWriteQueueSize !== writeQueueSize` means there is | ||
| 406 | 411 | // an active write in progress, so we suppress the timeout. | |
| 407 | - const prevWriteQueueSize = this._handle.writeQueueSize; | ||
| 408 | - if (prevWriteQueueSize > 0 && | ||
| 409 | - prevWriteQueueSize !== this._handle.updateWriteQueueSize()) { | ||
| 412 | + const writeQueueSize = handle.writeQueueSize; | ||
| 413 | + if (lastWriteQueueSize !== writeQueueSize) { | ||
| 414 | + this[kLastWriteQueueSize] = writeQueueSize; | ||
| 410 | 415 | this._unrefTimer(); | |
| 411 | 416 | return; | |
| 412 | 417 | } | |
@@ -476,7 +481,7 @@ Object.defineProperty(Socket.prototype, 'readyState', { | |||
| 476 | 481 | Object.defineProperty(Socket.prototype, 'bufferSize', { | |
| 477 | 482 | get: function() { | |
| 478 | 483 | if (this._handle) { | |
| 479 | - return this._handle.writeQueueSize + this.writableLength; | ||
| 484 | + return this[kLastWriteQueueSize] + this.writableLength; | ||
| 480 | 485 | } | |
| 481 | 486 | } | |
| 482 | 487 | }); | |
@@ -767,12 +772,13 @@ Socket.prototype._writeGeneric = function(writev, data, encoding, cb) { | |||
| 767 | 772 | ||
| 768 | 773 | this._bytesDispatched += req.bytes; | |
| 769 | 774 | ||
| 770 | - // If it was entirely flushed, we can write some more right now. | ||
| 771 | - // However, if more is left in the queue, then wait until that clears. | ||
| 772 | - if (req.async && this._handle.writeQueueSize !== 0) | ||
| 773 | - req.cb = cb; | ||
| 774 | - else | ||
| 775 | + if (!req.async) { | ||
| 775 | 776 | cb(); | |
| 777 | + return; | ||
| 778 | + } | ||
| 779 | + | ||
| 780 | + req.cb = cb; | ||
| 781 | + this[kLastWriteQueueSize] = req.bytes; | ||
| 776 | 782 | }; | |
| 777 | 783 | ||
| 778 | 784 | ||
@@ -856,6 +862,9 @@ function afterWrite(status, handle, req, err) { | |||
| 856 | 862 | if (self !== process.stderr && self !== process.stdout) | |
| 857 | 863 | debug('afterWrite', status); | |
| 858 | 864 | ||
| 865 | + if (req.async) | ||
| 866 | + self[kLastWriteQueueSize] = 0; | ||
| 867 | + | ||
| 859 | 868 | // callback may come after call to destroy. | |
| 860 | 869 | if (self.destroyed) { | |
| 861 | 870 | debug('afterWrite destroyed'); | |
@@ -875,7 +884,7 @@ function afterWrite(status, handle, req, err) { | |||
| 875 | 884 | debug('afterWrite call cb'); | |
| 876 | 885 | ||
| 877 | 886 | if (req.cb) | |
| 878 | - req.cb.call(self); | ||
| 887 | + req.cb.call(undefined); | ||
| 879 | 888 | } | |
| 880 | 889 | ||
| 881 | 890 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -166,7 +166,6 @@ PipeWrap::PipeWrap(Environment* env, | |||
| 166 | 166 | int r = uv_pipe_init(env->event_loop(), &handle_, ipc); | |
| 167 | 167 | CHECK_EQ(r, 0); // How do we proxy this error up to javascript? | |
| 168 | 168 | // Suggestion: uv_pipe_init() returns void. | |
| 169 | - UpdateWriteQueueSize(); | ||
| 170 | 169 | } | |
| 171 | 170 | ||
| 172 | 171 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -195,7 +195,8 @@ int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) { | |||
| 195 | 195 | } | |
| 196 | 196 | ||
| 197 | 197 | err = DoWrite(req_wrap, buf_list, count, nullptr); | |
| 198 | - req_wrap_obj->Set(env->async(), True(env->isolate())); | ||
| 198 | + if (HasWriteQueue()) | ||
| 199 | + req_wrap_obj->Set(env->async(), True(env->isolate())); | ||
| 199 | 200 | ||
| 200 | 201 | if (err) | |
| 201 | 202 | req_wrap->Dispose(); | |
@@ -253,7 +254,8 @@ int StreamBase::WriteBuffer(const FunctionCallbackInfo<Value>& args) { | |||
| 253 | 254 | } | |
| 254 | 255 | ||
| 255 | 256 | err = DoWrite(req_wrap, bufs, count, nullptr); | |
| 256 | - req_wrap_obj->Set(env->async(), True(env->isolate())); | ||
| 257 | + if (HasWriteQueue()) | ||
| 258 | + req_wrap_obj->Set(env->async(), True(env->isolate())); | ||
| 257 | 259 | req_wrap_obj->Set(env->buffer_string(), args[1]); | |
| 258 | 260 | ||
| 259 | 261 | if (err) | |
@@ -379,7 +381,8 @@ int StreamBase::WriteString(const FunctionCallbackInfo<Value>& args) { | |||
| 379 | 381 | reinterpret_cast<uv_stream_t*>(send_handle)); | |
| 380 | 382 | } | |
| 381 | 383 | ||
| 382 | - req_wrap_obj->Set(env->async(), True(env->isolate())); | ||
| 384 | + if (HasWriteQueue()) | ||
| 385 | + req_wrap_obj->Set(env->async(), True(env->isolate())); | ||
| 383 | 386 | ||
| 384 | 387 | if (err) | |
| 385 | 388 | req_wrap->Dispose(); | |
@@ -473,6 +476,10 @@ int StreamResource::DoTryWrite(uv_buf_t** bufs, size_t* count) { | |||
| 473 | 476 | return 0; | |
| 474 | 477 | } | |
| 475 | 478 | ||
| 479 | + bool StreamResource::HasWriteQueue() { | ||
| 480 | + return true; | ||
| 481 | + } | ||
| 482 | + | ||
| 476 | 483 | ||
| 477 | 484 | const char* StreamResource::Error() const { | |
| 478 | 485 | return nullptr; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -162,6 +162,7 @@ class StreamResource { | |||
| 162 | 162 | uv_buf_t* bufs, | |
| 163 | 163 | size_t count, | |
| 164 | 164 | uv_stream_t* send_handle) = 0; | |
| 165 | + virtual bool HasWriteQueue(); | ||
| 165 | 166 | virtual const char* Error() const; | |
| 166 | 167 | virtual void ClearError(); | |
| 167 | 168 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -40,13 +40,15 @@ | |||
| 40 | 40 | namespace node { | |
| 41 | 41 | ||
| 42 | 42 | using v8::Context; | |
| 43 | + using v8::DontDelete; | ||
| 43 | 44 | using v8::EscapableHandleScope; | |
| 44 | 45 | using v8::FunctionCallbackInfo; | |
| 45 | 46 | using v8::FunctionTemplate; | |
| 46 | 47 | using v8::HandleScope; | |
| 47 | - using v8::Integer; | ||
| 48 | 48 | using v8::Local; | |
| 49 | 49 | using v8::Object; | |
| 50 | + using v8::ReadOnly; | ||
| 51 | + using v8::Signature; | ||
| 50 | 52 | using v8::Value; | |
| 51 | 53 | ||
| 52 | 54 | ||
@@ -99,7 +101,16 @@ LibuvStreamWrap::LibuvStreamWrap(Environment* env, | |||
| 99 | 101 | void LibuvStreamWrap::AddMethods(Environment* env, | |
| 100 | 102 | v8::Local<v8::FunctionTemplate> target, | |
| 101 | 103 | int flags) { | |
| 102 | - env->SetProtoMethod(target, "updateWriteQueueSize", UpdateWriteQueueSize); | ||
| 104 | + Local<FunctionTemplate> get_write_queue_size = | ||
| 105 | + FunctionTemplate::New(env->isolate(), | ||
| 106 | + GetWriteQueueSize, | ||
| 107 | + env->as_external(), | ||
| 108 | + Signature::New(env->isolate(), target)); | ||
| 109 | + target->PrototypeTemplate()->SetAccessorProperty( | ||
| 110 | + env->write_queue_size_string(), | ||
| 111 | + get_write_queue_size, | ||
| 112 | + Local<FunctionTemplate>(), | ||
| 113 | + static_cast<PropertyAttribute>(ReadOnly | DontDelete)); | ||
| 103 | 114 | env->SetProtoMethod(target, "setBlocking", SetBlocking); | |
| 104 | 115 | StreamBase::AddMethods<LibuvStreamWrap>(env, target, flags); | |
| 105 | 116 | } | |
@@ -135,17 +146,6 @@ bool LibuvStreamWrap::IsIPCPipe() { | |||
| 135 | 146 | } | |
| 136 | 147 | ||
| 137 | 148 | ||
| 138 | - uint32_t LibuvStreamWrap::UpdateWriteQueueSize() { | ||
| 139 | - HandleScope scope(env()->isolate()); | ||
| 140 | - uint32_t write_queue_size = stream()->write_queue_size; | ||
| 141 | - object()->Set(env()->context(), | ||
| 142 | - env()->write_queue_size_string(), | ||
| 143 | - Integer::NewFromUnsigned(env()->isolate(), | ||
| 144 | - write_queue_size)).FromJust(); | ||
| 145 | - return write_queue_size; | ||
| 146 | - } | ||
| 147 | - | ||
| 148 | - | ||
| 149 | 149 | int LibuvStreamWrap::ReadStart() { | |
| 150 | 150 | return uv_read_start(stream(), OnAlloc, OnRead); | |
| 151 | 151 | } | |
@@ -267,13 +267,18 @@ void LibuvStreamWrap::OnRead(uv_stream_t* handle, | |||
| 267 | 267 | } | |
| 268 | 268 | ||
| 269 | 269 | ||
| 270 | - void LibuvStreamWrap::UpdateWriteQueueSize( | ||
| 271 | - const FunctionCallbackInfo<Value>& args) { | ||
| 270 | + void LibuvStreamWrap::GetWriteQueueSize( | ||
| 271 | + const FunctionCallbackInfo<Value>& info) { | ||
| 272 | 272 | LibuvStreamWrap* wrap; | |
| 273 | - ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); | ||
| 273 | + ASSIGN_OR_RETURN_UNWRAP(&wrap, info.This()); | ||
| 274 | + | ||
| 275 | + if (wrap->stream() == nullptr) { | ||
| 276 | + info.GetReturnValue().Set(0); | ||
| 277 | + return; | ||
| 278 | + } | ||
| 274 | 279 | ||
| 275 | - uint32_t write_queue_size = wrap->UpdateWriteQueueSize(); | ||
| 276 | - args.GetReturnValue().Set(write_queue_size); | ||
| 280 | + uint32_t write_queue_size = wrap->stream()->write_queue_size; | ||
| 281 | + info.GetReturnValue().Set(write_queue_size); | ||
| 277 | 282 | } | |
| 278 | 283 | ||
| 279 | 284 | ||
@@ -370,12 +375,16 @@ int LibuvStreamWrap::DoWrite(WriteWrap* w, | |||
| 370 | 375 | } | |
| 371 | 376 | ||
| 372 | 377 | w->Dispatched(); | |
| 373 | - UpdateWriteQueueSize(); | ||
| 374 | 378 | ||
| 375 | 379 | return r; | |
| 376 | 380 | } | |
| 377 | 381 | ||
| 378 | 382 | ||
| 383 | + bool LibuvStreamWrap::HasWriteQueue() { | ||
| 384 | + return stream()->write_queue_size > 0; | ||
| 385 | + } | ||
| 386 | + | ||
| 387 | + | ||
| 379 | 388 | void LibuvStreamWrap::AfterUvWrite(uv_write_t* req, int status) { | |
| 380 | 389 | WriteWrap* req_wrap = WriteWrap::from_req(req); | |
| 381 | 390 | CHECK_NE(req_wrap, nullptr); | |
@@ -387,7 +396,6 @@ void LibuvStreamWrap::AfterUvWrite(uv_write_t* req, int status) { | |||
| 387 | 396 | ||
| 388 | 397 | void LibuvStreamWrap::AfterWrite(WriteWrap* w, int status) { | |
| 389 | 398 | StreamBase::AfterWrite(w, status); | |
| 390 | - UpdateWriteQueueSize(); | ||
| 391 | 399 | } | |
| 392 | 400 | ||
| 393 | 401 | } // namespace node | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -55,6 +55,7 @@ class LibuvStreamWrap : public HandleWrap, public StreamBase { | |||
| 55 | 55 | uv_buf_t* bufs, | |
| 56 | 56 | size_t count, | |
| 57 | 57 | uv_stream_t* send_handle) override; | |
| 58 | + bool HasWriteQueue() override; | ||
| 58 | 59 | ||
| 59 | 60 | inline uv_stream_t* stream() const { | |
| 60 | 61 | return stream_; | |
@@ -83,15 +84,14 @@ class LibuvStreamWrap : public HandleWrap, public StreamBase { | |||
| 83 | 84 | } | |
| 84 | 85 | ||
| 85 | 86 | AsyncWrap* GetAsyncWrap() override; | |
| 86 | - uint32_t UpdateWriteQueueSize(); | ||
| 87 | 87 | ||
| 88 | 88 | static void AddMethods(Environment* env, | |
| 89 | 89 | v8::Local<v8::FunctionTemplate> target, | |
| 90 | 90 | int flags = StreamBase::kFlagNone); | |
| 91 | 91 | ||
| 92 | 92 | private: | |
| 93 | - static void UpdateWriteQueueSize( | ||
| 94 | - const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| 93 | + static void GetWriteQueueSize( | ||
| 94 | + const v8::FunctionCallbackInfo<v8::Value>& info); | ||
| 95 | 95 | static void SetBlocking(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 96 | 96 | ||
| 97 | 97 | // Callbacks for libuv | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -170,7 +170,6 @@ TCPWrap::TCPWrap(Environment* env, Local<Object> object, ProviderType provider) | |||
| 170 | 170 | int r = uv_tcp_init(env->event_loop(), &handle_); | |
| 171 | 171 | CHECK_EQ(r, 0); // How do we proxy this error up to javascript? | |
| 172 | 172 | // Suggestion: uv_tcp_init() returns void. | |
| 173 | - UpdateWriteQueueSize(); | ||
| 174 | 173 | } | |
| 175 | 174 | ||
| 176 | 175 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -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); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments