Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Unified Diff: net/test/test_server_win.cc

Issue 5196001: Made testserver communicate to parent process with JSON (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed cbentzel's comments Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/test/test_server_win.cc
diff --git a/net/test/test_server_win.cc b/net/test/test_server_win.cc
index 64437cd46d6a2aa8348d67c8b63f0400a8b71d7c..09e7ac814e13401f8b39af31481f6c6e71ba8efe 100644
--- a/net/test/test_server_win.cc
+++ b/net/test/test_server_win.cc
@@ -145,7 +145,30 @@ bool TestServer::LaunchPython(const FilePath& testserver_path) {
return true;
}
+namespace {
+
+bool ReadData(bool* unblocked, HANDLE fd, DWORD bytes_max, uint8* buffer) {
+ 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))
+ return false;
+ if (num_bytes <= 0)
+ return false;
+ if (*unblocked)
+ return false;
+ bytes_read += num_bytes;
+ }
+ return true;
+}
+
+} // namespace
+
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;
@@ -153,36 +176,21 @@ bool TestServer::WaitToStart() {
// 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),
+ NewRunnableFunction(UnblockPipe, 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)
+ uint32 server_data_len = 0;
+ if (!ReadData(&unblocked, read_fd.Get(), sizeof(server_data_len),
+ reinterpret_cast<uint8*>(&server_data_len)))
+ return false;
+ std::string server_data(server_data_len, '\0');
+ if (!ReadData(&unblocked, read_fd.Get(), server_data_len,
+ reinterpret_cast<uint8*>(&server_data[0])))
return false;
- // If not enough bytes were read, fail.
- if (bytes_read < bytes_max)
+ if (!ParseServerData(server_data))
Paweł Hajdan Jr. 2010/11/18 10:35:12 nit: Similar comments apply: move anonymous namesp
akalin 2010/11/18 22:38:34 Done.
return false;
- host_port_pair_.set_port(port);
return true;
}

Powered by Google App Engine
This is Rietveld 408576698