OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/spawned_test_server/local_test_server.h" | 5 #include "net/test/spawned_test_server/local_test_server.h" |
6 | 6 |
7 #include <poll.h> | 7 #include <poll.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
13 #include "base/files/scoped_file.h" | 13 #include "base/files/scoped_file.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/macros.h" |
15 #include "base/process/kill.h" | 16 #include "base/process/kill.h" |
16 #include "base/process/launch.h" | 17 #include "base/process/launch.h" |
17 #include "base/process/process_iterator.h" | 18 #include "base/process/process_iterator.h" |
18 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
19 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
20 #include "base/test/test_timeouts.h" | 21 #include "base/test/test_timeouts.h" |
21 #include "net/test/python_utils.h" | 22 #include "net/test/python_utils.h" |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
(...skipping 28 matching lines...) Expand all Loading... |
53 | 54 |
54 private: | 55 private: |
55 std::string path_string_; | 56 std::string path_string_; |
56 std::string port_string_; | 57 std::string port_string_; |
57 DISALLOW_COPY_AND_ASSIGN(OrphanedTestServerFilter); | 58 DISALLOW_COPY_AND_ASSIGN(OrphanedTestServerFilter); |
58 }; | 59 }; |
59 | 60 |
60 // Given a file descriptor, reads into |buffer| until |bytes_max| | 61 // Given a file descriptor, reads into |buffer| until |bytes_max| |
61 // bytes has been read or an error has been encountered. Returns true | 62 // bytes has been read or an error has been encountered. Returns true |
62 // if the read was successful. |remaining_time| is used as a timeout. | 63 // if the read was successful. |remaining_time| is used as a timeout. |
63 bool ReadData(int fd, ssize_t bytes_max, uint8* buffer, | 64 bool ReadData(int fd, |
| 65 ssize_t bytes_max, |
| 66 uint8_t* buffer, |
64 base::TimeDelta* remaining_time) { | 67 base::TimeDelta* remaining_time) { |
65 ssize_t bytes_read = 0; | 68 ssize_t bytes_read = 0; |
66 base::TimeTicks previous_time = base::TimeTicks::Now(); | 69 base::TimeTicks previous_time = base::TimeTicks::Now(); |
67 while (bytes_read < bytes_max) { | 70 while (bytes_read < bytes_max) { |
68 struct pollfd poll_fds[1]; | 71 struct pollfd poll_fds[1]; |
69 | 72 |
70 poll_fds[0].fd = fd; | 73 poll_fds[0].fd = fd; |
71 poll_fds[0].events = POLLIN | POLLPRI; | 74 poll_fds[0].events = POLLIN | POLLPRI; |
72 poll_fds[0].revents = 0; | 75 poll_fds[0].revents = 0; |
73 | 76 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 } | 149 } |
147 | 150 |
148 return true; | 151 return true; |
149 } | 152 } |
150 | 153 |
151 bool LocalTestServer::WaitToStart() { | 154 bool LocalTestServer::WaitToStart() { |
152 base::ScopedFD our_fd(child_fd_.release()); | 155 base::ScopedFD our_fd(child_fd_.release()); |
153 | 156 |
154 base::TimeDelta remaining_time = TestTimeouts::action_timeout(); | 157 base::TimeDelta remaining_time = TestTimeouts::action_timeout(); |
155 | 158 |
156 uint32 server_data_len = 0; | 159 uint32_t server_data_len = 0; |
157 if (!ReadData(our_fd.get(), sizeof(server_data_len), | 160 if (!ReadData(our_fd.get(), sizeof(server_data_len), |
158 reinterpret_cast<uint8*>(&server_data_len), | 161 reinterpret_cast<uint8_t*>(&server_data_len), |
159 &remaining_time)) { | 162 &remaining_time)) { |
160 LOG(ERROR) << "Could not read server_data_len"; | 163 LOG(ERROR) << "Could not read server_data_len"; |
161 return false; | 164 return false; |
162 } | 165 } |
163 std::string server_data(server_data_len, '\0'); | 166 std::string server_data(server_data_len, '\0'); |
164 if (!ReadData(our_fd.get(), server_data_len, | 167 if (!ReadData(our_fd.get(), server_data_len, |
165 reinterpret_cast<uint8*>(&server_data[0]), | 168 reinterpret_cast<uint8_t*>(&server_data[0]), &remaining_time)) { |
166 &remaining_time)) { | |
167 LOG(ERROR) << "Could not read server_data (" << server_data_len | 169 LOG(ERROR) << "Could not read server_data (" << server_data_len |
168 << " bytes)"; | 170 << " bytes)"; |
169 return false; | 171 return false; |
170 } | 172 } |
171 | 173 |
172 if (!ParseServerData(server_data)) { | 174 if (!ParseServerData(server_data)) { |
173 LOG(ERROR) << "Could not parse server_data: " << server_data; | 175 LOG(ERROR) << "Could not parse server_data: " << server_data; |
174 return false; | 176 return false; |
175 } | 177 } |
176 | 178 |
177 return true; | 179 return true; |
178 } | 180 } |
179 | 181 |
180 } // namespace net | 182 } // namespace net |
OLD | NEW |