| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/websockets/websocket_throttle.h" | 5 #include "net/websockets/websocket_throttle.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/hash_tables.h" | 9 #include "base/hash_tables.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/ref_counted.h" | 11 #include "base/ref_counted.h" |
| 12 #include "base/singleton.h" | 12 #include "base/singleton.h" |
| 13 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "base/stringprintf.h" |
| 15 #include "net/base/io_buffer.h" | 16 #include "net/base/io_buffer.h" |
| 16 #include "net/base/sys_addrinfo.h" | 17 #include "net/base/sys_addrinfo.h" |
| 17 #include "net/socket_stream/socket_stream.h" | 18 #include "net/socket_stream/socket_stream.h" |
| 18 #include "net/websockets/websocket_job.h" | 19 #include "net/websockets/websocket_job.h" |
| 19 | 20 |
| 20 namespace net { | 21 namespace net { |
| 21 | 22 |
| 22 static std::string AddrinfoToHashkey(const struct addrinfo* addrinfo) { | 23 static std::string AddrinfoToHashkey(const struct addrinfo* addrinfo) { |
| 23 switch (addrinfo->ai_family) { | 24 switch (addrinfo->ai_family) { |
| 24 case AF_INET: { | 25 case AF_INET: { |
| 25 const struct sockaddr_in* const addr = | 26 const struct sockaddr_in* const addr = |
| 26 reinterpret_cast<const sockaddr_in*>(addrinfo->ai_addr); | 27 reinterpret_cast<const sockaddr_in*>(addrinfo->ai_addr); |
| 27 return StringPrintf("%d:%s", | 28 return base::StringPrintf("%d:%s", |
| 28 addrinfo->ai_family, | 29 addrinfo->ai_family, |
| 29 base::HexEncode(&addr->sin_addr, 4).c_str()); | 30 base::HexEncode(&addr->sin_addr, 4).c_str()); |
| 30 } | 31 } |
| 31 case AF_INET6: { | 32 case AF_INET6: { |
| 32 const struct sockaddr_in6* const addr6 = | 33 const struct sockaddr_in6* const addr6 = |
| 33 reinterpret_cast<const sockaddr_in6*>(addrinfo->ai_addr); | 34 reinterpret_cast<const sockaddr_in6*>(addrinfo->ai_addr); |
| 34 return StringPrintf("%d:%s", | 35 return base::StringPrintf( |
| 35 addrinfo->ai_family, | 36 "%d:%s", |
| 36 base::HexEncode(&addr6->sin6_addr, | 37 addrinfo->ai_family, |
| 37 sizeof(addr6->sin6_addr)).c_str()); | 38 base::HexEncode(&addr6->sin6_addr, |
| 39 sizeof(addr6->sin6_addr)).c_str()); |
| 38 } | 40 } |
| 39 default: | 41 default: |
| 40 return StringPrintf("%d:%s", | 42 return base::StringPrintf("%d:%s", |
| 41 addrinfo->ai_family, | 43 addrinfo->ai_family, |
| 42 base::HexEncode(addrinfo->ai_addr, | 44 base::HexEncode(addrinfo->ai_addr, |
| 43 addrinfo->ai_addrlen).c_str()); | 45 addrinfo->ai_addrlen).c_str()); |
| 44 } | 46 } |
| 45 } | 47 } |
| 46 | 48 |
| 47 WebSocketThrottle::WebSocketThrottle() { | 49 WebSocketThrottle::WebSocketThrottle() { |
| 48 } | 50 } |
| 49 | 51 |
| 50 WebSocketThrottle::~WebSocketThrottle() { | 52 WebSocketThrottle::~WebSocketThrottle() { |
| 51 DCHECK(queue_.empty()); | 53 DCHECK(queue_.empty()); |
| 52 DCHECK(addr_map_.empty()); | 54 DCHECK(addr_map_.empty()); |
| 53 } | 55 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 should_wakeup = false; | 146 should_wakeup = false; |
| 145 break; | 147 break; |
| 146 } | 148 } |
| 147 } | 149 } |
| 148 if (should_wakeup) | 150 if (should_wakeup) |
| 149 job->Wakeup(); | 151 job->Wakeup(); |
| 150 } | 152 } |
| 151 } | 153 } |
| 152 | 154 |
| 153 } // namespace net | 155 } // namespace net |
| OLD | NEW |