Skip to content

Commit a9cdc4b

Browse files
committed
[squash] review comments
1 parent a852cc6 commit a9cdc4b

File tree

7 files changed

+25
-18
lines changed

7 files changed

+25
-18
lines changed

src/js_stream.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ void JSStream::New(const FunctionCallbackInfo<Value>& args) {
151151
template <class Wrap>
152152
void JSStream::Finish(const FunctionCallbackInfo<Value>& args) {
153153
CHECK(args[0]->IsObject());
154-
Wrap* w = static_cast<Wrap*>(Wrap::FromObject(args[0].As<Object>()));
154+
Wrap* w = static_cast<Wrap*>(StreamReq::FromObject(args[0].As<Object>()));
155155

156156
w->Done(args[1]->Int32Value());
157157
}

src/node_http2.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -1552,8 +1552,7 @@ void Http2Session::SendPendingData() {
15521552

15531553
chunks_sent_since_last_write_++;
15541554

1555-
StreamWriteResult res =
1556-
static_cast<StreamBase*>(stream_)->Write(*bufs, count);
1555+
StreamWriteResult res = underlying_stream()->Write(*bufs, count);
15571556
if (!res.async) {
15581557
ClearOutgoing(res.err);
15591558
}

src/node_http2.h

+4
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,10 @@ class Http2Session : public AsyncWrap, public StreamListener {
815815

816816
inline void EmitStatistics();
817817

818+
inline StreamBase* underlying_stream() {
819+
return static_cast<StreamBase*>(stream_);
820+
}
821+
818822
void Start();
819823
void Stop();
820824
void Close(uint32_t code = NGHTTP2_NO_ERROR,

src/stream_base.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) {
112112
}
113113
}
114114

115-
std::unique_ptr<char, Free> storage;
115+
std::unique_ptr<char[], Free> storage;
116116
if (storage_size > 0)
117-
storage = std::unique_ptr<char, Free>(Malloc(storage_size));
117+
storage = std::unique_ptr<char[], Free>(Malloc(storage_size));
118118

119119
offset = 0;
120120
if (!all_buffers) {
@@ -246,16 +246,16 @@ int StreamBase::WriteString(const FunctionCallbackInfo<Value>& args) {
246246
CHECK_EQ(count, 1);
247247
}
248248

249-
std::unique_ptr<char, Free> data;
249+
std::unique_ptr<char[], Free> data;
250250

251251
if (try_write) {
252252
// Copy partial data
253-
data = std::unique_ptr<char, Free>(Malloc(buf.len));
253+
data = std::unique_ptr<char[], Free>(Malloc(buf.len));
254254
memcpy(data.get(), buf.base, buf.len);
255255
data_size = buf.len;
256256
} else {
257257
// Write it
258-
data = std::unique_ptr<char, Free>(Malloc(storage_size));
258+
data = std::unique_ptr<char[], Free>(Malloc(storage_size));
259259
data_size = StringBytes::Write(env->isolate(),
260260
data.get(),
261261
storage_size,

src/stream_base.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ class StreamBase : public StreamResource {
310310
void AfterShutdown(ShutdownWrap* req, int status);
311311
void AfterWrite(WriteWrap* req, int status);
312312

313-
template<typename Wrap, typename EmitEvent>
313+
template <typename Wrap, typename EmitEvent>
314314
void AfterRequest(Wrap* req_wrap, EmitEvent emit);
315315

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

336-
template<typename OtherBase, bool kResetPersistentOnDestroy = true>
336+
template <typename OtherBase, bool kResetPersistentOnDestroy = true>
337337
class SimpleWriteWrap : public WriteWrap, public OtherBase {
338338
public:
339339
SimpleWriteWrap(StreamBase* stream,

src/tls_wrap.cc

+7-7
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ void TLSWrap::EncOut() {
285285
for (size_t i = 0; i < count; i++)
286286
buf[i] = uv_buf_init(data[i], size[i]);
287287

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

506506

507507
bool TLSWrap::IsIPCPipe() {
508-
return static_cast<StreamBase*>(stream_)->IsIPCPipe();
508+
return underlying_stream()->IsIPCPipe();
509509
}
510510

511511

512512
int TLSWrap::GetFD() {
513-
return static_cast<StreamBase*>(stream_)->GetFD();
513+
return underlying_stream()->GetFD();
514514
}
515515

516516

517517
bool TLSWrap::IsAlive() {
518518
return ssl_ != nullptr &&
519519
stream_ != nullptr &&
520-
static_cast<StreamBase*>(stream_)->IsAlive();
520+
underlying_stream()->IsAlive();
521521
}
522522

523523

524524
bool TLSWrap::IsClosing() {
525-
return static_cast<StreamBase*>(stream_)->IsClosing();
525+
return underlying_stream()->IsClosing();
526526
}
527527

528528

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

681681

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

686686

src/tls_wrap.h

+4
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ class TLSWrap : public AsyncWrap,
8080
size_t self_size() const override { return sizeof(*this); }
8181

8282
protected:
83+
inline StreamBase* underlying_stream() {
84+
return static_cast<StreamBase*>(stream_);
85+
}
86+
8387
static const int kClearOutChunkSize = 16384;
8488

8589
// Maximum number of bytes for hello parser

0 commit comments

Comments
 (0)