Skip to content

Commit d84d9be

Browse files
addaleaxMylesBorins
authored andcommitted
src: rename On* -> Emit* for stream callbacks
This should make these function calls a lot more intuitive for people who are more accustomed to Node’s EventEmitter API. PR-URL: #17701 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 6f520e3 commit d84d9be

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

src/js_stream.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,14 @@ void JSStream::ReadBuffer(const FunctionCallbackInfo<Value>& args) {
201201
do {
202202
uv_buf_t buf;
203203
ssize_t avail = len;
204-
wrap->OnAlloc(len, &buf);
204+
wrap->EmitAlloc(len, &buf);
205205
if (static_cast<ssize_t>(buf.len) < avail)
206206
avail = buf.len;
207207

208208
memcpy(buf.base, data, avail);
209209
data += avail;
210210
len -= avail;
211-
wrap->OnRead(avail, &buf);
211+
wrap->EmitRead(avail, &buf);
212212
} while (len != 0);
213213
}
214214

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

220-
wrap->OnRead(UV_EOF, nullptr);
220+
wrap->EmitRead(UV_EOF, nullptr);
221221
}
222222

223223

src/stream_base.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ void StreamBase::AfterWrite(WriteWrap* req_wrap, int status) {
402402
// Unref handle property
403403
Local<Object> req_wrap_obj = req_wrap->object();
404404
req_wrap_obj->Delete(env->context(), env->handle_string()).FromJust();
405-
OnAfterWrite(req_wrap, status);
405+
EmitAfterWrite(req_wrap, status);
406406

407407
Local<Value> argv[] = {
408408
Integer::New(env->isolate(), status),

src/stream_base.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -166,19 +166,19 @@ class StreamResource {
166166
virtual void ClearError();
167167

168168
// Events
169-
inline void OnAfterWrite(WriteWrap* w, int status) {
169+
inline void EmitAfterWrite(WriteWrap* w, int status) {
170170
if (!after_write_cb_.is_empty())
171171
after_write_cb_.fn(w, status, after_write_cb_.ctx);
172172
}
173173

174-
inline void OnAlloc(size_t size, uv_buf_t* buf) {
174+
inline void EmitAlloc(size_t size, uv_buf_t* buf) {
175175
if (!alloc_cb_.is_empty())
176176
alloc_cb_.fn(size, buf, alloc_cb_.ctx);
177177
}
178178

179-
inline void OnRead(ssize_t nread,
180-
const uv_buf_t* buf,
181-
uv_handle_type pending = UV_UNKNOWN_HANDLE) {
179+
inline void EmitRead(ssize_t nread,
180+
const uv_buf_t* buf,
181+
uv_handle_type pending = UV_UNKNOWN_HANDLE) {
182182
if (nread > 0)
183183
bytes_read_ += static_cast<uint64_t>(nread);
184184
if (!read_cb_.is_empty())

src/stream_wrap.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ void LibuvStreamWrap::OnAlloc(uv_handle_t* handle,
165165

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

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

171171

@@ -263,7 +263,7 @@ void LibuvStreamWrap::OnRead(uv_stream_t* handle,
263263
}
264264
}
265265

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

269269

src/tls_wrap.cc

+7-7
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,11 @@ void TLSWrap::Receive(const FunctionCallbackInfo<Value>& args) {
230230

231231
// Copy given buffer entirely or partiall if handle becomes closed
232232
while (len > 0 && wrap->IsAlive() && !wrap->IsClosing()) {
233-
wrap->stream_->OnAlloc(len, &buf);
233+
wrap->stream_->EmitAlloc(len, &buf);
234234
size_t copy = buf.len > len ? len : buf.len;
235235
memcpy(buf.base, data, copy);
236236
buf.len = copy;
237-
wrap->stream_->OnRead(buf.len, &buf);
237+
wrap->stream_->EmitRead(buf.len, &buf);
238238

239239
data += copy;
240240
len -= copy;
@@ -443,11 +443,11 @@ void TLSWrap::ClearOut() {
443443
int avail = read;
444444

445445
uv_buf_t buf;
446-
OnAlloc(avail, &buf);
446+
EmitAlloc(avail, &buf);
447447
if (static_cast<int>(buf.len) < avail)
448448
avail = buf.len;
449449
memcpy(buf.base, current, avail);
450-
OnRead(avail, &buf);
450+
EmitRead(avail, &buf);
451451

452452
// Caveat emptor: OnRead() calls into JS land which can result in
453453
// the SSL context object being destroyed. We have to carefully
@@ -463,7 +463,7 @@ void TLSWrap::ClearOut() {
463463
int flags = SSL_get_shutdown(ssl_);
464464
if (!eof_ && flags & SSL_RECEIVED_SHUTDOWN) {
465465
eof_ = true;
466-
OnRead(UV_EOF, nullptr);
466+
EmitRead(UV_EOF, nullptr);
467467
}
468468

469469
// We need to check whether an error occurred or the connection was
@@ -739,13 +739,13 @@ void TLSWrap::DoRead(ssize_t nread,
739739
eof_ = true;
740740
}
741741

742-
OnRead(nread, nullptr);
742+
EmitRead(nread, nullptr);
743743
return;
744744
}
745745

746746
// Only client connections can receive data
747747
if (ssl_ == nullptr) {
748-
OnRead(UV_EPROTO, nullptr);
748+
EmitRead(UV_EPROTO, nullptr);
749749
return;
750750
}
751751

0 commit comments

Comments
 (0)