OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/test/test_server.h" | 5 #include "net/test/test_server.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 if (!SetPythonPath()) | 151 if (!SetPythonPath()) |
152 return false; | 152 return false; |
153 | 153 |
154 if (!LaunchPython(testserver_path)) | 154 if (!LaunchPython(testserver_path)) |
155 return false; | 155 return false; |
156 | 156 |
157 if (!WaitToStart()) { | 157 if (!WaitToStart()) { |
158 Stop(); | 158 Stop(); |
159 return false; | 159 return false; |
160 } | 160 } |
161 | 161 |
akalin
2010/12/08 15:02:34
Add a TODO(akalin) to add code to store all ports
Bernhard Bauer
2010/12/09 10:48:08
Done.
| |
162 net::explicitly_allowed_ports.insert(host_port_pair_.port()); | |
163 | |
162 started_ = true; | 164 started_ = true; |
163 return true; | 165 return true; |
164 } | 166 } |
165 | 167 |
166 bool TestServer::Stop() { | 168 bool TestServer::Stop() { |
167 if (!process_handle_) | 169 if (!process_handle_) |
168 return true; | 170 return true; |
169 | 171 |
170 started_ = false; | 172 started_ = false; |
171 | 173 |
172 // First check if the process has already terminated. | 174 // First check if the process has already terminated. |
173 bool ret = base::WaitForSingleProcess(process_handle_, 0); | 175 bool ret = base::WaitForSingleProcess(process_handle_, 0); |
174 if (!ret) | 176 if (!ret) |
175 ret = base::KillProcess(process_handle_, 1, true); | 177 ret = base::KillProcess(process_handle_, 1, true); |
176 | 178 |
177 if (ret) { | 179 if (ret) { |
178 base::CloseProcessHandle(process_handle_); | 180 base::CloseProcessHandle(process_handle_); |
179 process_handle_ = base::kNullProcessHandle; | 181 process_handle_ = base::kNullProcessHandle; |
180 } else { | 182 } else { |
181 VLOG(1) << "Kill failed?"; | 183 VLOG(1) << "Kill failed?"; |
182 } | 184 } |
183 | 185 |
186 net::explicitly_allowed_ports.erase(host_port_pair_.port()); | |
187 | |
184 return ret; | 188 return ret; |
185 } | 189 } |
186 | 190 |
187 const HostPortPair& TestServer::host_port_pair() const { | 191 const HostPortPair& TestServer::host_port_pair() const { |
188 DCHECK(started_); | 192 DCHECK(started_); |
189 return host_port_pair_; | 193 return host_port_pair_; |
190 } | 194 } |
191 | 195 |
192 const DictionaryValue& TestServer::server_data() const { | 196 const DictionaryValue& TestServer::server_data() const { |
193 DCHECK(started_); | 197 DCHECK(started_); |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
404 } | 408 } |
405 if ((port <= 0) || (port > kuint16max)) { | 409 if ((port <= 0) || (port > kuint16max)) { |
406 LOG(ERROR) << "Invalid port value: " << port; | 410 LOG(ERROR) << "Invalid port value: " << port; |
407 return false; | 411 return false; |
408 } | 412 } |
409 host_port_pair_.set_port(port); | 413 host_port_pair_.set_port(port); |
410 return true; | 414 return true; |
411 } | 415 } |
412 | 416 |
413 } // namespace net | 417 } // namespace net |
OLD | NEW |