summaryrefslogtreecommitdiff
path: root/src/stream_base.cc
AgeCommit message (Collapse)Author
2016-09-20src: use MaybeStackBuffer on DoSend/WritevPaul Kiddie
instead of creating own buffer, use MaybeStackBuffer on DoSend to take advantage of its destructor to free up memory, so buffer never leaks memory - even if code in DoSend throws. Use MaybeStackBuffer in Writev to take advantage of destructor on MaybeStackBuffer to clear itself up, rather than Writev managing resources itself. PR-URL: https://github.com/nodejs/node/pull/8626 Reviewed-By: Anna Henningsen <anna@addaleax.net>
2016-08-27net: make holding the buffer in memory more robustAnna Henningsen
Set the `req.buffer` property, which serves as a way of keeping a `Buffer` alive that is being written to a stream, on the C++ side instead of the JS side. This closes a hole where buffers that were temporarily created in order to write strings with uncommon encodings (e.g. `hex`) were passed to the native side without being set as `req.buffer`. Fixes: https://github.com/nodejs/node/issues/8251 PR-URL: https://github.com/nodejs/node/pull/8252 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-06-07buffer: introduce latin1 encoding termTrevor Norris
When node began using the OneByte API (f150d56) it also switched to officially supporting ISO-8859-1. Though at the time no new encoding string was introduced. Introduce the new encoding string 'latin1' to be more explicit. The previous 'binary' and documented as an alias to 'latin1'. While many tests have switched to use 'latin1', there are still plenty that do both 'binary' and 'latin1' checks side-by-side to ensure there is no regression. PR-URL: https://github.com/nodejs/node/pull/7111 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
2016-05-24src: no abort from getter if object isn't wrappedTrevor Norris
v8::Object::GetAlignedPointerFromInternalField() returns a random value if Wrap() hasn't been run on the object handle. Causing v8 to abort if certain getters are accessed. It's possible to access these getters and functions during class construction through the AsyncWrap init() callback, and also possible in a subset of those scenarios while running the persistent handle visitor. Mitigate this issue by manually setting the internal aligned pointer field to nullptr in the BaseObject constructor and add necessary logic to return appropriate values when nullptr is encountered. PR-URL: https://github.com/nodejs/node/pull/6184 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net>
2016-04-05src: replace ARRAY_SIZE with typesafe arraysizeBen Noordhuis
To prevent `ARRAY_SIZE(&arg)` (i.e., taking the array size of a pointer) from happening again. PR-URL: https://github.com/nodejs/node/pull/5969 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2016-03-03src: replace usage of deprecated HasMichaël Zasso
PR-URL: https://github.com/nodejs/node/pull/5159 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-03-03src: replace usage of deprecated DeleteMichaël Zasso
PR-URL: https://github.com/nodejs/node/pull/5159 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-10-06http: fix out-of-order 'finish' bug in pipeliningFedor Indutny
Changes to `stream_base.cc` are required to support empty writes. Fixes CVE-2015-7384, https://github.com/nodejs/node/issues/3138 Fix: https://github.com/nodejs/node/issues/2639 PR-URL: https://github.com/nodejs/node/pull/3128
2015-09-06src: replace usage of v8::Handle with v8::LocalMichaël Zasso
v8::Handle is deprecated: https://codereview.chromium.org/1224623004 PR-URL: https://github.com/nodejs/io.js/pull/2202 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-08-20stream_base: various improvementsFedor Indutny
Expose and use in TLSWrap an `v8::External` wrap of the `StreamBase*` pointer instead of guessing the ancestor C++ class in `node_wrap.h`. Make use of `StreamBase::Callback` structure for storing/passing both callback and context in a single object. Introduce `GetObject()` for future user-land usage, when a child class is not going to be inherited from AsyncWrap. PR-URL: https://github.com/nodejs/node/pull/2351 Reviewed-By: Trevor Norris <trev.norris@gmail.com>
2015-05-01stream_base: dispatch reqs in the stream implFedor Indutny
Dispatch requests in the implementation of the stream, not in the code creating these requests. The requests might be piled up and invoked internally in the implementation, so it should know better when it is the time to dispatch them. In fact, TLS was doing exactly this thing which led us to... Fix: https://github.com/iojs/io.js/issues/1512 PR-URL: https://github.com/iojs/io.js/pull/1563 Reviewed-By: Shigeki Ohtsu <ohtsu@iij.ad.jp>
2015-03-07stream_base: WriteWrap::New/::DisposeFedor Indutny
Encapsulate allocation/disposal of `WriteWrap` instances into the `WriteWrap` class itself. PR-URL: https://github.com/iojs/io.js/pull/1090 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-03-03src: fix --without-ssl buildBen Noordhuis
Don't include tls_wrap.h in stream_base.cc. It's not used and it breaks the build when --without-ssl is passed to configure. Fixes the following build error: In file included from ../src/tls_wrap.h:5:0, from ../src/stream_base.cc:10: ../src/node_crypto.h:20:25: fatal error: openssl/ssl.h: No such file or directory #include <openssl/ssl.h> PR-URL: https://github.com/iojs/io.js/pull/1027 Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
2015-02-25stream_base: remove static JSMethod declarationsFedor Indutny
Move JS methods to the stream_base-inl.h and thus define them on each use of `StreamBase::AddMethods`. Inline `AddMethods` itself, so that there won't be any need in a static declaration in stream_base.cc. NOTE: This basically allows using this API in user-land, though, some polishing is required before releasing it. PR-URL: https://github.com/iojs/io.js/pull/957 Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
2015-02-24streams: introduce StreamWrap and JSStreamFedor Indutny
Introduce a way to wrap plain-js `stream.Duplex` streams into C++ StreamBase's child class. With such method at hand it is now possible to pass `stream.Duplex` instance as a `socket` parameter to `tls.connect()`. PR-URL: https://github.com/iojs/io.js/pull/926 Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
2015-02-22stream_base: introduce StreamBaseFedor Indutny
StreamBase is an improved way to write C++ streams. The class itself is for separting `StreamWrap` (with the methods like `.writeAsciiString`, `.writeBuffer`, `.writev`, etc) from the `HandleWrap` class, making possible to write abstract C++ streams that are not bound to any uv socket. The following methods are important part of the abstraction (which mimics libuv's stream API): * Events: * `OnAlloc(size_t size, uv_buf_t*)` * `OnRead(ssize_t nread, const uv_buf_t*, uv_handle_type pending)` * `OnAfterWrite(WriteWrap*)` * Wrappers: * `DoShutdown(ShutdownWrap*)` * `DoTryWrite(uv_buf_t** bufs, size_t* count)` * `DoWrite(WriteWrap*, uv_buf_t*, size_t count, uv_stream_t* handle)` * `Error()` * `ClearError()` The implementation should provide all of these methods, thus providing the access to the underlying resource (be it uv handle, TLS socket, or anything else). A C++ stream may consume the input of another stream by replacing the event callbacks and proxying the writes. This kind of API is actually used now for the TLSWrap implementation, making it possible to wrap TLS stream into another TLS stream. Thus legacy API calls are no longer required in `_tls_wrap.js`. PR-URL: https://github.com/iojs/io.js/pull/840 Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>