@@ -239,7 +239,6 @@ Http2Session::Http2Settings::Http2Settings(Environment* env,
239
239
: AsyncWrap(env, obj, PROVIDER_HTTP2SETTINGS),
240
240
session_ (session),
241
241
startTime_(start_time) {
242
- RemoveCleanupHook (); // This object is owned by the Http2Session.
243
242
Init ();
244
243
}
245
244
@@ -658,8 +657,6 @@ Http2Session::Http2Session(Environment* env,
658
657
Http2Session::~Http2Session () {
659
658
CHECK_EQ (flags_ & SESSION_STATE_HAS_SCOPE, 0 );
660
659
Debug (this , " freeing nghttp2 session" );
661
- for (const auto & iter : streams_)
662
- iter.second ->session_ = nullptr ;
663
660
nghttp2_session_del (session_);
664
661
CHECK_EQ (current_nghttp2_memory_, 0 );
665
662
}
@@ -767,7 +764,7 @@ void Http2Session::Close(uint32_t code, bool socket_closed) {
767
764
// If there are outstanding pings, those will need to be canceled, do
768
765
// so on the next iteration of the event loop to avoid calling out into
769
766
// javascript since this may be called during garbage collection.
770
- while (std::unique_ptr <Http2Ping> ping = PopPing ()) {
767
+ while (BaseObjectPtr <Http2Ping> ping = PopPing ()) {
771
768
ping->DetachFromSession ();
772
769
env ()->SetImmediate (
773
770
[ping = std::move (ping)](Environment* env) {
@@ -1483,7 +1480,7 @@ void Http2Session::HandlePingFrame(const nghttp2_frame* frame) {
1483
1480
Local<Value> arg;
1484
1481
bool ack = frame->hd .flags & NGHTTP2_FLAG_ACK;
1485
1482
if (ack) {
1486
- std::unique_ptr <Http2Ping> ping = PopPing ();
1483
+ BaseObjectPtr <Http2Ping> ping = PopPing ();
1487
1484
1488
1485
if (!ping) {
1489
1486
// PING Ack is unsolicited. Treat as a connection error. The HTTP/2
@@ -1522,7 +1519,7 @@ void Http2Session::HandleSettingsFrame(const nghttp2_frame* frame) {
1522
1519
1523
1520
// If this is an acknowledgement, we should have an Http2Settings
1524
1521
// object for it.
1525
- std::unique_ptr <Http2Settings> settings = PopSettings ();
1522
+ BaseObjectPtr <Http2Settings> settings = PopSettings ();
1526
1523
if (settings) {
1527
1524
settings->Done (true );
1528
1525
return ;
@@ -1982,12 +1979,11 @@ Http2Stream::~Http2Stream() {
1982
1979
nghttp2_rcbuf_decref (header.value );
1983
1980
}
1984
1981
1985
- if (session_ == nullptr )
1982
+ if (! session_)
1986
1983
return ;
1987
1984
Debug (this , " tearing down stream" );
1988
1985
session_->DecrementCurrentSessionMemory (current_headers_length_);
1989
1986
session_->RemoveStream (this );
1990
- session_ = nullptr ;
1991
1987
}
1992
1988
1993
1989
std::string Http2Stream::diagnostic_name () const {
@@ -2189,8 +2185,10 @@ Http2Stream* Http2Stream::SubmitPushPromise(nghttp2_nv* nva,
2189
2185
id_, nva, len, nullptr );
2190
2186
CHECK_NE (*ret, NGHTTP2_ERR_NOMEM);
2191
2187
Http2Stream* stream = nullptr ;
2192
- if (*ret > 0 )
2193
- stream = Http2Stream::New (session_, *ret, NGHTTP2_HCAT_HEADERS, options);
2188
+ if (*ret > 0 ) {
2189
+ stream = Http2Stream::New (
2190
+ session_.get (), *ret, NGHTTP2_HCAT_HEADERS, options);
2191
+ }
2194
2192
2195
2193
return stream;
2196
2194
}
@@ -2855,7 +2853,8 @@ void Http2Session::Ping(const FunctionCallbackInfo<Value>& args) {
2855
2853
if (obj->Set (env->context (), env->ondone_string (), args[1 ]).IsNothing ())
2856
2854
return ;
2857
2855
2858
- Http2Ping* ping = session->AddPing (std::make_unique<Http2Ping>(session, obj));
2856
+ Http2Ping* ping = session->AddPing (
2857
+ MakeDetachedBaseObject<Http2Ping>(session, obj));
2859
2858
// To prevent abuse, we strictly limit the number of unacknowledged PING
2860
2859
// frames that may be sent at any given time. This is configurable in the
2861
2860
// Options when creating a Http2Session.
@@ -2884,16 +2883,16 @@ void Http2Session::Settings(const FunctionCallbackInfo<Value>& args) {
2884
2883
if (obj->Set (env->context (), env->ondone_string (), args[0 ]).IsNothing ())
2885
2884
return ;
2886
2885
2887
- Http2Session:: Http2Settings* settings = session->AddSettings (
2888
- std::make_unique <Http2Settings>(session->env (), session, obj, 0 ));
2886
+ Http2Settings* settings = session->AddSettings (
2887
+ MakeDetachedBaseObject <Http2Settings>(session->env (), session, obj, 0 ));
2889
2888
if (settings == nullptr ) return args.GetReturnValue ().Set (false );
2890
2889
2891
2890
settings->Send ();
2892
2891
args.GetReturnValue ().Set (true );
2893
2892
}
2894
2893
2895
- std::unique_ptr <Http2Session::Http2Ping> Http2Session::PopPing () {
2896
- std::unique_ptr <Http2Ping> ping;
2894
+ BaseObjectPtr <Http2Session::Http2Ping> Http2Session::PopPing () {
2895
+ BaseObjectPtr <Http2Ping> ping;
2897
2896
if (!outstanding_pings_.empty ()) {
2898
2897
ping = std::move (outstanding_pings_.front ());
2899
2898
outstanding_pings_.pop ();
@@ -2903,7 +2902,7 @@ std::unique_ptr<Http2Session::Http2Ping> Http2Session::PopPing() {
2903
2902
}
2904
2903
2905
2904
Http2Session::Http2Ping* Http2Session::AddPing (
2906
- std::unique_ptr <Http2Session::Http2Ping> ping) {
2905
+ BaseObjectPtr <Http2Session::Http2Ping> ping) {
2907
2906
if (outstanding_pings_.size () == max_outstanding_pings_) {
2908
2907
ping->Done (false );
2909
2908
return nullptr ;
@@ -2914,8 +2913,8 @@ Http2Session::Http2Ping* Http2Session::AddPing(
2914
2913
return ptr;
2915
2914
}
2916
2915
2917
- std::unique_ptr <Http2Session::Http2Settings> Http2Session::PopSettings () {
2918
- std::unique_ptr <Http2Settings> settings;
2916
+ BaseObjectPtr <Http2Session::Http2Settings> Http2Session::PopSettings () {
2917
+ BaseObjectPtr <Http2Settings> settings;
2919
2918
if (!outstanding_settings_.empty ()) {
2920
2919
settings = std::move (outstanding_settings_.front ());
2921
2920
outstanding_settings_.pop ();
@@ -2925,7 +2924,7 @@ std::unique_ptr<Http2Session::Http2Settings> Http2Session::PopSettings() {
2925
2924
}
2926
2925
2927
2926
Http2Session::Http2Settings* Http2Session::AddSettings (
2928
- std::unique_ptr <Http2Session::Http2Settings> settings) {
2927
+ BaseObjectPtr <Http2Session::Http2Settings> settings) {
2929
2928
if (outstanding_settings_.size () == max_outstanding_settings_) {
2930
2929
settings->Done (false );
2931
2930
return nullptr ;
@@ -2940,7 +2939,6 @@ Http2Session::Http2Ping::Http2Ping(Http2Session* session, Local<Object> obj)
2940
2939
: AsyncWrap(session->env (), obj, AsyncWrap::PROVIDER_HTTP2PING),
2941
2940
session_(session),
2942
2941
startTime_(uv_hrtime()) {
2943
- RemoveCleanupHook (); // This object is owned by the Http2Session.
2944
2942
}
2945
2943
2946
2944
void Http2Session::Http2Ping::Send (const uint8_t * payload) {
0 commit comments