Skip to content

Commit 5f5d380

Browse files
jasnelladdaleax
authored andcommitted
src: rename http2 class and suppress compile warnings
Suppress compile warnings on Windows, rename class for consistent styling. Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: #32551 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 8f8bbc6 commit 5f5d380

File tree

2 files changed

+60
-51
lines changed

2 files changed

+60
-51
lines changed

src/node_http2.cc

+43-34
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ Http2Options::Http2Options(Environment* env, nghttp2_session_type type) {
210210
// Important: The maxSessionMemory option in javascript is expressed in
211211
// terms of MB increments (i.e. the value 1 == 1 MB)
212212
if (flags & (1 << IDX_OPTIONS_MAX_SESSION_MEMORY))
213-
SetMaxSessionMemory(buffer[IDX_OPTIONS_MAX_SESSION_MEMORY] * 1e6);
213+
SetMaxSessionMemory(buffer[IDX_OPTIONS_MAX_SESSION_MEMORY] * 1000000);
214214
}
215215

216216
void Http2Session::Http2Settings::Init() {
@@ -350,8 +350,8 @@ Http2Priority::Http2Priority(Environment* env,
350350
int32_t weight_ = weight->Int32Value(context).ToChecked();
351351
bool exclusive_ = exclusive->BooleanValue(env->isolate());
352352
Debug(env, DebugCategory::HTTP2STREAM,
353-
"Http2Priority: parent: %d, weight: %d, exclusive: %d\n",
354-
parent_, weight_, exclusive_);
353+
"Http2Priority: parent: %d, weight: %d, exclusive: %s\n",
354+
parent_, weight_, exclusive_ ? "yes" : "no");
355355
nghttp2_priority_spec_init(&spec, parent_, weight_, exclusive_ ? 1 : 0);
356356
}
357357

