From 2b47fd2eb615511ee1f2f29d496cd817e54740e1 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Sun, 1 Mar 2015 00:46:43 +0300 Subject: [PATCH] stream_base: `.writev()` has limited support Only TCP and JSStream do support `.writev()` on all platforms at the moment. Ensure that it won't be enabled everywhere. Fix: https://github.com/iojs/io.js/issues/995 PR-URL: https://github.com/iojs/io.js/pull/1008 Reviewed-by: Bert Belder Reviewed-By: Rod Vagg --- src/js_stream.cc | 2 +- src/stream_base-inl.h | 7 +++++-- src/stream_base.h | 8 +++++++- src/stream_wrap.cc | 5 +++-- src/stream_wrap.h | 3 ++- src/tcp_wrap.cc | 2 +- 6 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/js_stream.cc b/src/js_stream.cc index 02f32510c87464..21f5ce07ac08b3 100644 --- a/src/js_stream.cc +++ b/src/js_stream.cc @@ -210,7 +210,7 @@ void JSStream::Initialize(Handle target, env->SetProtoMethod(t, "readBuffer", ReadBuffer); env->SetProtoMethod(t, "emitEOF", EmitEOF); - StreamBase::AddMethods(env, t); + StreamBase::AddMethods(env, t, StreamBase::kFlagHasWritev); target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "JSStream"), t->GetFunction()); env->set_jsstream_constructor_template(t); diff --git a/src/stream_base-inl.h b/src/stream_base-inl.h index 2167bdeb130b69..490909456b3624 100644 --- a/src/stream_base-inl.h +++ b/src/stream_base-inl.h @@ -21,7 +21,9 @@ using v8::String; using v8::Value; template -void StreamBase::AddMethods(Environment* env, Handle t) { +void StreamBase::AddMethods(Environment* env, + Handle t, + int flags) { HandleScope scope(env->isolate()); enum PropertyAttribute attributes = @@ -36,7 +38,8 @@ void StreamBase::AddMethods(Environment* env, Handle t) { env->SetProtoMethod(t, "readStart", JSMethod); env->SetProtoMethod(t, "readStop", JSMethod); env->SetProtoMethod(t, "shutdown", JSMethod); - env->SetProtoMethod(t, "writev", JSMethod); + if ((flags & kFlagHasWritev) != 0) + env->SetProtoMethod(t, "writev", JSMethod); env->SetProtoMethod(t, "writeBuffer", JSMethod); diff --git a/src/stream_base.h b/src/stream_base.h index 0864eb51cac1ed..dcbde09bacf25d 100644 --- a/src/stream_base.h +++ b/src/stream_base.h @@ -158,9 +158,15 @@ class StreamResource { class StreamBase : public StreamResource { public: + enum Flags { + kFlagNone = 0x0, + kFlagHasWritev = 0x1 + }; + template static inline void AddMethods(Environment* env, - v8::Handle target); + v8::Handle target, + int flags = kFlagNone); virtual void* Cast() = 0; virtual bool IsAlive() = 0; diff --git a/src/stream_wrap.cc b/src/stream_wrap.cc index 824a880ebd6341..8f6fcac85d76b1 100644 --- a/src/stream_wrap.cc +++ b/src/stream_wrap.cc @@ -81,9 +81,10 @@ StreamWrap::StreamWrap(Environment* env, void StreamWrap::AddMethods(Environment* env, - v8::Handle target) { + v8::Handle target, + int flags) { env->SetProtoMethod(target, "setBlocking", SetBlocking); - StreamBase::AddMethods(env, target); + StreamBase::AddMethods(env, target, flags); } diff --git a/src/stream_wrap.h b/src/stream_wrap.h index 99561e843ae11d..8e4cdf20be962e 100644 --- a/src/stream_wrap.h +++ b/src/stream_wrap.h @@ -68,7 +68,8 @@ class StreamWrap : public HandleWrap, public StreamBase { void UpdateWriteQueueSize(); static void AddMethods(Environment* env, - v8::Handle target); + v8::Handle target, + int flags = StreamBase::kFlagNone); private: static void SetBlocking(const v8::FunctionCallbackInfo& args); diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index a823e758ee100d..202053e837dc33 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -89,7 +89,7 @@ void TCPWrap::Initialize(Handle target, env->SetProtoMethod(t, "ref", HandleWrap::Ref); env->SetProtoMethod(t, "unref", HandleWrap::Unref); - StreamWrap::AddMethods(env, t); + StreamWrap::AddMethods(env, t, StreamBase::kFlagHasWritev); env->SetProtoMethod(t, "open", Open); env->SetProtoMethod(t, "bind", Bind);