summaryrefslogtreecommitdiff
path: root/src/tls_wrap.cc
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2018-01-28 17:26:08 +0100
committerAnna Henningsen <anna@addaleax.net>2018-02-14 10:00:26 +0100
commit82c43aed16cf9b69e2fd44f2e9797a8c56f6fb6d (patch)
tree70f9153d40462c980829d601de75f5ebc7d8dca9 /src/tls_wrap.cc
parentb2e20b002bcc36cc027f7121b99cb0376a6f9af7 (diff)
downloadnode-new-82c43aed16cf9b69e2fd44f2e9797a8c56f6fb6d.tar.gz
tls_wrap: use DoTryWrite()
Use `DoTryWrite()` to write data to the underlying socket. This does probably not make any difference in performance because the callback is still deferred (for now), but brings TLSWrap in line with other things that write to streams. PR-URL: https://github.com/nodejs/node/pull/18676 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/tls_wrap.cc')
-rw-r--r--src/tls_wrap.cc26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc
index 0cba1898fb..ee6e120ca0 100644
--- a/src/tls_wrap.cc
+++ b/src/tls_wrap.cc
@@ -280,6 +280,22 @@ void TLSWrap::EncOut() {
&count);
CHECK(write_size_ != 0 && count != 0);
+ uv_buf_t buf[arraysize(data)];
+ uv_buf_t* bufs = buf;
+ for (size_t i = 0; i < count; i++)
+ buf[i] = uv_buf_init(data[i], size[i]);
+
+ int err = stream_->DoTryWrite(&bufs, &count);
+ if (err != 0) {
+ InvokeQueued(err);
+ } else if (count == 0) {
+ env()->SetImmediate([](Environment* env, void* data) {
+ NODE_COUNT_NET_BYTES_SENT(write_size_);
+ static_cast<TLSWrap*>(data)->OnStreamAfterWrite(nullptr, 0);
+ }, this, object());
+ return;
+ }
+
Local<Object> req_wrap_obj =
env()->write_wrap_constructor_function()
->NewInstance(env()->context()).ToLocalChecked();
@@ -287,10 +303,7 @@ void TLSWrap::EncOut() {
req_wrap_obj,
static_cast<StreamBase*>(stream_));
- uv_buf_t buf[arraysize(data)];
- for (size_t i = 0; i < count; i++)
- buf[i] = uv_buf_init(data[i], size[i]);
- int err = stream_->DoWrite(write_req, buf, count, nullptr);
+ err = stream_->DoWrite(write_req, buf, count, nullptr);
// Ignore errors, this should be already handled in js
if (err) {
@@ -303,9 +316,8 @@ void TLSWrap::EncOut() {
void TLSWrap::OnStreamAfterWrite(WriteWrap* req_wrap, int status) {
- // We should not be getting here after `DestroySSL`, because all queued writes
- // must be invoked with UV_ECANCELED
- CHECK_NE(ssl_, nullptr);
+ if (ssl_ == nullptr)
+ status = UV_ECANCELED;
// Handle error
if (status) {