Files
node/src/stream_pipe.h
Anna Henningsen 84e02b178a src: allocate Buffer memory using ArrayBuffer allocator
Always use the right allocator for memory that is turned into
an `ArrayBuffer` at a later point.

This enables embedders to use their own `ArrayBuffer::Allocator`s,
and is inspired by Electron’s electron/node@f61bae3440. It should
render their downstream patch unnecessary.

Refs: f61bae3440

PR-URL: https://github.com/nodejs/node/pull/26207
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2019-02-25 02:01:11 +01:00

72 lines
2.0 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#ifndef SRC_STREAM_PIPE_H_
#define SRC_STREAM_PIPE_H_
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#include "stream_base.h"
namespace node {
class StreamPipe : public AsyncWrap {
public:
StreamPipe(StreamBase* source, StreamBase* sink, v8::Local<v8::Object> obj);
~StreamPipe() override;
void Unpipe();
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Start(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Unpipe(const v8::FunctionCallbackInfo<v8::Value>& args);
SET_NO_MEMORY_INFO()
SET_MEMORY_INFO_NAME(StreamPipe)
SET_SELF_SIZE(StreamPipe)
private:
inline StreamBase* source();
inline StreamBase* sink();
inline void ShutdownWritable();
bool is_reading_ = false;
bool is_writing_ = false;
bool is_eof_ = false;
bool is_closed_ = true;
bool sink_destroyed_ = false;
bool source_destroyed_ = false;
// Set a default value so that when were coming from Start(), we know
// that we dont want to read just yet.
// This will likely need to be changed when supporting streams without
// `OnStreamWantsWrite()` support.
size_t wanted_data_ = 0;
void ProcessData(size_t nread, AllocatedBuffer&& buf);
class ReadableListener : public StreamListener {
public:
uv_buf_t OnStreamAlloc(size_t suggested_size) override;
void OnStreamRead(ssize_t nread, const uv_buf_t& buf) override;
void OnStreamDestroy() override;
};
class WritableListener : public StreamListener {
public:
uv_buf_t OnStreamAlloc(size_t suggested_size) override;
void OnStreamRead(ssize_t nread, const uv_buf_t& buf) override;
void OnStreamAfterWrite(WriteWrap* w, int status) override;
void OnStreamAfterShutdown(ShutdownWrap* w, int status) override;
void OnStreamWantsWrite(size_t suggested_size) override;
void OnStreamDestroy() override;
};
ReadableListener readable_listener_;
WritableListener writable_listener_;
};
} // namespace node
#endif
#endif // SRC_STREAM_PIPE_H_