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

Unified Diff: net/test/test_server_win.cc

Issue 4136008: testserver.py listens on ephemeral ports by default. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Respond to latest round of 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
« no previous file with comments | « net/test/test_server_posix.cc ('k') | net/tools/testserver/testserver.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/test/test_server_win.cc
diff --git a/net/test/test_server_win.cc b/net/test/test_server_win.cc
index c6e10d5bbc61d2d6cac8b5e69fa3b9e2a3bfe64b..64437cd46d6a2aa8348d67c8b63f0400a8b71d7c 100644
--- a/net/test/test_server_win.cc
+++ b/net/test/test_server_win.cc
@@ -156,11 +156,20 @@ bool TestServer::WaitToStart() {
NewRunnableFunction(UnblockPipe, child_write_fd_.Get(), &unblocked),
TestTimeouts::action_max_timeout_ms());
- char buf[8];
- DWORD bytes_read;
- BOOL result = ReadFile(child_read_fd_.Get(), buf, sizeof(buf), &bytes_read,
- NULL);
-
+ // 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();
@@ -169,7 +178,12 @@ bool TestServer::WaitToStart() {
if (unblocked)
return false;
- return result && bytes_read > 0;
+ // If not enough bytes were read, fail.
+ if (bytes_read < bytes_max)
+ return false;
+
+ host_port_pair_.set_port(port);
+ return true;
}
bool TestServer::CheckCATrusted() {
« no previous file with comments | « net/test/test_server_posix.cc ('k') | net/tools/testserver/testserver.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698