diff --git a/lib/net.js b/lib/net.js index f8af082a85a1a4..2393539737910a 100644 --- a/lib/net.js +++ b/lib/net.js @@ -210,10 +210,6 @@ function initSocketHandle(self) { self._handle.owner = self; self._handle.onread = onread; self[async_id_symbol] = getNewAsyncId(self._handle); - - // If handle doesn't support writev - neither do we - if (!self._handle.writev) - self._writev = null; } } diff --git a/src/js_stream.cc b/src/js_stream.cc index e562a62f3d1bb2..902aff7abee43e 100644 --- a/src/js_stream.cc +++ b/src/js_stream.cc @@ -208,7 +208,7 @@ void JSStream::Initialize(Local target, env->SetProtoMethod(t, "readBuffer", ReadBuffer); env->SetProtoMethod(t, "emitEOF", EmitEOF); - StreamBase::AddMethods(env, t, StreamBase::kFlagHasWritev); + StreamBase::AddMethods(env, t); target->Set(jsStreamString, t->GetFunction()); } diff --git a/src/node_file.cc b/src/node_file.cc index ed1799da586e24..f08833b201b19d 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -1997,7 +1997,7 @@ void Initialize(Local target, Local handleString = FIXED_ONE_BYTE_STRING(env->isolate(), "FileHandle"); fd->SetClassName(handleString); - StreamBase::AddMethods(env, fd, StreamBase::kFlagNone); + StreamBase::AddMethods(env, fd); target->Set(context, handleString, fd->GetFunction()).FromJust(); env->set_fd_constructor_template(fdt); diff --git a/src/node_http2.cc b/src/node_http2.cc index 934dbea5f0fc14..e6aeb80a91add9 100644 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -2840,7 +2840,7 @@ void Initialize(Local target, env->SetProtoMethod(stream, "rstStream", Http2Stream::RstStream); env->SetProtoMethod(stream, "refreshState", Http2Stream::RefreshState); AsyncWrap::AddWrapMethods(env, stream); - StreamBase::AddMethods(env, stream, StreamBase::kFlagHasWritev); + StreamBase::AddMethods(env, stream); Local streamt = stream->InstanceTemplate(); streamt->SetInternalFieldCount(1); env->set_http2stream_constructor_template(streamt); diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index 52e3f2730ed125..e2cc114479d5a1 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -83,11 +83,7 @@ void PipeWrap::Initialize(Local target, env->SetProtoMethod(t, "ref", HandleWrap::Ref); env->SetProtoMethod(t, "hasRef", HandleWrap::HasRef); -#ifdef _WIN32 LibuvStreamWrap::AddMethods(env, t); -#else - LibuvStreamWrap::AddMethods(env, t, StreamBase::kFlagHasWritev); -#endif env->SetProtoMethod(t, "bind", Bind); env->SetProtoMethod(t, "listen", Listen); diff --git a/src/stream_base-inl.h b/src/stream_base-inl.h index 4509825a60d184..b53d3e5979c2a5 100644 --- a/src/stream_base-inl.h +++ b/src/stream_base-inl.h @@ -266,9 +266,7 @@ inline WriteWrap* StreamBase::CreateWriteWrap( } template -void StreamBase::AddMethods(Environment* env, - Local t, - int flags) { +void StreamBase::AddMethods(Environment* env, Local t) { HandleScope scope(env->isolate()); enum PropertyAttribute attributes = @@ -324,8 +322,7 @@ void StreamBase::AddMethods(Environment* env, env->SetProtoMethod(t, "readStart", JSMethod); env->SetProtoMethod(t, "readStop", JSMethod); env->SetProtoMethod(t, "shutdown", JSMethod); - if ((flags & kFlagHasWritev) != 0) - env->SetProtoMethod(t, "writev", JSMethod); + env->SetProtoMethod(t, "writev", JSMethod); env->SetProtoMethod(t, "writeBuffer", JSMethod); diff --git a/src/stream_base.h b/src/stream_base.h index b91cf7df6cf8c4..405780619856ba 100644 --- a/src/stream_base.h +++ b/src/stream_base.h @@ -255,15 +255,9 @@ class StreamResource { class StreamBase : public StreamResource { public: - enum Flags { - kFlagNone = 0x0, - kFlagHasWritev = 0x1 - }; - template static inline void AddMethods(Environment* env, - v8::Local target, - int flags = kFlagNone); + v8::Local target); virtual bool IsAlive() = 0; virtual bool IsClosing() = 0; diff --git a/src/stream_wrap.cc b/src/stream_wrap.cc index ddeb74d80970f0..2dea245fd1dddc 100644 --- a/src/stream_wrap.cc +++ b/src/stream_wrap.cc @@ -97,8 +97,7 @@ LibuvStreamWrap::LibuvStreamWrap(Environment* env, void LibuvStreamWrap::AddMethods(Environment* env, - v8::Local target, - int flags) { + v8::Local target) { Local get_write_queue_size = FunctionTemplate::New(env->isolate(), GetWriteQueueSize, @@ -110,7 +109,7 @@ void LibuvStreamWrap::AddMethods(Environment* env, Local(), static_cast(ReadOnly | DontDelete)); env->SetProtoMethod(target, "setBlocking", SetBlocking); - StreamBase::AddMethods(env, target, flags); + StreamBase::AddMethods(env, target); } diff --git a/src/stream_wrap.h b/src/stream_wrap.h index 7847ebe754614a..487a40b7ffc7f9 100644 --- a/src/stream_wrap.h +++ b/src/stream_wrap.h @@ -85,8 +85,7 @@ class LibuvStreamWrap : public HandleWrap, public StreamBase { AsyncWrap* GetAsyncWrap() override; static void AddMethods(Environment* env, - v8::Local target, - int flags = StreamBase::kFlagNone); + v8::Local target); protected: inline void set_fd(int fd) { diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index 28a970a22647ca..aa130d22e02689 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -93,7 +93,7 @@ void TCPWrap::Initialize(Local target, env->SetProtoMethod(t, "unref", HandleWrap::Unref); env->SetProtoMethod(t, "hasRef", HandleWrap::HasRef); - LibuvStreamWrap::AddMethods(env, t, StreamBase::kFlagHasWritev); + LibuvStreamWrap::AddMethods(env, t); env->SetProtoMethod(t, "open", Open); env->SetProtoMethod(t, "bind", Bind); diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc index 4c4360358c7a41..e731c0c130216b 100644 --- a/src/tls_wrap.cc +++ b/src/tls_wrap.cc @@ -895,7 +895,7 @@ void TLSWrap::Initialize(Local target, env->SetProtoMethod(t, "destroySSL", DestroySSL); env->SetProtoMethod(t, "enableCertCb", EnableCertCb); - StreamBase::AddMethods(env, t, StreamBase::kFlagHasWritev); + StreamBase::AddMethods(env, t); SSLWrap::AddMethods(env, t); env->SetProtoMethod(t, "getServername", GetServername); diff --git a/test/parallel/test-http2-pipe-named-pipe.js b/test/parallel/test-http2-pipe-named-pipe.js new file mode 100644 index 00000000000000..49fc142961d919 --- /dev/null +++ b/test/parallel/test-http2-pipe-named-pipe.js @@ -0,0 +1,52 @@ +'use strict'; + +const common = require('../common'); +if (!common.hasCrypto) + common.skip('missing crypto'); +const fixtures = require('../common/fixtures'); +const assert = require('assert'); +const http2 = require('http2'); +const fs = require('fs'); +const net = require('net'); +const path = require('path'); + +// HTTP/2 servers can listen on a named pipe. + +const tmpdir = require('../common/tmpdir'); +tmpdir.refresh(); +const loc = fixtures.path('url-tests.js'); +const fn = path.join(tmpdir.path, 'http2-url-tests.js'); + +const server = http2.createServer(); + +server.on('stream', common.mustCall((stream) => { + const dest = stream.pipe(fs.createWriteStream(fn)); + + dest.on('finish', () => { + assert.strictEqual(fs.readFileSync(loc).length, + fs.readFileSync(fn).length); + }); + stream.respond(); + stream.end(); +})); + +server.listen(common.PIPE, common.mustCall(() => { + const client = http2.connect('http://localhost', { + createConnection(url) { + return net.connect(server.address()); + } + }); + + const req = client.request({ ':method': 'POST' }); + req.on('response', common.mustCall()); + req.resume(); + + req.on('close', common.mustCall(() => { + server.close(); + client.close(); + })); + + const str = fs.createReadStream(loc); + str.on('end', common.mustCall()); + str.pipe(req); +}));