summaryrefslogtreecommitdiffstats
path: root/net/test/test_server_posix.cc
diff options
context:
space:
mode:
authorcbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-11 20:31:31 +0000
committercbentzel@chromium.org <cbentzel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-11 20:31:31 +0000
commitfd6cfaf721f4da81f4fb19983b73f96c1005f0d8 (patch)
treee85638342ec6e69f72eee8522f4127dcd5dfbfe5 /net/test/test_server_posix.cc
parent09c1973dd93208a0d1d96c8b095dcf9c7cb10043 (diff)
downloadchromium_src-fd6cfaf721f4da81f4fb19983b73f96c1005f0d8.zip
chromium_src-fd6cfaf721f4da81f4fb19983b73f96c1005f0d8.tar.gz
chromium_src-fd6cfaf721f4da81f4fb19983b73f96c1005f0d8.tar.bz2
testserver.py listens on ephemeral ports by default.
If --port is specified on the command line, testserver.py will listen on that port, otherwise it will listen on an ephemeral port. If --startup_pipe is specified, the port number is written to the pipe as a 2 byte unsigned int in host order. TestServer spawns testserver.py to listen on an ephemeral port and reads the port value from the pipe. A fixed port can not be specified. BUG=56814 TEST=try bots pass Review URL: http://codereview.chromium.org/4733005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65843 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/test/test_server_posix.cc')
-rw-r--r--net/test/test_server_posix.cc47
1 files changed, 34 insertions, 13 deletions
diff --git a/net/test/test_server_posix.cc b/net/test/test_server_posix.cc
index 707eb93..9c0210b 100644
--- a/net/test/test_server_posix.cc
+++ b/net/test/test_server_posix.cc
@@ -98,24 +98,45 @@ bool TestServer::LaunchPython(const FilePath& testserver_path) {
}
bool TestServer::WaitToStart() {
- struct pollfd poll_fds[1];
-
- poll_fds[0].fd = child_fd_;
- poll_fds[0].events = POLLIN | POLLPRI;
- poll_fds[0].revents = 0;
+ uint16 port;
+ uint8* buffer = reinterpret_cast<uint8*>(&port);
+ ssize_t bytes_read = 0;
+ ssize_t bytes_max = sizeof(port);
+ base::TimeDelta remaining_time = base::TimeDelta::FromMilliseconds(
+ TestTimeouts::action_max_timeout_ms());
+ base::Time previous_time = base::Time::Now();
+ while (bytes_read < bytes_max) {
+ struct pollfd poll_fds[1];
+
+ poll_fds[0].fd = child_fd_;
+ poll_fds[0].events = POLLIN | POLLPRI;
+ poll_fds[0].revents = 0;
+
+ int rv = HANDLE_EINTR(poll(poll_fds, 1, remaining_time.InMilliseconds()));
+ if (rv != 1) {
+ LOG(ERROR) << "Failed to poll for the child file descriptor.";
+ return false;
+ }
- int rv = HANDLE_EINTR(poll(poll_fds, 1,
- TestTimeouts::action_max_timeout_ms()));
- if (rv != 1) {
- LOG(ERROR) << "Failed to poll for the child file descriptor.";
- return false;
+ base::Time current_time = base::Time::Now();
+ base::TimeDelta elapsed_time_cycle = current_time - previous_time;
+ DCHECK(elapsed_time_cycle.InMilliseconds() >= 0);
+ remaining_time -= elapsed_time_cycle;
+ previous_time = current_time;
+
+ ssize_t num_bytes = HANDLE_EINTR(read(child_fd_, buffer + bytes_read,
+ bytes_max - bytes_read));
+ if (num_bytes <= 0)
+ break;
+ bytes_read += num_bytes;
}
- char buf[8];
- ssize_t n = HANDLE_EINTR(read(child_fd_, buf, sizeof(buf)));
// We don't need the FD anymore.
child_fd_closer_.reset(NULL);
- return n > 0;
+ if (bytes_read < bytes_max)
+ return false;
+ host_port_pair_.set_port(port);
+ return true;
}
bool TestServer::CheckCATrusted() {