Skip to content

Commit 8f766e8

Browse files
jasnelltargos
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 <[email protected]> PR-URL: #32551 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent afc6a25 commit 8f766e8

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
@@ -209,7 +209,7 @@ Http2Options::Http2Options(Environment* env, nghttp2_session_type type) {
209209
// Important: The maxSessionMemory option in javascript is expressed in
210210
// terms of MB increments (i.e. the value 1 == 1 MB)
211211
if (flags & (1 << IDX_OPTIONS_MAX_SESSION_MEMORY))
212-
SetMaxSessionMemory(buffer[IDX_OPTIONS_MAX_SESSION_MEMORY] * 1e6);
212+
SetMaxSessionMemory(buffer[IDX_OPTIONS_MAX_SESSION_MEMORY] * 1000000);
213213
}
214214

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

@@ -578,8 +578,10 @@ void Http2Stream::EmitStatistics() {
578578
} else {
579579
buffer[IDX_STREAM_STATS_TIMETOFIRSTBYTESENT] = 0;
580580
}
581-
buffer[IDX_STREAM_STATS_SENTBYTES] = entry->sent_bytes();
582-
buffer[IDX_STREAM_STATS_RECEIVEDBYTES] = entry->received_bytes();
581+
buffer[IDX_STREAM_STATS_SENTBYTES] =
582+
static_cast<double>(entry->sent_bytes());
583+
buffer[IDX_STREAM_STATS_RECEIVEDBYTES] =
584+
static_cast<double>(entry->received_bytes());
583585
Local<Object> obj;
584586
if (entry->ToObject().ToLocal(&obj)) entry->Notify(obj);
585587
});
@@ -602,10 +604,12 @@ void Http2Session::EmitStatistics() {
602604
buffer[IDX_SESSION_STATS_STREAMCOUNT] = entry->stream_count();
603605
buffer[IDX_SESSION_STATS_STREAMAVERAGEDURATION] =
604606
entry->stream_average_duration();
605-
buffer[IDX_SESSION_STATS_DATA_SENT] = entry->data_sent();
606-
buffer[IDX_SESSION_STATS_DATA_RECEIVED] = entry->data_received();
607+
buffer[IDX_SESSION_STATS_DATA_SENT] =
608+
static_cast<double>(entry->data_sent());
609+
buffer[IDX_SESSION_STATS_DATA_RECEIVED] =
610+
static_cast<double>(entry->data_received());
607611
buffer[IDX_SESSION_STATS_MAX_CONCURRENT_STREAMS] =
608-
entry->max_concurrent_streams();
612+
static_cast<double>(entry->max_concurrent_streams());
609613
Local<Object> obj;
610614
if (entry->ToObject().ToLocal(&obj)) entry->Notify(obj);
611615
});
@@ -1513,9 +1517,9 @@ void Http2Session::ClearOutgoing(int status) {
15131517
outgoing_storage_.clear();
15141518
outgoing_length_ = 0;
15151519

1516-
std::vector<nghttp2_stream_write> current_outgoing_buffers_;
1520+
std::vector<NgHttp2StreamWrite> current_outgoing_buffers_;
15171521
current_outgoing_buffers_.swap(outgoing_buffers_);
1518-
for (const nghttp2_stream_write& wr : current_outgoing_buffers_) {
1522+
for (const NgHttp2StreamWrite& wr : current_outgoing_buffers_) {
15191523
WriteWrap* wrap = wr.req_wrap;
15201524
if (wrap != nullptr) {
15211525
// TODO(addaleax): Pass `status` instead of 0, so that we actually error
@@ -1542,7 +1546,7 @@ void Http2Session::ClearOutgoing(int status) {
15421546
}
15431547
}
15441548

1545-
void Http2Session::PushOutgoingBuffer(nghttp2_stream_write&& write) {
1549+
void Http2Session::PushOutgoingBuffer(NgHttp2StreamWrite&& write) {
15461550
outgoing_length_ += write.buf.len;
15471551
outgoing_buffers_.emplace_back(std::move(write));
15481552
}
@@ -1559,7 +1563,7 @@ void Http2Session::CopyDataIntoOutgoing(const uint8_t* src, size_t src_length) {
15591563
// of the outgoing_buffers_ vector may invalidate the pointer.
15601564
// The correct base pointers will be set later, before writing to the
15611565
// underlying socket.
1562-
PushOutgoingBuffer(nghttp2_stream_write {
1566+
PushOutgoingBuffer(NgHttp2StreamWrite {
15631567
uv_buf_init(nullptr, src_length)
15641568
});
15651569
}
@@ -1622,7 +1626,7 @@ uint8_t Http2Session::SendPendingData() {
16221626
// (Those are marked by having .base == nullptr.)
16231627
size_t offset = 0;
16241628
size_t i = 0;
1625-
for (const nghttp2_stream_write& write : outgoing_buffers_) {
1629+
for (const NgHttp2StreamWrite& write : outgoing_buffers_) {
16261630
statistics_.data_sent += write.buf.len;
16271631
if (write.buf.base == nullptr) {
16281632
bufs[i++] = uv_buf_init(
@@ -1678,7 +1682,7 @@ int Http2Session::OnSendData(
16781682
// we told it so, which means that we *should* have data available.
16791683
CHECK(!stream->queue_.empty());
16801684

1681-
nghttp2_stream_write& write = stream->queue_.front();
1685+
NgHttp2StreamWrite& write = stream->queue_.front();
16821686
if (write.buf.len <= length) {
16831687
// This write does not suffice by itself, so we can consume it completely.
16841688
length -= write.buf.len;
@@ -1688,7 +1692,7 @@ int Http2Session::OnSendData(
16881692
}
16891693

16901694
// Slice off `length` bytes of the first write in the queue.
1691-
session->PushOutgoingBuffer(nghttp2_stream_write {
1695+
session->PushOutgoingBuffer(NgHttp2StreamWrite {
16921696
uv_buf_init(write.buf.base, length)
16931697
});
16941698
write.buf.base += length;
@@ -1698,7 +1702,7 @@ int Http2Session::OnSendData(
16981702

16991703
if (frame->data.padlen > 0) {
17001704
// Send padding if that was requested.
1701-
session->PushOutgoingBuffer(nghttp2_stream_write {
1705+
session->PushOutgoingBuffer(NgHttp2StreamWrite {
17021706
uv_buf_init(const_cast<char*>(zero_bytes_256), frame->data.padlen - 1)
17031707
});
17041708
}
@@ -1779,7 +1783,7 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) {
17791783

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

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

@@ -1792,7 +1796,7 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) {
17921796

17931797
if (UNLIKELY(ret < 0)) {
17941798
Debug(this, "fatal error receiving data: %d", ret);
1795-
Local<Value> arg = Integer::New(isolate, ret);
1799+
Local<Value> arg = Integer::New(isolate, static_cast<int32_t>(ret));
17961800
MakeCallback(env()->http2session_on_error_function(), 1, &arg);
17971801
return;
17981802
}
@@ -1801,7 +1805,7 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) {
18011805
}
18021806

18031807
bool Http2Session::HasWritesOnSocketForStream(Http2Stream* stream) {
1804-
for (const nghttp2_stream_write& wr : outgoing_buffers_) {
1808+
for (const NgHttp2StreamWrite& wr : outgoing_buffers_) {
18051809
if (wr.req_wrap != nullptr && wr.req_wrap->stream() == stream)
18061810
return true;
18071811
}
@@ -1948,7 +1952,7 @@ void Http2Stream::Destroy() {
19481952
// here because it's possible for destroy to have been called while
19491953
// we still have queued outbound writes.
19501954
while (!queue_.empty()) {
1951-
nghttp2_stream_write& head = queue_.front();
1955+
NgHttp2StreamWrite& head = queue_.front();
19521956
if (head.req_wrap != nullptr)
19531957
head.req_wrap->Done(UV_ECANCELED);
19541958
queue_.pop();
@@ -2166,7 +2170,7 @@ int Http2Stream::DoWrite(WriteWrap* req_wrap,
21662170
for (size_t i = 0; i < nbufs; ++i) {
21672171
// Store the req_wrap on the last write info in the queue, so that it is
21682172
// only marked as finished once all buffers associated with it are finished.
2169-
queue_.emplace(nghttp2_stream_write {
2173+
queue_.emplace(NgHttp2StreamWrite {
21702174
i == nbufs - 1 ? req_wrap : nullptr,
21712175
bufs[i]
21722176
});
@@ -2402,19 +2406,19 @@ void Http2Session::RefreshState(const FunctionCallbackInfo<Value>& args) {
24022406
buffer[IDX_SESSION_STATE_REMOTE_WINDOW_SIZE] =
24032407
nghttp2_session_get_remote_window_size(s);
24042408
buffer[IDX_SESSION_STATE_OUTBOUND_QUEUE_SIZE] =
2405-
nghttp2_session_get_outbound_queue_size(s);
2409+
static_cast<double>(nghttp2_session_get_outbound_queue_size(s));
24062410
buffer[IDX_SESSION_STATE_HD_DEFLATE_DYNAMIC_TABLE_SIZE] =
2407-
nghttp2_session_get_hd_deflate_dynamic_table_size(s);
2411+
static_cast<double>(nghttp2_session_get_hd_deflate_dynamic_table_size(s));
24082412
buffer[IDX_SESSION_STATE_HD_INFLATE_DYNAMIC_TABLE_SIZE] =
2409-
nghttp2_session_get_hd_inflate_dynamic_table_size(s);
2413+
static_cast<double>(nghttp2_session_get_hd_inflate_dynamic_table_size(s));
24102414
}
24112415

24122416

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

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

24582462
Debug(session, "request submitted");
@@ -2463,7 +2467,7 @@ void Http2Session::Request(const FunctionCallbackInfo<Value>& args) {
24632467
*priority,
24642468
Http2Headers(env, headers),
24652469
&ret,
2466-
options);
2470+
static_cast<int>(options));
24672471

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

25542558
Local<Array> headers = args[0].As<Array>();
2555-
int options = args[1]->IntegerValue(env->context()).ToChecked();
2559+
int32_t options = args[1]->Int32Value(env->context()).ToChecked();
25562560

25572561
args.GetReturnValue().Set(
2558-
stream->SubmitResponse(Http2Headers(env, headers), options));
2562+
stream->SubmitResponse(
2563+
Http2Headers(env, headers),
2564+
static_cast<int>(options)));
25592565
Debug(stream, "response submitted");
25602566
}
25612567

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

26072613
Local<Array> headers = args[0].As<Array>();
2608-
int options = args[1]->IntegerValue(env->context()).ToChecked();
2614+
int32_t options = args[1]->Int32Value(env->context()).ToChecked();
26092615

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

26122618
int32_t ret = 0;
26132619
Http2Stream* stream =
2614-
parent->SubmitPushPromise(Http2Headers(env, headers), &ret, options);
2620+
parent->SubmitPushPromise(
2621+
Http2Headers(env, headers),
2622+
&ret,
2623+
static_cast<int>(options));
26152624

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

27272736
Local<String> origin_string = args[0].As<String>();
2728-
int count = args[1]->IntegerValue(context).ToChecked();
2737+
int32_t count = args[1]->Int32Value(context).ToChecked();
27292738

27302739

27312740
Origins origins(env->isolate(),
27322741
env->context(),
27332742
origin_string,
2734-
count);
2743+
static_cast<int>(count));
27352744

27362745
session->Origin(*origins, origins.length());
27372746
}
@@ -2885,7 +2894,7 @@ void Http2Session::Http2Ping::DetachFromSession() {
28852894
session_ = nullptr;
28862895
}
28872896

2888-
void nghttp2_stream_write::MemoryInfo(MemoryTracker* tracker) const {
2897+
void NgHttp2StreamWrite::MemoryInfo(MemoryTracker* tracker) const {
28892898
if (req_wrap != nullptr)
28902899
tracker->TrackField("req_wrap", req_wrap->GetAsyncWrap());
28912900
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_;
@@ -835,7 +835,7 @@ class Http2Session : public AsyncWrap,
835835
uint32_t max_header_pairs_ = DEFAULT_MAX_HEADER_LIST_PAIRS;
836836

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

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

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

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

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

0 commit comments

Comments
 (0)