@@ -579,8 +579,10 @@ void Http2Stream::EmitStatistics() {
579579
} else {
580580
buffer[IDX_STREAM_STATS_TIMETOFIRSTBYTESENT] = 0;
581581
}
582-
buffer[IDX_STREAM_STATS_SENTBYTES] = entry->sent_bytes();
583-
buffer[IDX_STREAM_STATS_RECEIVEDBYTES] = entry->received_bytes();
582+
buffer[IDX_STREAM_STATS_SENTBYTES] =
583+
static_cast<double>(entry->sent_bytes());
584+
buffer[IDX_STREAM_STATS_RECEIVEDBYTES] =
585+
static_cast<double>(entry->received_bytes());
584586
Local<Object> obj;
585587
if (entry->ToObject().ToLocal(&obj)) entry->Notify(obj);
586588
});
@@ -603,10 +605,12 @@ void Http2Session::EmitStatistics() {
603605
buffer[IDX_SESSION_STATS_STREAMCOUNT] = entry->stream_count();
604606
buffer[IDX_SESSION_STATS_STREAMAVERAGEDURATION] =
605607
entry->stream_average_duration();
606-
buffer[IDX_SESSION_STATS_DATA_SENT] = entry->data_sent();
607-
buffer[IDX_SESSION_STATS_DATA_RECEIVED] = entry->data_received();
608+
buffer[IDX_SESSION_STATS_DATA_SENT] =
609+
static_cast<double>(entry->data_sent());
610+
buffer[IDX_SESSION_STATS_DATA_RECEIVED] =
611+
static_cast<double>(entry->data_received());
608612
buffer[IDX_SESSION_STATS_MAX_CONCURRENT_STREAMS] =
609-
entry->max_concurrent_streams();
613+
static_cast<double>(entry->max_concurrent_streams());
610614
Local<Object> obj;
611615
if (entry->ToObject().ToLocal(&obj)) entry->Notify(obj);
612616
});
@@ -1514,9 +1518,9 @@ void Http2Session::ClearOutgoing(int status) {
15141518
outgoing_storage_.clear();
15151519
outgoing_length_ = 0;
15161520

1517-
std::vector<nghttp2_stream_write> current_outgoing_buffers_;
1521+
std::vector<NgHttp2StreamWrite> current_outgoing_buffers_;
15181522
current_outgoing_buffers_.swap(outgoing_buffers_);
1519-
for (const nghttp2_stream_write& wr : current_outgoing_buffers_) {
1523+
for (const NgHttp2StreamWrite& wr : current_outgoing_buffers_) {
15201524
WriteWrap* wrap = wr.req_wrap;
15211525
if (wrap != nullptr) {
15221526
// TODO(addaleax): Pass `status` instead of 0, so that we actually error
@@ -1543,7 +1547,7 @@ void Http2Session::ClearOutgoing(int status) {
15431547
}
15441548
}
15451549

1546-
void Http2Session::PushOutgoingBuffer(nghttp2_stream_write&& write) {
1550+
void Http2Session::PushOutgoingBuffer(NgHttp2StreamWrite&& write) {
15471551
outgoing_length_ += write.buf.len;
15481552
outgoing_buffers_.emplace_back(std::move(write));
15491553
}
@@ -1560,7 +1564,7 @@ void Http2Session::CopyDataIntoOutgoing(const uint8_t* src, size_t src_length) {
15601564
// of the outgoing_buffers_ vector may invalidate the pointer.
15611565
// The correct base pointers will be set later, before writing to the
15621566
// underlying socket.
1563-
PushOutgoingBuffer(nghttp2_stream_write {
1567+
PushOutgoingBuffer(NgHttp2StreamWrite {
15641568
uv_buf_init(nullptr, src_length)
15651569
});
15661570
}
@@ -1623,7 +1627,7 @@ uint8_t Http2Session::SendPendingData() {
16231627
// (Those are marked by having .base == nullptr.)
16241628
size_t offset = 0;
16251629
size_t i = 0;
1626-
for (const nghttp2_stream_write& write : outgoing_buffers_) {
1630+
for (const NgHttp2StreamWrite& write : outgoing_buffers_) {
16271631
statistics_.data_sent += write.buf.len;
16281632
if (write.buf.base == nullptr) {
16291633
bufs[i++] = uv_buf_init(
@@ -1679,7 +1683,7 @@ int Http2Session::OnSendData(
16791683
// we told it so, which means that we *should* have data available.
16801684
CHECK(!stream->queue_.empty());
16811685

1682-
nghttp2_stream_write& write = stream->queue_.front();
1686+
NgHttp2StreamWrite& write = stream->queue_.front();
16831687
if (write.buf.len <= length) {
16841688
// This write does not suffice by itself, so we can consume it completely.
16851689
length -= write.buf.len;
@@ -1689,7 +1693,7 @@ int Http2Session::OnSendData(
16891693
}
16901694

16911695
// Slice off `length` bytes of the first write in the queue.
1692-
session->PushOutgoingBuffer(nghttp2_stream_write {
1696+
session->PushOutgoingBuffer(NgHttp2StreamWrite {
16931697
uv_buf_init(write.buf.base, length)
16941698
});
16951699
write.buf.base += length;
@@ -1699,7 +1703,7 @@ int Http2Session::OnSendData(
16991703

17001704
if (frame->data.padlen > 0) {
17011705
// Send padding if that was requested.
1702-
session->PushOutgoingBuffer(nghttp2_stream_write {
1706+
session->PushOutgoingBuffer(NgHttp2StreamWrite {
17031707
uv_buf_init(const_cast<char*>(zero_bytes_256), frame->data.padlen - 1)
17041708
});
17051709
}
@@ -1780,7 +1784,7 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) {
17801784

17811785
// Remember the current buffer, so that OnDataChunkReceived knows the
17821786
// offset of a DATA frame's data into the socket read buffer.
1783-
stream_buf_ = uv_buf_init(buf.data(), nread);
1787+
stream_buf_ = uv_buf_init(buf.data(), static_cast<unsigned int>(nread));
17841788

17851789
Isolate* isolate = env()->isolate();
17861790

@@ -1793,7 +1797,7 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) {
17931797

17941798
if (UNLIKELY(ret < 0)) {
17951799
Debug(this, "fatal error receiving data: %d", ret);
1796-
Local<Value> arg = Integer::New(isolate, ret);
1800+
Local<Value> arg = Integer::New(isolate, static_cast<int32_t>(ret));
17971801
MakeCallback(env()->http2session_on_error_function(), 1, &arg);
17981802
return;
17991803
}
@@ -1802,7 +1806,7 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) {
18021806
}
18031807

18041808
bool Http2Session::HasWritesOnSocketForStream(Http2Stream* stream) {
1805-
for (const nghttp2_stream_write& wr : outgoing_buffers_) {
1809+
for (const NgHttp2StreamWrite& wr : outgoing_buffers_) {
18061810
if (wr.req_wrap != nullptr && wr.req_wrap->stream() == stream)
18071811
return true;
18081812
}
@@ -1949,7 +1953,7 @@ void Http2Stream::Destroy() {
19491953
// here because it's possible for destroy to have been called while
19501954
// we still have queued outbound writes.
19511955
while (!queue_.empty()) {
1952-
nghttp2_stream_write& head = queue_.front();
1956+
NgHttp2StreamWrite& head = queue_.front();
19531957
if (head.req_wrap != nullptr)
19541958
head.req_wrap->Done(UV_ECANCELED);
19551959
queue_.pop();
@@ -2167,7 +2171,7 @@ int Http2Stream::DoWrite(WriteWrap* req_wrap,
21672171
for (size_t i = 0; i < nbufs; ++i) {
21682172
// Store the req_wrap on the last write info in the queue, so that it is
21692173
// only marked as finished once all buffers associated with it are finished.
2170-
queue_.emplace(nghttp2_stream_write {
2174+
queue_.emplace(NgHttp2StreamWrite {
21712175
i == nbufs - 1 ? req_wrap : nullptr,
21722176
bufs[i]
21732177
});
@@ -2403,19 +2407,19 @@ void Http2Session::RefreshState(const FunctionCallbackInfo<Value>& args) {
24032407
buffer[IDX_SESSION_STATE_REMOTE_WINDOW_SIZE] =
24042408
nghttp2_session_get_remote_window_size(s);
24052409
buffer[IDX_SESSION_STATE_OUTBOUND_QUEUE_SIZE] =
2406-
nghttp2_session_get_outbound_queue_size(s);
2410+
static_cast<double>(nghttp2_session_get_outbound_queue_size(s));
24072411
buffer[IDX_SESSION_STATE_HD_DEFLATE_DYNAMIC_TABLE_SIZE] =
2408-
nghttp2_session_get_hd_deflate_dynamic_table_size(s);
2412+
static_cast<double>(nghttp2_session_get_hd_deflate_dynamic_table_size(s));
24092413
buffer[IDX_SESSION_STATE_HD_INFLATE_DYNAMIC_TABLE_SIZE] =
2410-
nghttp2_session_get_hd_inflate_dynamic_table_size(s);
2414+
static_cast<double>(nghttp2_session_get_hd_inflate_dynamic_table_size(s));
24112415
}
24122416

24132417

24142418
// Constructor for new Http2Session instances.
24152419
void Http2Session::New(const FunctionCallbackInfo<Value>& args) {
24162420
Environment* env = Environment::GetCurrent(args);
24172421
CHECK(args.IsConstructCall());
2418-
int val = args[0]->IntegerValue(env->context()).ToChecked();
2422+
int32_t val = args[0]->Int32Value(env->context()).ToChecked();
24192423
nghttp2_session_type type = static_cast<nghttp2_session_type>(val);
24202424
Http2Session* session = new Http2Session(env, args.This(), type);
24212425
session->get_async_id(); // avoid compiler warning
@@ -2453,7 +2457,7 @@ void Http2Session::Request(const FunctionCallbackInfo<Value>& args) {
24532457
Environment* env = session->env();
24542458

24552459
Local<Array> headers = args[0].As<Array>();
2456-
int options = args[1]->IntegerValue(env->context()).ToChecked();
2460+
int32_t options = args[1]->Int32Value(env->context()).ToChecked();
24572461
Http2Priority priority(env, args[2], args[3], args[4]);
24582462

24592463
Debug(session, "request submitted");
@@ -2464,7 +2468,7 @@ void Http2Session::Request(const FunctionCallbackInfo<Value>& args) {
24642468
*priority,
24652469
Http2Headers(env, headers),
24662470
&ret,
2467-
options);
2471+
static_cast<int>(options));
24682472

24692473
if (ret <= 0 || stream == nullptr) {
24702474
Debug(session, "could not submit request: %s", nghttp2_strerror(ret));
@@ -2553,10 +2557,12 @@ void Http2Stream::Respond(const FunctionCallbackInfo<Value>& args) {
25532557
ASSIGN_OR_RETURN_UNWRAP(&stream, args.Holder());
25542558

25552559
Local<Array> headers = args[0].As<Array>();
2556-
int options = args[1]->IntegerValue(env->context()).ToChecked();
2560+
int32_t options = args[1]->Int32Value(env->context()).ToChecked();
25572561

25582562
args.GetReturnValue().Set(
2559-
stream->SubmitResponse(Http2Headers(env, headers), options));
2563+
stream->SubmitResponse(
2564+
Http2Headers(env, headers),
2565+
static_cast<int>(options)));
25602566
Debug(stream, "response submitted");
25612567
}
25622568

@@ -2606,13 +2612,16 @@ void Http2Stream::PushPromise(const FunctionCallbackInfo<Value>& args) {
26062612
ASSIGN_OR_RETURN_UNWRAP(&parent, args.Holder());
26072613

26082614
Local<Array> headers = args[0].As<Array>();
2609-
int options = args[1]->IntegerValue(env->context()).ToChecked();
2615+
int32_t options = args[1]->Int32Value(env->context()).ToChecked();
26102616

26112617
Debug(parent, "creating push promise");
26122618

26132619
int32_t ret = 0;
26142620
Http2Stream* stream =
2615-
parent->SubmitPushPromise(Http2Headers(env, headers), &ret, options);
2621+
parent->SubmitPushPromise(
2622+
Http2Headers(env, headers),
2623+
&ret,
2624+
static_cast<int>(options));
26162625

26172626
if (ret <= 0 || stream == nullptr) {
26182627
Debug(parent, "failed to create push stream: %d", ret);
@@ -2726,13 +2735,13 @@ void Http2Session::Origin(const FunctionCallbackInfo<Value>& args) {
27262735
ASSIGN_OR_RETURN_UNWRAP(&session, args.Holder());
27272736

27282737
Local<String> origin_string = args[0].As<String>();
2729-
int count = args[1]->IntegerValue(context).ToChecked();
2738+
int32_t count = args[1]->Int32Value(context).ToChecked();
27302739

27312740

27322741
Origins origins(env->isolate(),
27332742
env->context(),
27342743
origin_string,
2735-
count);
2744+
static_cast<int>(count));
27362745

27372746
session->Origin(*origins, origins.length());
27382747
}
@@ -2886,7 +2895,7 @@ void Http2Session::Http2Ping::DetachFromSession() {
28862895
session_ = nullptr;
28872896
}
28882897

2889-
void nghttp2_stream_write::MemoryInfo(MemoryTracker* tracker) const {
2898+
void NgHttp2StreamWrite::MemoryInfo(MemoryTracker* tracker) const {
28902899
if (req_wrap != nullptr)
28912900
tracker->TrackField("req_wrap", req_wrap->GetAsyncWrap());
28922901
tracker->TrackField("buf", buf);

src/node_http2.h

+17-17
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ namespace http2 {
2424
// may send in order to prevent abuse. The current default cap is 10. The
2525
// user may set a different limit using a per Http2Session configuration
2626
// option.
27-
#define DEFAULT_MAX_PINGS 10
27+
constexpr size_t kDefaultMaxPings = 10;
2828

2929
// Also strictly limit the number of outstanding SETTINGS frames a user sends
30-
#define DEFAULT_MAX_SETTINGS 10
30+
constexpr size_t kDefaultMaxSettings = 10;
3131

3232
// Default maximum total memory cap for Http2Session.
33-
#define DEFAULT_MAX_SESSION_MEMORY 1e7
33+
constexpr uint64_t kDefaultMaxSessionMemory = 10000000;
3434

3535
// These are the standard HTTP/2 defaults as specified by the RFC
3636
#define DEFAULT_SETTINGS_HEADER_TABLE_SIZE 4096
@@ -123,17 +123,17 @@ enum nghttp2_stream_options {
123123
STREAM_OPTION_GET_TRAILERS = 0x2,
124124
};
125125

126-
struct nghttp2_stream_write : public MemoryRetainer {
126+
struct NgHttp2StreamWrite : public MemoryRetainer {
127127
WriteWrap* req_wrap = nullptr;
128128
uv_buf_t buf;
129129

130-
inline explicit nghttp2_stream_write(uv_buf_t buf_) : buf(buf_) {}
131-
inline nghttp2_stream_write(WriteWrap* req, uv_buf_t buf_) :
130+
inline explicit NgHttp2StreamWrite(uv_buf_t buf_) : buf(buf_) {}
131+
inline NgHttp2StreamWrite(WriteWrap* req, uv_buf_t buf_) :
132132
req_wrap(req), buf(buf_) {}
133133

134134
void MemoryInfo(MemoryTracker* tracker) const override;
135-
SET_MEMORY_INFO_NAME(nghttp2_stream_write)
136-
SET_SELF_SIZE(nghttp2_stream_write)
135+
SET_MEMORY_INFO_NAME(NgHttp2StreamWrite)
136+
SET_SELF_SIZE(NgHttp2StreamWrite)
137137
};
138138

139139
// The Padding Strategy determines the method by which extra padding is
@@ -239,11 +239,11 @@ class Http2Options {
239239

240240
private:
241241
Nghttp2OptionPointer options_;
242-
uint64_t max_session_memory_ = DEFAULT_MAX_SESSION_MEMORY;
242+
uint64_t max_session_memory_ = kDefaultMaxSessionMemory;
243243
uint32_t max_header_pairs_ = DEFAULT_MAX_HEADER_LIST_PAIRS;
244244
padding_strategy_type padding_strategy_ = PADDING_STRATEGY_NONE;
245-
size_t max_outstanding_pings_ = DEFAULT_MAX_PINGS;
246-
size_t max_outstanding_settings_ = DEFAULT_MAX_SETTINGS;
245+
size_t max_outstanding_pings_ = kDefaultMaxPings;
246+
size_t max_outstanding_settings_ = kDefaultMaxSettings;
247247
};
248248

249249
class Http2Priority {
@@ -473,7 +473,7 @@ class Http2Stream : public AsyncWrap,
473473

474474
// Outbound Data... This is the data written by the JS layer that is
475475
// waiting to be written out to the socket.
476-
std::queue<nghttp2_stream_write> queue_;
476+
std::queue<NgHttp2StreamWrite> queue_;
477477
size_t available_outbound_length_ = 0;
478478

479479
Http2StreamListener stream_listener_;
@@ -836,7 +836,7 @@ class Http2Session : public AsyncWrap,
836836
uint32_t max_header_pairs_ = DEFAULT_MAX_HEADER_LIST_PAIRS;
837837

838838
// The maximum amount of memory allocated for this session
839-
uint64_t max_session_memory_ = DEFAULT_MAX_SESSION_MEMORY;
839+
uint64_t max_session_memory_ = kDefaultMaxSessionMemory;
840840
uint64_t current_session_memory_ = 0;
841841
// The amount of memory allocated by nghttp2 internals
842842
uint64_t current_nghttp2_memory_ = 0;
@@ -859,13 +859,13 @@ class Http2Session : public AsyncWrap,
859859
AllocatedBuffer stream_buf_allocation_;
860860
size_t stream_buf_offset_ = 0;
861861

862-
size_t max_outstanding_pings_ = DEFAULT_MAX_PINGS;
862+
size_t max_outstanding_pings_ = kDefaultMaxPings;
863863
std::queue<BaseObjectPtr<Http2Ping>> outstanding_pings_;
864864

865-
size_t max_outstanding_settings_ = DEFAULT_MAX_SETTINGS;
865+
size_t max_outstanding_settings_ = kDefaultMaxSettings;
866866
std::queue<BaseObjectPtr<Http2Settings>> outstanding_settings_;
867867

868-
std::vector<nghttp2_stream_write> outgoing_buffers_;
868+
std::vector<NgHttp2StreamWrite> outgoing_buffers_;
869869
std::vector<uint8_t> outgoing_storage_;
870870
size_t outgoing_length_ = 0;
871871
std::vector<int32_t> pending_rst_streams_;
@@ -877,7 +877,7 @@ class Http2Session : public AsyncWrap,
877877
// Also use the invalid frame count as a measure for rejecting input frames.
878878
uint32_t invalid_frame_count_ = 0;
879879

880-
void PushOutgoingBuffer(nghttp2_stream_write&& write);
880+
void PushOutgoingBuffer(NgHttp2StreamWrite&& write);
881881
void CopyDataIntoOutgoing(const uint8_t* src, size_t src_length);
882882
void ClearOutgoing(int status);
883883

0 commit comments

Comments
 (0)