| 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" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 if (!on_free_func_.is_null()) | 36 if (!on_free_func_.is_null()) |
| 37 on_free_func_.Run(); | 37 on_free_func_.Run(); |
| 38 } | 38 } |
| 39 | 39 |
| 40 void PortReservation::Leak() { | 40 void PortReservation::Leak() { |
| 41 LOG(ERROR) << "Port leaked: " << port_; | 41 LOG(ERROR) << "Port leaked: " << port_; |
| 42 on_free_func_.Reset(); | 42 on_free_func_.Reset(); |
| 43 } | 43 } |
| 44 | 44 |
| 45 PortServer::PortServer(const std::string& path) : path_(path) { | 45 PortServer::PortServer(const std::string& path) : path_(path) { |
| 46 CHECK(path_.size() && path_[0] == 0) | 46 // path must be for Linux abstract namespace |
| 47 << "path must be for Linux abstract namespace"; | 47 CHECK(path_.size() && path_[0] == 0); |
| 48 } | 48 } |
| 49 | 49 |
| 50 PortServer::~PortServer() {} | 50 PortServer::~PortServer() {} |
| 51 | 51 |
| 52 Status PortServer::ReservePort(uint16_t* port, | 52 Status PortServer::ReservePort(uint16_t* port, |
| 53 std::unique_ptr<PortReservation>* reservation) { | 53 std::unique_ptr<PortReservation>* reservation) { |
| 54 uint16_t port_to_use = 0; | 54 uint16_t port_to_use = 0; |
| 55 { | 55 { |
| 56 base::AutoLock lock(free_lock_); | 56 base::AutoLock lock(free_lock_); |
| 57 if (free_.size()) { | 57 if (free_.size()) { |
| (...skipping 157 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 |