Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: rename On* -> Emit* for stream callbacks #17701

Closed
wants to merge 1 commit into from
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
6 changes: 3 additions & 3 deletions src/js_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,14 @@ void JSStream::ReadBuffer(const FunctionCallbackInfo<Value>& args) {
do {
uv_buf_t buf;
ssize_t avail = len;
wrap->OnAlloc(len, &buf);
wrap->EmitAlloc(len, &buf);
if (static_cast<ssize_t>(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);
}

Expand All @@ -217,7 +217,7 @@ void JSStream::EmitEOF(const FunctionCallbackInfo<Value>& args) {
JSStream* wrap;
ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());

wrap->OnRead(UV_EOF, nullptr);
wrap->EmitRead(UV_EOF, nullptr);
}


Expand Down
2 changes: 1 addition & 1 deletion src/stream_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ void StreamBase::AfterWrite(WriteWrap* req_wrap, int status) {
// Unref handle property
Local<Object> 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<Value> argv[] = {
Integer::New(env->isolate(), status),
Expand Down
10 changes: 5 additions & 5 deletions src/stream_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint64_t>(nread);
if (!read_cb_.is_empty())
Expand Down
4 changes: 2 additions & 2 deletions src/stream_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void LibuvStreamWrap::OnAlloc(uv_handle_t* handle,

CHECK_EQ(wrap->stream(), reinterpret_cast<uv_stream_t*>(handle));

return static_cast<StreamBase*>(wrap)->OnAlloc(suggested_size, buf);
return wrap->EmitAlloc(suggested_size, buf);
}


Expand Down Expand Up @@ -263,7 +263,7 @@ void LibuvStreamWrap::OnRead(uv_stream_t* handle,
}
}

static_cast<StreamBase*>(wrap)->OnRead(nread, buf, type);
wrap->EmitRead(nread, buf, type);
}


Expand Down
14 changes: 7 additions & 7 deletions src/tls_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,11 @@ void TLSWrap::Receive(const FunctionCallbackInfo<Value>& 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;
Expand Down Expand Up @@ -443,11 +443,11 @@ void TLSWrap::ClearOut() {
int avail = read;

uv_buf_t buf;
OnAlloc(avail, &buf);
EmitAlloc(avail, &buf);
if (static_cast<int>(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
Expand All @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down