| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a2dbadc commit 6665881
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -63,10 +63,6 @@ BaseObject::~BaseObject() { | |||
| 63 | 63 | } | |
| 64 | 64 | } | |
| 65 | 65 | ||
| 66 | - void BaseObject::RemoveCleanupHook() { | ||
| 67 | - env_->RemoveCleanupHook(DeleteMe, static_cast<void*>(this)); | ||
| 68 | - } | ||
| 69 | - | ||
| 70 | 66 | void BaseObject::Detach() { | |
| 71 | 67 | CHECK_GT(pointer_data()->strong_ptr_count, 0); | |
| 72 | 68 | pointer_data()->is_detached = true; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -97,7 +97,6 @@ class BaseObject : public MemoryRetainer { | |||
| 97 | 97 | inline void Detach(); | |
| 98 | 98 | ||
| 99 | 99 | protected: | |
| 100 | - inline void RemoveCleanupHook(); // TODO(addaleax): Remove. | ||
| 101 | 100 | virtual inline void OnGCCollect(); | |
| 102 | 101 | ||
| 103 | 102 | private: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -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) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -456,8 +456,8 @@ class Http2Stream : public AsyncWrap, | |||
| 456 | 456 | ||
| 457 | 457 | nghttp2_stream* operator*(); | |
| 458 | 458 | ||
| 459 | - Http2Session* session() { return session_; } | ||
| 460 | - const Http2Session* session() const { return session_; } | ||
| 459 | + Http2Session* session() { return session_.get(); } | ||
| 460 | + const Http2Session* session() const { return session_.get(); } | ||
| 461 | 461 | ||
| 462 | 462 | void EmitStatistics(); | |
| 463 | 463 | ||
@@ -609,7 +609,7 @@ class Http2Stream : public AsyncWrap, | |||
| 609 | 609 | nghttp2_headers_category category, | |
| 610 | 610 | int options); | |
| 611 | 611 | ||
| 612 | - Http2Session* session_ = nullptr; // The Parent HTTP/2 Session | ||
| 612 | + BaseObjectWeakPtr<Http2Session> session_; // The Parent HTTP/2 Session | ||
| 613 | 613 | int32_t id_ = 0; // The Stream Identifier | |
| 614 | 614 | int32_t code_ = NGHTTP2_NO_ERROR; // The RST_STREAM code (if any) | |
| 615 | 615 | int flags_ = NGHTTP2_STREAM_FLAG_NONE; // Internal state flags | |
@@ -822,11 +822,11 @@ class Http2Session : public AsyncWrap, public StreamListener { | |||
| 822 | 822 | return env()->event_loop(); | |
| 823 | 823 | } | |
| 824 | 824 | ||
| 825 | - std::unique_ptr<Http2Ping> PopPing(); | ||
| 826 | - Http2Ping* AddPing(std::unique_ptr<Http2Ping> ping); | ||
| 825 | + BaseObjectPtr<Http2Ping> PopPing(); | ||
| 826 | + Http2Ping* AddPing(BaseObjectPtr<Http2Ping> ping); | ||
| 827 | 827 | ||
| 828 | - std::unique_ptr<Http2Settings> PopSettings(); | ||
| 829 | - Http2Settings* AddSettings(std::unique_ptr<Http2Settings> settings); | ||
| 828 | + BaseObjectPtr<Http2Settings> PopSettings(); | ||
| 829 | + Http2Settings* AddSettings(BaseObjectPtr<Http2Settings> settings); | ||
| 830 | 830 | ||
| 831 | 831 | void IncrementCurrentSessionMemory(uint64_t amount) { | |
| 832 | 832 | current_session_memory_ += amount; | |
@@ -1001,10 +1001,10 @@ class Http2Session : public AsyncWrap, public StreamListener { | |||
| 1001 | 1001 | size_t stream_buf_offset_ = 0; | |
| 1002 | 1002 | ||
| 1003 | 1003 | size_t max_outstanding_pings_ = DEFAULT_MAX_PINGS; | |
| 1004 | - std::queue<std::unique_ptr<Http2Ping>> outstanding_pings_; | ||
| 1004 | + std::queue<BaseObjectPtr<Http2Ping>> outstanding_pings_; | ||
| 1005 | 1005 | ||
| 1006 | 1006 | size_t max_outstanding_settings_ = DEFAULT_MAX_SETTINGS; | |
| 1007 | - std::queue<std::unique_ptr<Http2Settings>> outstanding_settings_; | ||
| 1007 | + std::queue<BaseObjectPtr<Http2Settings>> outstanding_settings_; | ||
| 1008 | 1008 | ||
| 1009 | 1009 | std::vector<nghttp2_stream_write> outgoing_buffers_; | |
| 1010 | 1010 | std::vector<uint8_t> outgoing_storage_; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments