diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/env.h | 2 | ||||
-rw-r--r-- | src/stream_base.cc | 33 | ||||
-rw-r--r-- | src/stream_base.h | 4 | ||||
-rw-r--r-- | src/stream_wrap.cc | 2 |
4 files changed, 13 insertions, 28 deletions
@@ -128,10 +128,8 @@ constexpr size_t kFsStatsBufferLength = kFsStatsFieldsNumber * 2; V(address_string, "address") \ V(aliases_string, "aliases") \ V(args_string, "args") \ - V(async, "async") \ V(async_ids_stack_string, "async_ids_stack") \ V(buffer_string, "buffer") \ - V(bytes_string, "bytes") \ V(bytes_parsed_string, "bytesParsed") \ V(bytes_read_string, "bytesRead") \ V(bytes_written_string, "bytesWritten") \ diff --git a/src/stream_base.cc b/src/stream_base.cc index 57713d5eaf..adb839c3e5 100644 --- a/src/stream_base.cc +++ b/src/stream_base.cc @@ -18,13 +18,11 @@ namespace node { using v8::Array; using v8::ArrayBuffer; -using v8::Boolean; using v8::Context; using v8::FunctionCallbackInfo; using v8::HandleScope; using v8::Integer; using v8::Local; -using v8::Number; using v8::Object; using v8::String; using v8::Value; @@ -56,18 +54,9 @@ int StreamBase::Shutdown(const FunctionCallbackInfo<Value>& args) { return Shutdown(req_wrap_obj); } -inline void SetWriteResultPropertiesOnWrapObject( - Environment* env, - Local<Object> req_wrap_obj, - const StreamWriteResult& res) { - req_wrap_obj->Set( - env->context(), - env->bytes_string(), - Number::New(env->isolate(), res.bytes)).FromJust(); - req_wrap_obj->Set( - env->context(), - env->async(), - Boolean::New(env->isolate(), res.async)).FromJust(); +void StreamBase::SetWriteResult(const StreamWriteResult& res) { + env_->stream_base_state()[kBytesWritten] = res.bytes; + env_->stream_base_state()[kLastWriteWasAsync] = res.async; } int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) { @@ -160,7 +149,7 @@ int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) { } StreamWriteResult res = Write(*bufs, count, nullptr, req_wrap_obj); - SetWriteResultPropertiesOnWrapObject(env, req_wrap_obj, res); + SetWriteResult(res); if (res.wrap != nullptr && storage_size > 0) { res.wrap->SetAllocatedStorage(storage.release(), storage_size); } @@ -185,10 +174,7 @@ int StreamBase::WriteBuffer(const FunctionCallbackInfo<Value>& args) { buf.len = Buffer::Length(args[1]); StreamWriteResult res = Write(&buf, 1, nullptr, req_wrap_obj); - - if (res.async) - req_wrap_obj->Set(env->context(), env->buffer_string(), args[1]).FromJust(); - SetWriteResultPropertiesOnWrapObject(env, req_wrap_obj, res); + SetWriteResult(res); return res.err; } @@ -247,12 +233,7 @@ int StreamBase::WriteString(const FunctionCallbackInfo<Value>& args) { // Immediate failure or success if (err != 0 || count == 0) { - req_wrap_obj->Set(env->context(), env->async(), False(env->isolate())) - .FromJust(); - req_wrap_obj->Set(env->context(), - env->bytes_string(), - Integer::NewFromUnsigned(env->isolate(), data_size)) - .FromJust(); + SetWriteResult(StreamWriteResult { false, err, nullptr, data_size }); return err; } @@ -295,7 +276,7 @@ int StreamBase::WriteString(const FunctionCallbackInfo<Value>& args) { StreamWriteResult res = Write(&buf, 1, send_handle, req_wrap_obj); res.bytes += synchronously_written; - SetWriteResultPropertiesOnWrapObject(env, req_wrap_obj, res); + SetWriteResult(res); if (res.wrap != nullptr) { res.wrap->SetAllocatedStorage(data.release(), data_size); } diff --git a/src/stream_base.h b/src/stream_base.h index 039009e072..063c8714fd 100644 --- a/src/stream_base.h +++ b/src/stream_base.h @@ -332,6 +332,8 @@ class StreamBase : public StreamResource { enum StreamBaseStateFields { kReadBytesOrError, kArrayBufferOffset, + kBytesWritten, + kLastWriteWasAsync, kNumStreamBaseStateFields }; @@ -339,6 +341,8 @@ class StreamBase : public StreamResource { Environment* env_; EmitToJSStreamListener default_listener_; + void SetWriteResult(const StreamWriteResult& res); + friend class WriteWrap; friend class ShutdownWrap; friend class Environment; // For kNumStreamBaseStateFields. diff --git a/src/stream_wrap.cc b/src/stream_wrap.cc index a3c45b940a..dac5ebdeb3 100644 --- a/src/stream_wrap.cc +++ b/src/stream_wrap.cc @@ -83,6 +83,8 @@ void LibuvStreamWrap::Initialize(Local<Object> target, NODE_DEFINE_CONSTANT(target, kReadBytesOrError); NODE_DEFINE_CONSTANT(target, kArrayBufferOffset); + NODE_DEFINE_CONSTANT(target, kBytesWritten); + NODE_DEFINE_CONSTANT(target, kLastWriteWasAsync); target->Set(context, FIXED_ONE_BYTE_STRING(env->isolate(), "streamBaseState"), env->stream_base_state().GetJSArray()).FromJust(); } |