OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chrome/test/chromedriver/net/port_server.h" | 5 #include "chrome/test/chromedriver/net/port_server.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/process/process_handle.h" | 14 #include "base/process/process_handle.h" |
15 #include "base/rand_util.h" | 15 #include "base/rand_util.h" |
16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
17 #include "base/sync_socket.h" | 17 #include "base/sync_socket.h" |
18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
19 #include "chrome/test/chromedriver/chrome/status.h" | 19 #include "chrome/test/chromedriver/chrome/status.h" |
20 #include "net/base/ip_address.h" | 20 #include "net/base/ip_address.h" |
21 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
22 #include "net/base/sys_addrinfo.h" | 22 #include "net/base/sys_addrinfo.h" |
23 #include "net/log/net_log.h" | 23 #include "net/log/net_log_source.h" |
24 #include "net/socket/tcp_server_socket.h" | 24 #include "net/socket/tcp_server_socket.h" |
25 | 25 |
26 #if defined(OS_LINUX) | 26 #if defined(OS_LINUX) |
27 #include <sys/socket.h> | 27 #include <sys/socket.h> |
28 #include <sys/un.h> | 28 #include <sys/un.h> |
29 #endif | 29 #endif |
30 | 30 |
31 PortReservation::PortReservation(const base::Closure& on_free_func, | 31 PortReservation::PortReservation(const base::Closure& on_free_func, |
32 uint16_t port) | 32 uint16_t port) |
33 : on_free_func_(on_free_func), port_(port) {} | 33 : on_free_func_(on_free_func), port_(port) {} |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 if (try_port > max_port_) { | 156 if (try_port > max_port_) { |
157 wrapped = true; | 157 wrapped = true; |
158 if (min_port_ == max_port_) | 158 if (min_port_ == max_port_) |
159 break; | 159 break; |
160 try_port = min_port_; | 160 try_port = min_port_; |
161 } | 161 } |
162 uint16_t try_port_uint16 = static_cast<uint16_t>(try_port); | 162 uint16_t try_port_uint16 = static_cast<uint16_t>(try_port); |
163 if (taken_.count(try_port_uint16)) | 163 if (taken_.count(try_port_uint16)) |
164 continue; | 164 continue; |
165 | 165 |
166 net::NetLog::Source source; | 166 net::NetLogSource source; |
167 net::TCPServerSocket sock(NULL, source); | 167 net::TCPServerSocket sock(NULL, source); |
168 if (sock.Listen( | 168 if (sock.Listen( |
169 net::IPEndPoint(net::IPAddress::IPv4Localhost(), try_port_uint16), | 169 net::IPEndPoint(net::IPAddress::IPv4Localhost(), try_port_uint16), |
170 1) == net::OK) | 170 1) == net::OK) |
171 return try_port_uint16; | 171 return try_port_uint16; |
172 } | 172 } |
173 return 0; | 173 return 0; |
174 } | 174 } |
175 | 175 |
176 Status PortManager::ReservePort(uint16_t* port, | 176 Status PortManager::ReservePort(uint16_t* port, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 void PortManager::ReleasePort(uint16_t port) { | 215 void PortManager::ReleasePort(uint16_t port) { |
216 base::AutoLock lock(lock_); | 216 base::AutoLock lock(lock_); |
217 taken_.erase(port); | 217 taken_.erase(port); |
218 } | 218 } |
219 | 219 |
220 void PortManager::ReleasePortToPool(uint16_t port) { | 220 void PortManager::ReleasePortToPool(uint16_t port) { |
221 base::AutoLock lock(lock_); | 221 base::AutoLock lock(lock_); |
222 taken_.erase(port); | 222 taken_.erase(port); |
223 unused_forwarded_port_.push_back(port); | 223 unused_forwarded_port_.push_back(port); |
224 } | 224 } |
OLD | NEW |