diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2021-09-30 12:23:08 +0330 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-30 11:46:37 +0200 |
commit | 56bb7dde8705c18846a9ba51bfd43b633517e65d (patch) | |
tree | 29ebc354f986d0a7382fe2639eded70ac110a8d9 /Userland/Services/RequestServer/ConnectionCache.h | |
parent | b0a9c5673e7a8a100ddd827b780abe7d284802c1 (diff) | |
download | serenity-56bb7dde8705c18846a9ba51bfd43b633517e65d.zip |
RequestServer: Use an OwnPtr for the connection cache vector
Just as removing individual connections can cause the vector entries to
change positions, adding or removing connections to the cache can also
move the connections around, which would make it possible for a
connection to avoid being deleted (and make the RS spin on the Notifier
for that connection).
This commit makes it so that no connection cache is left when it's
supposed to be deleted.
Fixes a few more RS spins.
Diffstat (limited to 'Userland/Services/RequestServer/ConnectionCache.h')
-rw-r--r-- | Userland/Services/RequestServer/ConnectionCache.h | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/Userland/Services/RequestServer/ConnectionCache.h b/Userland/Services/RequestServer/ConnectionCache.h index 4221244330..eba52f2b12 100644 --- a/Userland/Services/RequestServer/ConnectionCache.h +++ b/Userland/Services/RequestServer/ConnectionCache.h @@ -61,8 +61,8 @@ struct AK::Traits<RequestServer::ConnectionCache::ConnectionKey> : public AK::Ge namespace RequestServer::ConnectionCache { -extern HashMap<ConnectionKey, NonnullOwnPtrVector<Connection<Core::TCPSocket>>> g_tcp_connection_cache; -extern HashMap<ConnectionKey, NonnullOwnPtrVector<Connection<TLS::TLSv12>>> g_tls_connection_cache; +extern HashMap<ConnectionKey, NonnullOwnPtr<NonnullOwnPtrVector<Connection<Core::TCPSocket>>>> g_tcp_connection_cache; +extern HashMap<ConnectionKey, NonnullOwnPtr<NonnullOwnPtrVector<Connection<TLS::TLSv12>>>> g_tls_connection_cache; void request_did_finish(URL const&, Core::Socket const*); void dump_jobs(); @@ -72,14 +72,15 @@ constexpr static inline size_t ConnectionKeepAliveTimeMilliseconds = 10'000; decltype(auto) get_or_create_connection(auto& cache, URL const& url, auto& job) { + using CacheEntryType = RemoveCVReference<decltype(*cache.begin()->value)>; auto start_job = [&job](auto& socket) { job.start(socket); }; - auto& sockets_for_url = cache.ensure({ url.host(), url.port_or_default() }); + auto& sockets_for_url = *cache.ensure({ url.host(), url.port_or_default() }, [] { return make<CacheEntryType>(); }); auto it = sockets_for_url.find_if([](auto& connection) { return connection->request_queue.is_empty(); }); auto did_add_new_connection = false; if (it.is_end() && sockets_for_url.size() < ConnectionCache::MaxConcurrentConnectionsPerURL) { - using ConnectionType = RemoveCVReference<decltype(cache.begin()->value.at(0))>; + using ConnectionType = RemoveCVReference<decltype(cache.begin()->value->at(0))>; sockets_for_url.append(make<ConnectionType>( ConnectionType::SocketType::construct(nullptr), typename ConnectionType::QueueType {}, @@ -106,7 +107,7 @@ decltype(auto) get_or_create_connection(auto& cache, URL const& url, auto& job) } auto& connection = sockets_for_url[index]; if (!connection.has_started) { - dbgln("Immediately start request for url {} in {}", url, &connection); + dbgln("Immediately start request for url {} in {} - {}", url, &connection, connection.socket); connection.has_started = true; connection.removal_timer->stop(); if constexpr (REQUEST_SERVER_DEBUG) { @@ -115,7 +116,7 @@ decltype(auto) get_or_create_connection(auto& cache, URL const& url, auto& job) } start_job(*connection.socket); } else { - dbgln("Enqueue request for URL {} in {}", url, &connection); + dbgln("Enqueue request for URL {} in {} - {}", url, &connection, connection.socket); connection.request_queue.append(move(start_job)); } return connection; |