Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2146)

Unified Diff: net/websockets/websocket_throttle.cc

Issue 1750001: Don't process the same address for throttling. (Closed)
Patch Set: add test Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/websockets/websocket_throttle_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/websockets/websocket_throttle.cc
diff --git a/net/websockets/websocket_throttle.cc b/net/websockets/websocket_throttle.cc
index e2e98c3ad0cd22b86d1779cae5253161d6527ed7..9e33cada5d95c508e51e457225bb57c28a717343 100644
--- a/net/websockets/websocket_throttle.cc
+++ b/net/websockets/websocket_throttle.cc
@@ -6,6 +6,7 @@
#include <string>
+#include "base/hash_tables.h"
#include "base/message_loop.h"
#include "base/ref_counted.h"
#include "base/singleton.h"
@@ -53,10 +54,17 @@ WebSocketThrottle::~WebSocketThrottle() {
void WebSocketThrottle::PutInQueue(WebSocketJob* job) {
queue_.push_back(job);
const AddressList& address_list = job->address_list();
+ base::hash_set<std::string> address_set;
for (const struct addrinfo* addrinfo = address_list.head();
addrinfo != NULL;
addrinfo = addrinfo->ai_next) {
std::string addrkey = AddrinfoToHashkey(addrinfo);
+
+ // If |addrkey| is already processed, don't do it again.
+ if (address_set.find(addrkey) != address_set.end())
+ continue;
+ address_set.insert(addrkey);
+
ConnectingAddressMap::iterator iter = addr_map_.find(addrkey);
if (iter == addr_map_.end()) {
ConnectingQueue* queue = new ConnectingQueue();
@@ -65,6 +73,7 @@ void WebSocketThrottle::PutInQueue(WebSocketJob* job) {
} else {
iter->second->push_back(job);
job->SetWaiting();
+ DLOG(INFO) << "Waiting on " << addrkey;
}
}
}
@@ -83,12 +92,19 @@ void WebSocketThrottle::RemoveFromQueue(WebSocketJob* job) {
if (!in_queue)
return;
const AddressList& address_list = job->address_list();
+ base::hash_set<std::string> address_set;
for (const struct addrinfo* addrinfo = address_list.head();
addrinfo != NULL;
addrinfo = addrinfo->ai_next) {
std::string addrkey = AddrinfoToHashkey(addrinfo);
+ // If |addrkey| is already processed, don't do it again.
+ if (address_set.find(addrkey) != address_set.end())
+ continue;
+ address_set.insert(addrkey);
+
ConnectingAddressMap::iterator iter = addr_map_.find(addrkey);
DCHECK(iter != addr_map_.end());
+
ConnectingQueue* queue = iter->second;
// Job may not be front of queue when job is closed early while waiting.
for (ConnectingQueue::iterator iter = queue->begin();
« no previous file with comments | « no previous file | net/websockets/websocket_throttle_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698