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 <poll.h> | 7 #include <poll.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 &process_handle_)) { | 91 &process_handle_)) { |
92 LOG(ERROR) << "Failed to launch " << python_command.command_line_string() | 92 LOG(ERROR) << "Failed to launch " << python_command.command_line_string() |
93 << " ..."; | 93 << " ..."; |
94 return false; | 94 return false; |
95 } | 95 } |
96 | 96 |
97 return true; | 97 return true; |
98 } | 98 } |
99 | 99 |
100 bool TestServer::WaitToStart() { | 100 bool TestServer::WaitToStart() { |
101 struct pollfd poll_fds[1]; | 101 uint16 port; |
| 102 uint8* buffer = reinterpret_cast<uint8*>(&port); |
| 103 ssize_t bytes_read = 0; |
| 104 ssize_t bytes_max = sizeof(port); |
| 105 base::TimeDelta remaining_time = base::TimeDelta::FromMilliseconds( |
| 106 TestTimeouts::action_max_timeout_ms()); |
| 107 base::Time previous_time = base::Time::Now(); |
| 108 while (bytes_read < bytes_max) { |
| 109 struct pollfd poll_fds[1]; |
102 | 110 |
103 poll_fds[0].fd = child_fd_; | 111 poll_fds[0].fd = child_fd_; |
104 poll_fds[0].events = POLLIN | POLLPRI; | 112 poll_fds[0].events = POLLIN | POLLPRI; |
105 poll_fds[0].revents = 0; | 113 poll_fds[0].revents = 0; |
106 | 114 |
107 int rv = HANDLE_EINTR(poll(poll_fds, 1, | 115 int rv = HANDLE_EINTR(poll(poll_fds, 1, remaining_time.InMilliseconds())); |
108 TestTimeouts::action_max_timeout_ms())); | 116 if (rv != 1) { |
109 if (rv != 1) { | 117 LOG(ERROR) << "Failed to poll for the child file descriptor."; |
110 LOG(ERROR) << "Failed to poll for the child file descriptor."; | 118 return false; |
111 return false; | 119 } |
| 120 |
| 121 base::Time current_time = base::Time::Now(); |
| 122 base::TimeDelta elapsed_time_cycle = current_time - previous_time; |
| 123 DCHECK(elapsed_time_cycle.InMilliseconds() >= 0); |
| 124 remaining_time -= elapsed_time_cycle; |
| 125 previous_time = current_time; |
| 126 |
| 127 ssize_t num_bytes = HANDLE_EINTR(read(child_fd_, buffer + bytes_read, |
| 128 bytes_max - bytes_read)); |
| 129 if (num_bytes <= 0) |
| 130 break; |
| 131 bytes_read += num_bytes; |
112 } | 132 } |
113 | 133 |
114 char buf[8]; | |
115 ssize_t n = HANDLE_EINTR(read(child_fd_, buf, sizeof(buf))); | |
116 // We don't need the FD anymore. | 134 // We don't need the FD anymore. |
117 child_fd_closer_.reset(NULL); | 135 child_fd_closer_.reset(NULL); |
118 return n > 0; | 136 if (bytes_read < bytes_max) |
| 137 return false; |
| 138 host_port_pair_.set_port(port); |
| 139 return true; |
119 } | 140 } |
120 | 141 |
121 bool TestServer::CheckCATrusted() { | 142 bool TestServer::CheckCATrusted() { |
122 return true; | 143 return true; |
123 } | 144 } |
124 | 145 |
125 } // namespace net | 146 } // namespace net |
OLD | NEW |