From d84d9be6ef2b6e8af3bc32653163fa1879a29094 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 15 Dec 2017 05:09:49 +0100 Subject: [PATCH] src: rename `On*` -> `Emit*` for stream callbacks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This should make these function calls a lot more intuitive for people who are more accustomed to Node’s EventEmitter API. PR-URL: https://github.com/nodejs/node/pull/17701 Reviewed-By: Colin Ihrig Reviewed-By: Timothy Gu Reviewed-By: Anatoli Papirovski Reviewed-By: Ruben Bridgewater --- src/js_stream.cc | 6 +++--- src/stream_base.cc | 2 +- src/stream_base.h | 10 +++++----- src/stream_wrap.cc | 4 ++-- src/tls_wrap.cc | 14 +++++++------- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/js_stream.cc b/src/js_stream.cc index 22d267f5493e2a..739d59df133d29 100644 --- a/src/js_stream.cc +++ b/src/js_stream.cc @@ -201,14 +201,14 @@ void JSStream::ReadBuffer(const FunctionCallbackInfo& args) { do { uv_buf_t buf; ssize_t avail = len; - wrap->OnAlloc(len, &buf); + wrap->EmitAlloc(len, &buf); if (static_cast(buf.len) < avail) avail = buf.len; memcpy(buf.base, data, avail); data += avail; len -= avail; - wrap->OnRead(avail, &buf); + wrap->EmitRead(avail, &buf); } while (len != 0); } @@ -217,7 +217,7 @@ void JSStream::EmitEOF(const FunctionCallbackInfo& args) { JSStream* wrap; ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); - wrap->OnRead(UV_EOF, nullptr); + wrap->EmitRead(UV_EOF, nullptr); } diff --git a/src/stream_base.cc b/src/stream_base.cc index 46d2ff5faf0969..bb25fc1cff0e9c 100644 --- a/src/stream_base.cc +++ b/src/stream_base.cc @@ -402,7 +402,7 @@ void StreamBase::AfterWrite(WriteWrap* req_wrap, int status) { // Unref handle property Local req_wrap_obj = req_wrap->object(); req_wrap_obj->Delete(env->context(), env->handle_string()).FromJust(); - OnAfterWrite(req_wrap, status); + EmitAfterWrite(req_wrap, status); Local argv[] = { Integer::New(env->isolate(), status), diff --git a/src/stream_base.h b/src/stream_base.h index 5bf5f013947347..345554fa05c46e 100644 --- a/src/stream_base.h +++ b/src/stream_base.h @@ -166,19 +166,19 @@ class StreamResource { virtual void ClearError(); // Events - inline void OnAfterWrite(WriteWrap* w, int status) { + inline void EmitAfterWrite(WriteWrap* w, int status) { if (!after_write_cb_.is_empty()) after_write_cb_.fn(w, status, after_write_cb_.ctx); } - inline void OnAlloc(size_t size, uv_buf_t* buf) { + inline void EmitAlloc(size_t size, uv_buf_t* buf) { if (!alloc_cb_.is_empty()) alloc_cb_.fn(size, buf, alloc_cb_.ctx); } - inline void OnRead(ssize_t nread, - const uv_buf_t* buf, - uv_handle_type pending = UV_UNKNOWN_HANDLE) { + inline void EmitRead(ssize_t nread, + const uv_buf_t* buf, + uv_handle_type pending = UV_UNKNOWN_HANDLE) { if (nread > 0) bytes_read_ += static_cast(nread); if (!read_cb_.is_empty()) diff --git a/src/stream_wrap.cc b/src/stream_wrap.cc index 3cce3b151cf0d4..f6cfba84c28a55 100644 --- a/src/stream_wrap.cc +++ b/src/stream_wrap.cc @@ -165,7 +165,7 @@ void LibuvStreamWrap::OnAlloc(uv_handle_t* handle, CHECK_EQ(wrap->stream(), reinterpret_cast(handle)); - return static_cast(wrap)->OnAlloc(suggested_size, buf); + return wrap->EmitAlloc(suggested_size, buf); } @@ -263,7 +263,7 @@ void LibuvStreamWrap::OnRead(uv_stream_t* handle, } } - static_cast(wrap)->OnRead(nread, buf, type); + wrap->EmitRead(nread, buf, type); } diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc index 616771b389c823..c661a0ac32ab2b 100644 --- a/src/tls_wrap.cc +++ b/src/tls_wrap.cc @@ -230,11 +230,11 @@ void TLSWrap::Receive(const FunctionCallbackInfo& args) { // Copy given buffer entirely or partiall if handle becomes closed while (len > 0 && wrap->IsAlive() && !wrap->IsClosing()) { - wrap->stream_->OnAlloc(len, &buf); + wrap->stream_->EmitAlloc(len, &buf); size_t copy = buf.len > len ? len : buf.len; memcpy(buf.base, data, copy); buf.len = copy; - wrap->stream_->OnRead(buf.len, &buf); + wrap->stream_->EmitRead(buf.len, &buf); data += copy; len -= copy; @@ -443,11 +443,11 @@ void TLSWrap::ClearOut() { int avail = read; uv_buf_t buf; - OnAlloc(avail, &buf); + EmitAlloc(avail, &buf); if (static_cast(buf.len) < avail) avail = buf.len; memcpy(buf.base, current, avail); - OnRead(avail, &buf); + EmitRead(avail, &buf); // Caveat emptor: OnRead() calls into JS land which can result in // the SSL context object being destroyed. We have to carefully @@ -463,7 +463,7 @@ void TLSWrap::ClearOut() { int flags = SSL_get_shutdown(ssl_); if (!eof_ && flags & SSL_RECEIVED_SHUTDOWN) { eof_ = true; - OnRead(UV_EOF, nullptr); + EmitRead(UV_EOF, nullptr); } // We need to check whether an error occurred or the connection was @@ -739,13 +739,13 @@ void TLSWrap::DoRead(ssize_t nread, eof_ = true; } - OnRead(nread, nullptr); + EmitRead(nread, nullptr); return; } // Only client connections can receive data if (ssl_ == nullptr) { - OnRead(UV_EPROTO, nullptr); + EmitRead(UV_EPROTO, nullptr); return; }