summaryrefslogtreecommitdiff
path: root/src/stream_base-inl.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/stream_base-inl.h')
-rw-r--r--src/stream_base-inl.h28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/stream_base-inl.h b/src/stream_base-inl.h
index f4c228d7c5..35e49dfea2 100644
--- a/src/stream_base-inl.h
+++ b/src/stream_base-inl.h
@@ -193,6 +193,10 @@ inline StreamWriteResult StreamBase::Write(
v8::Local<v8::Object> req_wrap_obj) {
Environment* env = stream_env();
int err;
+
+ for (size_t i = 0; i < count; ++i)
+ bytes_written_ += bufs[i].len;
+
if (send_handle == nullptr) {
err = DoTryWrite(&bufs, &count);
if (err != 0 || count == 0) {
@@ -301,6 +305,12 @@ void StreamBase::AddMethods(Environment* env,
env->as_external(),
signature);
+ Local<FunctionTemplate> get_bytes_written_templ =
+ FunctionTemplate::New(env->isolate(),
+ GetBytesWritten<Base>,
+ env->as_external(),
+ signature);
+
t->PrototypeTemplate()->SetAccessorProperty(env->fd_string(),
get_fd_templ,
Local<FunctionTemplate>(),
@@ -316,6 +326,11 @@ void StreamBase::AddMethods(Environment* env,
Local<FunctionTemplate>(),
attributes);
+ t->PrototypeTemplate()->SetAccessorProperty(env->bytes_written_string(),
+ get_bytes_written_templ,
+ Local<FunctionTemplate>(),
+ attributes);
+
env->SetProtoMethod(t, "readStart", JSMethod<Base, &StreamBase::ReadStartJS>);
env->SetProtoMethod(t, "readStop", JSMethod<Base, &StreamBase::ReadStopJS>);
if ((flags & kFlagNoShutdown) == 0)
@@ -357,7 +372,6 @@ void StreamBase::GetFD(const FunctionCallbackInfo<Value>& args) {
template <class Base>
void StreamBase::GetBytesRead(const FunctionCallbackInfo<Value>& args) {
- // The handle instance hasn't been set. So no bytes could have been read.
Base* handle;
ASSIGN_OR_RETURN_UNWRAP(&handle,
args.This(),
@@ -369,6 +383,18 @@ void StreamBase::GetBytesRead(const FunctionCallbackInfo<Value>& args) {
}
template <class Base>
+void StreamBase::GetBytesWritten(const FunctionCallbackInfo<Value>& args) {
+ Base* handle;
+ ASSIGN_OR_RETURN_UNWRAP(&handle,
+ args.This(),
+ args.GetReturnValue().Set(0));
+
+ StreamBase* wrap = static_cast<StreamBase*>(handle);
+ // uint64_t -> double. 53bits is enough for all real cases.
+ args.GetReturnValue().Set(static_cast<double>(wrap->bytes_written_));
+}
+
+template <class Base>
void StreamBase::GetExternal(const FunctionCallbackInfo<Value>& args) {
Base* handle;
ASSIGN_OR_RETURN_UNWRAP(&handle, args.This());