Skip to content

Commit 2b47fd2

Browse files
indutnyrvagg
authored andcommitted
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: #995 PR-URL: #1008 Reviewed-by: Bert Belder <[email protected]> Reviewed-By: Rod Vagg <[email protected]>
1 parent c915154 commit 2b47fd2

File tree

6 files changed

+19
-8
lines changed

6 files changed

+19
-8
lines changed

src/js_stream.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ void JSStream::Initialize(Handle<Object> target,
210210
env->SetProtoMethod(t, "readBuffer", ReadBuffer);
211211
env->SetProtoMethod(t, "emitEOF", EmitEOF);
212212

213-
StreamBase::AddMethods<JSStream>(env, t);
213+
StreamBase::AddMethods<JSStream>(env, t, StreamBase::kFlagHasWritev);
214214
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "JSStream"),
215215
t->GetFunction());
216216
env->set_jsstream_constructor_template(t);

src/stream_base-inl.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ using v8::String;
2121
using v8::Value;
2222

2323
template <class Base>
24-
void StreamBase::AddMethods(Environment* env, Handle<FunctionTemplate> t) {
24+
void StreamBase::AddMethods(Environment* env,
25+
Handle<FunctionTemplate> t,
26+
int flags) {
2527
HandleScope scope(env->isolate());
2628

2729
enum PropertyAttribute attributes =
@@ -36,7 +38,8 @@ void StreamBase::AddMethods(Environment* env, Handle<FunctionTemplate> t) {
3638
env->SetProtoMethod(t, "readStart", JSMethod<Base, &StreamBase::ReadStart>);
3739
env->SetProtoMethod(t, "readStop", JSMethod<Base, &StreamBase::ReadStop>);
3840
env->SetProtoMethod(t, "shutdown", JSMethod<Base, &StreamBase::Shutdown>);
39-
env->SetProtoMethod(t, "writev", JSMethod<Base, &StreamBase::Writev>);
41+
if ((flags & kFlagHasWritev) != 0)
42+
env->SetProtoMethod(t, "writev", JSMethod<Base, &StreamBase::Writev>);
4043
env->SetProtoMethod(t,
4144
"writeBuffer",
4245
JSMethod<Base, &StreamBase::WriteBuffer>);

src/stream_base.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,15 @@ class StreamResource {
158158

159159
class StreamBase : public StreamResource {
160160
public:
161+
enum Flags {
162+
kFlagNone = 0x0,
163+
kFlagHasWritev = 0x1
164+
};
165+
161166
template <class Base>
162167
static inline void AddMethods(Environment* env,
163-
v8::Handle<v8::FunctionTemplate> target);
168+
v8::Handle<v8::FunctionTemplate> target,
169+
int flags = kFlagNone);
164170

165171
virtual void* Cast() = 0;
166172
virtual bool IsAlive() = 0;

src/stream_wrap.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ StreamWrap::StreamWrap(Environment* env,
8181

8282

8383
void StreamWrap::AddMethods(Environment* env,
84-
v8::Handle<v8::FunctionTemplate> target) {
84+
v8::Handle<v8::FunctionTemplate> target,
85+
int flags) {
8586
env->SetProtoMethod(target, "setBlocking", SetBlocking);
86-
StreamBase::AddMethods<StreamWrap>(env, target);
87+
StreamBase::AddMethods<StreamWrap>(env, target, flags);
8788
}
8889

8990

src/stream_wrap.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ class StreamWrap : public HandleWrap, public StreamBase {
6868
void UpdateWriteQueueSize();
6969

7070
static void AddMethods(Environment* env,
71-
v8::Handle<v8::FunctionTemplate> target);
71+
v8::Handle<v8::FunctionTemplate> target,
72+
int flags = StreamBase::kFlagNone);
7273

7374
private:
7475
static void SetBlocking(const v8::FunctionCallbackInfo<v8::Value>& args);

src/tcp_wrap.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ void TCPWrap::Initialize(Handle<Object> target,
8989
env->SetProtoMethod(t, "ref", HandleWrap::Ref);
9090
env->SetProtoMethod(t, "unref", HandleWrap::Unref);
9191

92-
StreamWrap::AddMethods(env, t);
92+
StreamWrap::AddMethods(env, t, StreamBase::kFlagHasWritev);
9393

9494
env->SetProtoMethod(t, "open", Open);
9595
env->SetProtoMethod(t, "bind", Bind);

0 commit comments

Comments
 (0)