@@ -243,7 +243,6 @@ Http2Session::Http2Settings::Http2Settings(Environment* env,
243
243
: AsyncWrap(env, obj, PROVIDER_HTTP2SETTINGS),
244
244
session_ (session),
245
245
startTime_(start_time) {
246
- RemoveCleanupHook (); // This object is owned by the Http2Session.
247
246
Init ();
248
247
}
249
248
@@ -586,8 +585,6 @@ Http2Session::Http2Session(Environment* env,
586
585
Http2Session::~Http2Session () {
587
586
CHECK_EQ (flags_ & SESSION_STATE_HAS_SCOPE, 0 );
588
587
Debug (this , " freeing nghttp2 session" );
589
- for (const auto & iter : streams_)
590
- iter.second ->session_ = nullptr ;
591
588
nghttp2_session_del (session_);
592
589
CHECK_EQ (current_nghttp2_memory_, 0 );
593
590
}
@@ -695,7 +692,7 @@ void Http2Session::Close(uint32_t code, bool socket_closed) {
695
692
// If there are outstanding pings, those will need to be canceled, do
696
693
// so on the next iteration of the event loop to avoid calling out into
697
694
// javascript since this may be called during garbage collection.
698
- while (std::unique_ptr <Http2Ping> ping = PopPing ()) {
695
+ while (BaseObjectPtr <Http2Ping> ping = PopPing ()) {
699
696
ping->DetachFromSession ();
700
697
env ()->SetImmediate (
701
698
[ping = std::move (ping)](Environment* env) {
@@ -1451,7 +1448,7 @@ void Http2Session::HandlePingFrame(const nghttp2_frame* frame) {
1451
1448
Local<Value> arg;
1452
1449
bool ack = frame->hd .flags & NGHTTP2_FLAG_ACK;
1453
1450
if (ack) {
1454
- std::unique_ptr <Http2Ping> ping = PopPing ();
1451
+ BaseObjectPtr <Http2Ping> ping = PopPing ();
1455
1452
1456
1453
if (!ping) {
1457
1454
// PING Ack is unsolicited. Treat as a connection error. The HTTP/2
@@ -1490,7 +1487,7 @@ void Http2Session::HandleSettingsFrame(const nghttp2_frame* frame) {
1490
1487
1491
1488
// If this is an acknowledgement, we should have an Http2Settings
1492
1489
// object for it.
1493
- std::unique_ptr <Http2Settings> settings = PopSettings ();
1490
+ BaseObjectPtr <Http2Settings> settings = PopSettings ();
1494
1491
if (settings) {
1495
1492
settings->Done (true );
1496
1493
return ;
@@ -1951,12 +1948,11 @@ Http2Stream::~Http2Stream() {
1951
1948
nghttp2_rcbuf_decref (header.value );
1952
1949
}
1953
1950
1954
- if (session_ == nullptr )
1951
+ if (! session_)
1955
1952
return ;
1956
1953
Debug (this , " tearing down stream" );
1957
1954
session_->DecrementCurrentSessionMemory (current_headers_length_);
1958
1955
session_->RemoveStream (this );
1959
- session_ = nullptr ;
1960
1956
}
1961
1957
1962
1958
std::string Http2Stream::diagnostic_name () const {
@@ -2164,8 +2160,10 @@ Http2Stream* Http2Stream::SubmitPushPromise(nghttp2_nv* nva,
2164
2160
id_, nva, len, nullptr );
2165
2161
CHECK_NE (*ret, NGHTTP2_ERR_NOMEM);
2166
2162
Http2Stream* stream = nullptr ;
2167
- if (*ret > 0 )
2168
- stream = Http2Stream::New (session_, *ret, NGHTTP2_HCAT_HEADERS, options);
2163
+ if (*ret > 0 ) {
2164
+ stream = Http2Stream::New (
2165
+ session_.get (), *ret, NGHTTP2_HCAT_HEADERS, options);
2166
+ }
2169
2167
2170
2168
return stream;
2171
2169
}
@@ -2832,7 +2830,8 @@ void Http2Session::Ping(const FunctionCallbackInfo<Value>& args) {
2832
2830
if (obj->Set (env->context (), env->ondone_string (), args[1 ]).IsNothing ())
2833
2831
return ;
2834
2832
2835
- Http2Ping* ping = session->AddPing (std::make_unique<Http2Ping>(session, obj));
2833
+ Http2Ping* ping = session->AddPing (
2834
+ MakeDetachedBaseObject<Http2Ping>(session, obj));
2836
2835
// To prevent abuse, we strictly limit the number of unacknowledged PING
2837
2836
// frames that may be sent at any given time. This is configurable in the
2838
2837
// Options when creating a Http2Session.
@@ -2861,16 +2860,16 @@ void Http2Session::Settings(const FunctionCallbackInfo<Value>& args) {
2861
2860
if (obj->Set (env->context (), env->ondone_string (), args[0 ]).IsNothing ())
2862
2861
return ;
2863
2862
2864
- Http2Session:: Http2Settings* settings = session->AddSettings (
2865
- std::make_unique <Http2Settings>(session->env (), session, obj, 0 ));
2863
+ Http2Settings* settings = session->AddSettings (
2864
+ MakeDetachedBaseObject <Http2Settings>(session->env (), session, obj, 0 ));
2866
2865
if (settings == nullptr ) return args.GetReturnValue ().Set (false );
2867
2866
2868
2867
settings->Send ();
2869
2868
args.GetReturnValue ().Set (true );
2870
2869
}
2871
2870
2872
- std::unique_ptr <Http2Session::Http2Ping> Http2Session::PopPing () {
2873
- std::unique_ptr <Http2Ping> ping;
2871
+ BaseObjectPtr <Http2Session::Http2Ping> Http2Session::PopPing () {
2872
+ BaseObjectPtr <Http2Ping> ping;
2874
2873
if (!outstanding_pings_.empty ()) {
2875
2874
ping = std::move (outstanding_pings_.front ());
2876
2875
outstanding_pings_.pop ();
@@ -2880,7 +2879,7 @@ std::unique_ptr<Http2Session::Http2Ping> Http2Session::PopPing() {
2880
2879
}
2881
2880
2882
2881
Http2Session::Http2Ping* Http2Session::AddPing (
2883
- std::unique_ptr <Http2Session::Http2Ping> ping) {
2882
+ BaseObjectPtr <Http2Session::Http2Ping> ping) {
2884
2883
if (outstanding_pings_.size () == max_outstanding_pings_) {
2885
2884
ping->Done (false );
2886
2885
return nullptr ;
@@ -2891,8 +2890,8 @@ Http2Session::Http2Ping* Http2Session::AddPing(
2891
2890
return ptr;
2892
2891
}
2893
2892
2894
- std::unique_ptr <Http2Session::Http2Settings> Http2Session::PopSettings () {
2895
- std::unique_ptr <Http2Settings> settings;
2893
+ BaseObjectPtr <Http2Session::Http2Settings> Http2Session::PopSettings () {
2894
+ BaseObjectPtr <Http2Settings> settings;
2896
2895
if (!outstanding_settings_.empty ()) {
2897
2896
settings = std::move (outstanding_settings_.front ());
2898
2897
outstanding_settings_.pop ();
@@ -2902,7 +2901,7 @@ std::unique_ptr<Http2Session::Http2Settings> Http2Session::PopSettings() {
2902
2901
}
2903
2902
2904
2903
Http2Session::Http2Settings* Http2Session::AddSettings (
2905
- std::unique_ptr <Http2Session::Http2Settings> settings) {
2904
+ BaseObjectPtr <Http2Session::Http2Settings> settings) {
2906
2905
if (outstanding_settings_.size () == max_outstanding_settings_) {
2907
2906
settings->Done (false );
2908
2907
return nullptr ;
@@ -2917,7 +2916,6 @@ Http2Session::Http2Ping::Http2Ping(Http2Session* session, Local<Object> obj)
2917
2916
: AsyncWrap(session->env (), obj, AsyncWrap::PROVIDER_HTTP2PING),
2918
2917
session_(session),
2919
2918
startTime_(uv_hrtime()) {
2920
- RemoveCleanupHook (); // This object is owned by the Http2Session.
2921
2919
}
2922
2920
2923
2921
void Http2Session::Http2Ping::Send (const uint8_t * payload) {
0 commit comments