Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[squash] review comments
  • Loading branch information
addaleax committed Feb 13, 2018
commit a9cdc4b2b9b43dd5e774d44e74300674a6c40ccc
2 changes: 1 addition & 1 deletion src/js_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void JSStream::New(const FunctionCallbackInfo<Value>& args) {
template <class Wrap>
void JSStream::Finish(const FunctionCallbackInfo<Value>& args) {
CHECK(args[0]->IsObject());
Wrap* w = static_cast<Wrap*>(Wrap::FromObject(args[0].As<Object>()));
Wrap* w = static_cast<Wrap*>(StreamReq::FromObject(args[0].As<Object>()));

w->Done(args[1]->Int32Value());
}
Expand Down
3 changes: 1 addition & 2 deletions src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1552,8 +1552,7 @@ void Http2Session::SendPendingData() {

chunks_sent_since_last_write_++;

StreamWriteResult res =
static_cast<StreamBase*>(stream_)->Write(*bufs, count);
StreamWriteResult res = underlying_stream()->Write(*bufs, count);
if (!res.async) {
ClearOutgoing(res.err);
}
Expand Down
4 changes: 4 additions & 0 deletions src/node_http2.h
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,10 @@ class Http2Session : public AsyncWrap, public StreamListener {

inline void EmitStatistics();

inline StreamBase* underlying_stream() {
return static_cast<StreamBase*>(stream_);
}

void Start();
void Stop();
void Close(uint32_t code = NGHTTP2_NO_ERROR,
Expand Down
10 changes: 5 additions & 5 deletions src/stream_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) {
}
}

std::unique_ptr<char, Free> storage;
std::unique_ptr<char[], Free> storage;
if (storage_size > 0)
storage = std::unique_ptr<char, Free>(Malloc(storage_size));
storage = std::unique_ptr<char[], Free>(Malloc(storage_size));

offset = 0;
if (!all_buffers) {
Expand Down Expand Up @@ -246,16 +246,16 @@ int StreamBase::WriteString(const FunctionCallbackInfo<Value>& args) {
CHECK_EQ(count, 1);
}

std::unique_ptr<char, Free> data;
std::unique_ptr<char[], Free> data;

if (try_write) {
// Copy partial data
data = std::unique_ptr<char, Free>(Malloc(buf.len));
data = std::unique_ptr<char[], Free>(Malloc(buf.len));
memcpy(data.get(), buf.base, buf.len);
data_size = buf.len;
} else {
// Write it
data = std::unique_ptr<char, Free>(Malloc(storage_size));
data = std::unique_ptr<char[], Free>(Malloc(storage_size));
data_size = StringBytes::Write(env->isolate(),
data.get(),
storage_size,
Expand Down
6 changes: 3 additions & 3 deletions src/stream_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ class StreamBase : public StreamResource {
void AfterShutdown(ShutdownWrap* req, int status);
void AfterWrite(WriteWrap* req, int status);

template<typename Wrap, typename EmitEvent>
template <typename Wrap, typename EmitEvent>
void AfterRequest(Wrap* req_wrap, EmitEvent emit);

friend class WriteWrap;
Expand All @@ -322,7 +322,7 @@ class StreamBase : public StreamResource {
// `OtherBase` must have a constructor that matches the `AsyncWrap`
// constructors’s (Environment*, Local<Object>, AsyncWrap::Provider) signature
// and be a subclass of `AsyncWrap`.
template<typename OtherBase, bool kResetPersistentOnDestroy = true>
template <typename OtherBase, bool kResetPersistentOnDestroy = true>
class SimpleShutdownWrap : public ShutdownWrap, public OtherBase {
public:
SimpleShutdownWrap(StreamBase* stream,
Expand All @@ -333,7 +333,7 @@ class SimpleShutdownWrap : public ShutdownWrap, public OtherBase {
size_t self_size() const override { return sizeof(*this); }
};

template<typename OtherBase, bool kResetPersistentOnDestroy = true>
template <typename OtherBase, bool kResetPersistentOnDestroy = true>
class SimpleWriteWrap : public WriteWrap, public OtherBase {
public:
SimpleWriteWrap(StreamBase* stream,
Expand Down
14 changes: 7 additions & 7 deletions src/tls_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ void TLSWrap::EncOut() {
for (size_t i = 0; i < count; i++)
buf[i] = uv_buf_init(data[i], size[i]);

StreamWriteResult res = static_cast<StreamBase*>(stream_)->Write(bufs, count);
StreamWriteResult res = underlying_stream()->Write(bufs, count);
if (res.err != 0) {
InvokeQueued(res.err);
return;
Expand Down Expand Up @@ -505,24 +505,24 @@ AsyncWrap* TLSWrap::GetAsyncWrap() {


bool TLSWrap::IsIPCPipe() {
return static_cast<StreamBase*>(stream_)->IsIPCPipe();
return underlying_stream()->IsIPCPipe();
}


int TLSWrap::GetFD() {
return static_cast<StreamBase*>(stream_)->GetFD();
return underlying_stream()->GetFD();
}


bool TLSWrap::IsAlive() {
return ssl_ != nullptr &&
stream_ != nullptr &&
static_cast<StreamBase*>(stream_)->IsAlive();
underlying_stream()->IsAlive();
}


bool TLSWrap::IsClosing() {
return static_cast<StreamBase*>(stream_)->IsClosing();
return underlying_stream()->IsClosing();
}


Expand Down Expand Up @@ -582,7 +582,7 @@ int TLSWrap::DoWrite(WriteWrap* w,
Local<Object> req_wrap_obj =
w->GetAsyncWrap()->persistent().Get(env()->isolate());
w->Dispose();
w = static_cast<StreamBase*>(stream_)->CreateWriteWrap(req_wrap_obj);
w = underlying_stream()->CreateWriteWrap(req_wrap_obj);
return stream_->DoWrite(w, bufs, count, send_handle);
}
}
Expand Down Expand Up @@ -680,7 +680,7 @@ void TLSWrap::OnStreamRead(ssize_t nread, const uv_buf_t& buf) {


ShutdownWrap* TLSWrap::CreateShutdownWrap(Local<Object> req_wrap_object) {
return static_cast<StreamBase*>(stream_)->CreateShutdownWrap(req_wrap_object);
return underlying_stream()->CreateShutdownWrap(req_wrap_object);
}


Expand Down
4 changes: 4 additions & 0 deletions src/tls_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ class TLSWrap : public AsyncWrap,
size_t self_size() const override { return sizeof(*this); }

protected:
inline StreamBase* underlying_stream() {
return static_cast<StreamBase*>(stream_);
}

static const int kClearOutChunkSize = 16384;

// Maximum number of bytes for hello parser
Expand Down