summaryrefslogtreecommitdiffstats
path: root/net/test/test_server_win.cc
diff options
context:
space:
mode:
authorakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-25 07:54:10 +0000
committerakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-25 07:54:10 +0000
commitf73ecb005462a2d7de56979ef9168452559ea71c (patch)
tree01df584fe7872bb556407ed6b656199881777ec5 /net/test/test_server_win.cc
parent2ff778c5748038872c0c6b7df04c834b005167fa (diff)
downloadchromium_src-f73ecb005462a2d7de56979ef9168452559ea71c.zip
chromium_src-f73ecb005462a2d7de56979ef9168452559ea71c.tar.gz
chromium_src-f73ecb005462a2d7de56979ef9168452559ea71c.tar.bz2
Revert 67386 - Made testserver communicate to parent process with JSON
This is so that if the testserver needs to communicate anything more than the port in the future (e.g., xmpp port for the test sync server), it can do so in a flexible manner. BUG=53934 TEST=manually Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=66879 Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=67018 Review URL: http://codereview.chromium.org/5196001 TBR=akalin@chromium.org Review URL: http://codereview.chromium.org/5343003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67393 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/test/test_server_win.cc')
-rw-r--r--net/test/test_server_win.cc82
1 files changed, 34 insertions, 48 deletions
diff --git a/net/test/test_server_win.cc b/net/test/test_server_win.cc
index 0593b7e1..a363755 100644
--- a/net/test/test_server_win.cc
+++ b/net/test/test_server_win.cc
@@ -86,45 +86,6 @@ void UnblockPipe(HANDLE handle, bool* unblocked) {
*unblocked = true;
}
-// Given a file handle, reads into |buffer| until |bytes_max| bytes
-// has been read or an error has been encountered. Returns
-// true if the read was successful.
-bool ReadData(HANDLE fd, DWORD bytes_max, uint8* buffer) {
- base::Thread thread("test_server_watcher");
- if (!thread.Start())
- return false;
-
- // Prepare a timeout in case the server fails to start.
- bool unblocked = false;
- thread.message_loop()->PostDelayedTask(FROM_HERE,
- NewRunnableFunction(UnblockPipe, fd, &unblocked),
- TestTimeouts::action_max_timeout_ms());
-
- DWORD bytes_read = 0;
- while (bytes_read < bytes_max) {
- DWORD num_bytes;
- if (!ReadFile(fd, buffer + bytes_read, bytes_max - bytes_read,
- &num_bytes, NULL)) {
- PLOG(ERROR) << "ReadFile failed";
- return false;
- }
- if (num_bytes <= 0) {
- LOG(ERROR) << "ReadFile returned invalid byte count: " << num_bytes;
- return false;
- }
- bytes_read += num_bytes;
- }
-
- thread.Stop();
- // If the timeout kicked in, abort.
- if (unblocked) {
- LOG(ERROR) << "Timeout exceeded for ReadData";
- return false;
- }
-
- return true;
-}
-
} // namespace
namespace net {
@@ -185,19 +146,44 @@ bool TestServer::LaunchPython(const FilePath& testserver_path) {
}
bool TestServer::WaitToStart() {
- ScopedHandle read_fd(child_read_fd_.Take());
- ScopedHandle write_fd(child_write_fd_.Take());
+ base::Thread thread("test_server_watcher");
+ if (!thread.Start())
+ return false;
- uint32 server_data_len = 0;
- if (!ReadData(read_fd.Get(), sizeof(server_data_len),
- reinterpret_cast<uint8*>(&server_data_len)))
+ // Prepare a timeout in case the server fails to start.
+ bool unblocked = false;
+ thread.message_loop()->PostDelayedTask(FROM_HERE,
+ NewRunnableFunction(UnblockPipe, child_write_fd_.Get(), &unblocked),
+ TestTimeouts::action_max_timeout_ms());
+
+ // Try to read two bytes from the pipe indicating the ephemeral port number.
+ uint16 port;
+ uint8* buffer = reinterpret_cast<uint8*>(&port);
+ DWORD bytes_read = 0;
+ DWORD bytes_max = sizeof(port);
+ while (bytes_read < bytes_max) {
+ DWORD num_bytes;
+ if (!ReadFile(child_read_fd_, buffer + bytes_read, bytes_max - bytes_read,
+ &num_bytes, NULL))
+ break;
+ if (num_bytes <= 0)
+ break;
+ bytes_read += num_bytes;
+ }
+ thread.Stop();
+ child_read_fd_.Close();
+ child_write_fd_.Close();
+
+ // If we hit the timeout, fail.
+ if (unblocked)
return false;
- std::string server_data(server_data_len, '\0');
- if (!ReadData(read_fd.Get(), server_data_len,
- reinterpret_cast<uint8*>(&server_data[0])))
+
+ // If not enough bytes were read, fail.
+ if (bytes_read < bytes_max)
return false;
- return ParseServerData(server_data);
+ host_port_pair_.set_port(port);
+ return true;
}
bool TestServer::CheckCATrusted() {