summaryrefslogtreecommitdiff
path: root/src/stream_base-inl.h
diff options
context:
space:
mode:
authorFedor Indutny <fedor@indutny.com>2016-04-19 14:46:53 -0400
committerFedor Indutny <fedor@indutny.com>2016-04-20 12:42:33 -0400
commit6198472d8390d9476f555c634b7aa66ce6c6d0fe (patch)
tree506f7b4824a8754ff2645b49077e918af627386b /src/stream_base-inl.h
parente1cf634a0bd0cae2b54c60c8f19fc29079bdc309 (diff)
downloadandroid-node-v8-6198472d8390d9476f555c634b7aa66ce6c6d0fe.tar.gz
android-node-v8-6198472d8390d9476f555c634b7aa66ce6c6d0fe.tar.bz2
android-node-v8-6198472d8390d9476f555c634b7aa66ce6c6d0fe.zip
stream_base: expose `bytesRead` getter
This will provide `bytesRead` data on consumed sockets. Fix: #3021 PR-URL: https://github.com/nodejs/node/pull/6284 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'src/stream_base-inl.h')
-rw-r--r--src/stream_base-inl.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/stream_base-inl.h b/src/stream_base-inl.h
index 81114a265e..099e105334 100644
--- a/src/stream_base-inl.h
+++ b/src/stream_base-inl.h
@@ -43,6 +43,13 @@ void StreamBase::AddMethods(Environment* env,
v8::DEFAULT,
attributes);
+ t->InstanceTemplate()->SetAccessor(env->bytes_read_string(),
+ GetBytesRead<Base>,
+ nullptr,
+ env->as_external(),
+ v8::DEFAULT,
+ attributes);
+
env->SetProtoMethod(t, "readStart", JSMethod<Base, &StreamBase::ReadStart>);
env->SetProtoMethod(t, "readStop", JSMethod<Base, &StreamBase::ReadStop>);
if ((flags & kFlagNoShutdown) == 0)
@@ -80,6 +87,16 @@ void StreamBase::GetFD(Local<String> key,
template <class Base>
+void StreamBase::GetBytesRead(Local<String> key,
+ const PropertyCallbackInfo<Value>& args) {
+ StreamBase* wrap = Unwrap<Base>(args.Holder());
+
+ // uint64_t -> double. 53bits is enough for all real cases.
+ args.GetReturnValue().Set(static_cast<double>(wrap->bytes_read_));
+}
+
+
+template <class Base>
void StreamBase::GetExternal(Local<String> key,
const PropertyCallbackInfo<Value>& args) {
StreamBase* wrap = Unwrap<Base>(args.Holder());