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

Unified Diff: net/websockets/websocket_throttle.cc

Issue 10309002: Reimplements net::AddressList without struct addrinfo. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: get_canonical_name -> canonical_name. iterator to indexing Created 8 years, 7 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 | « net/websockets/websocket_job_spdy3_unittest.cc ('k') | 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 510dea44d564bb8a6bdf4f3ad6596fc709c1fd13..61b408621c05dbe0cced5d938b0b9469a52dca02 100644
--- a/net/websockets/websocket_throttle.cc
+++ b/net/websockets/websocket_throttle.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -14,36 +14,16 @@
#include "base/string_util.h"
#include "base/stringprintf.h"
#include "net/base/io_buffer.h"
-#include "net/base/sys_addrinfo.h"
#include "net/socket_stream/socket_stream.h"
#include "net/websockets/websocket_job.h"
namespace net {
-static std::string AddrinfoToHashkey(const struct addrinfo* addrinfo) {
- switch (addrinfo->ai_family) {
- case AF_INET: {
- const struct sockaddr_in* const addr =
- reinterpret_cast<const sockaddr_in*>(addrinfo->ai_addr);
- return base::StringPrintf("%d:%s",
- addrinfo->ai_family,
- base::HexEncode(&addr->sin_addr, 4).c_str());
- }
- case AF_INET6: {
- const struct sockaddr_in6* const addr6 =
- reinterpret_cast<const sockaddr_in6*>(addrinfo->ai_addr);
- return base::StringPrintf(
- "%d:%s",
- addrinfo->ai_family,
- base::HexEncode(&addr6->sin6_addr,
- sizeof(addr6->sin6_addr)).c_str());
- }
- default:
- return base::StringPrintf("%d:%s",
- addrinfo->ai_family,
- base::HexEncode(addrinfo->ai_addr,
- addrinfo->ai_addrlen).c_str());
- }
+static std::string IPEndPointToHashkey(const IPEndPoint& endpoint) {
+ return base::StringPrintf("%d:%s",
+ endpoint.GetFamily(),
+ base::HexEncode(&endpoint.address()[0],
+ endpoint.address().size()).c_str());
}
WebSocketThrottle::WebSocketThrottle() {
@@ -63,10 +43,10 @@ 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);
+ for (AddressList::const_iterator addr_iter = address_list.begin();
+ addr_iter != address_list.end();
+ ++addr_iter) {
+ std::string addrkey = IPEndPointToHashkey(*addr_iter);
// If |addrkey| is already processed, don't do it again.
if (address_set.find(addrkey) != address_set.end())
@@ -101,10 +81,10 @@ void WebSocketThrottle::RemoveFromQueue(WebSocketJob* job) {
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);
+ for (AddressList::const_iterator addr_iter = address_list.begin();
+ addr_iter != address_list.end();
+ ++addr_iter) {
+ std::string addrkey = IPEndPointToHashkey(*addr_iter);
// If |addrkey| is already processed, don't do it again.
if (address_set.find(addrkey) != address_set.end())
continue;
@@ -140,10 +120,10 @@ void WebSocketThrottle::WakeupSocketIfNecessary() {
bool should_wakeup = true;
const AddressList& address_list = job->address_list();
- for (const struct addrinfo* addrinfo = address_list.head();
- addrinfo != NULL;
- addrinfo = addrinfo->ai_next) {
- std::string addrkey = AddrinfoToHashkey(addrinfo);
+ for (AddressList::const_iterator addr_iter = address_list.begin();
+ addr_iter != address_list.end();
+ ++addr_iter) {
+ std::string addrkey = IPEndPointToHashkey(*addr_iter);
ConnectingAddressMap::iterator iter = addr_map_.find(addrkey);
DCHECK(iter != addr_map_.end());
ConnectingQueue* queue = iter->second;
« no previous file with comments | « net/websockets/websocket_job_spdy3_unittest.cc ('k') | net/websockets/websocket_throttle_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698