| 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 #ifndef CHROME_TEST_CHROMEDRIVER_NET_PORT_SERVER_H_ | 5 #ifndef CHROME_TEST_CHROMEDRIVER_NET_PORT_SERVER_H_ |
| 6 #define CHROME_TEST_CHROMEDRIVER_NET_PORT_SERVER_H_ | 6 #define CHROME_TEST_CHROMEDRIVER_NET_PORT_SERVER_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 std::list<int> free_; | 47 std::list<int> free_; |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 // Manages reservation of a block of local ports. | 50 // Manages reservation of a block of local ports. |
| 51 class PortManager { | 51 class PortManager { |
| 52 public: | 52 public: |
| 53 PortManager(int min_port, int max_port); | 53 PortManager(int min_port, int max_port); |
| 54 ~PortManager(); | 54 ~PortManager(); |
| 55 | 55 |
| 56 Status ReservePort(int* port, scoped_ptr<PortReservation>* reservation); | 56 Status ReservePort(int* port, scoped_ptr<PortReservation>* reservation); |
| 57 // Since we cannot remove forwarded adb ports on older SDKs, |
| 58 // maintain a pool of forwarded ports for reuse. |
| 59 Status ReservePortFromPool(int* port, |
| 60 scoped_ptr<PortReservation>* reservation); |
| 57 | 61 |
| 58 private: | 62 private: |
| 63 int FindAvailablePort() const; |
| 59 void ReleasePort(int port); | 64 void ReleasePort(int port); |
| 65 void ReleasePortToPool(int port); |
| 60 | 66 |
| 61 base::Lock taken_lock_; | 67 base::Lock lock_; |
| 62 std::set<int> taken_; | 68 std::set<int> taken_; |
| 63 | 69 std::list<int> unused_forwarded_port_; |
| 64 int min_port_; | 70 int min_port_; |
| 65 int max_port_; | 71 int max_port_; |
| 66 }; | 72 }; |
| 67 | 73 |
| 68 #endif // CHROME_TEST_CHROMEDRIVER_NET_PORT_SERVER_H_ | 74 #endif // CHROME_TEST_CHROMEDRIVER_NET_PORT_SERVER_H_ |
| OLD | NEW |