Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions src/tls_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,22 @@ void TLSWrap::EncOut() {

NODE_COUNT_NET_BYTES_SENT(write_size_);

if (!res.async) {
HandleScope handle_scope(env()->isolate());

// Simulate asynchronous finishing, TLS cannot handle this at the moment.
env()->SetImmediate([](Environment* env, void* data) {
static_cast<TLSWrap*>(data)->OnStreamAfterWrite(nullptr, 0);
}, this, object());
}
if (!res.async)
SyncAfterWrite();
}

// Simulate asynchronous finishing, TLS cannot handle this at the moment.
void TLSWrap::SyncAfterWrite() {
env()->isolate()->EnqueueMicrotask([](void* data) {
TLSWrap* wrap = static_cast<TLSWrap*>(data);
wrap->MakeWeak(wrap);
wrap->OnStreamAfterWrite(nullptr, 0);
}, this);
ClearWeak();
// This is a cheap way for us to ensure that microtasks will get to run
// at some point in the near future.
if (env()->immediate_info()->count() == 0)
env()->SetImmediate([](Environment* env, void* data) {}, this);
}


Expand Down
2 changes: 2 additions & 0 deletions src/tls_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ class TLSWrap : public AsyncWrap,
bool eof_;

private:
void SyncAfterWrite();

static void GetWriteQueueSize(
const v8::FunctionCallbackInfo<v8::Value>& info);
};
Expand Down