OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/spawned_test_server/local_test_server.h" | 5 #include "net/test/spawned_test_server/local_test_server.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 HANDLE child_read = NULL; | 94 HANDLE child_read = NULL; |
95 HANDLE child_write = NULL; | 95 HANDLE child_write = NULL; |
96 if (!CreatePipe(&child_read, &child_write, NULL, 0)) { | 96 if (!CreatePipe(&child_read, &child_write, NULL, 0)) { |
97 PLOG(ERROR) << "Failed to create pipe"; | 97 PLOG(ERROR) << "Failed to create pipe"; |
98 return false; | 98 return false; |
99 } | 99 } |
100 child_read_fd_.Set(child_read); | 100 child_read_fd_.Set(child_read); |
101 child_write_fd_.Set(child_write); | 101 child_write_fd_.Set(child_write); |
102 | 102 |
103 // Have the child inherit the write half. | 103 // Have the child inherit the write half. |
104 if (!SetHandleInformation(child_write, HANDLE_FLAG_INHERIT, | 104 if (!::DuplicateHandle(::GetCurrentProcess(), child_write, |
105 HANDLE_FLAG_INHERIT)) { | 105 ::GetCurrentProcess(), &child_write, 0, TRUE, |
| 106 DUPLICATE_SAME_ACCESS)) { |
106 PLOG(ERROR) << "Failed to enable pipe inheritance"; | 107 PLOG(ERROR) << "Failed to enable pipe inheritance"; |
107 return false; | 108 return false; |
108 } | 109 } |
109 | 110 |
110 // Pass the handle on the command-line. Although HANDLE is a | 111 // Pass the handle on the command-line. Although HANDLE is a |
111 // pointer, truncating it on 64-bit machines is okay. See | 112 // pointer, truncating it on 64-bit machines is okay. See |
112 // http://msdn.microsoft.com/en-us/library/aa384203.aspx | 113 // http://msdn.microsoft.com/en-us/library/aa384203.aspx |
113 // | 114 // |
114 // "64-bit versions of Windows use 32-bit handles for | 115 // "64-bit versions of Windows use 32-bit handles for |
115 // interoperability. When sharing a handle between 32-bit and 64-bit | 116 // interoperability. When sharing a handle between 32-bit and 64-bit |
116 // applications, only the lower 32 bits are significant, so it is | 117 // applications, only the lower 32 bits are significant, so it is |
117 // safe to truncate the handle (when passing it from 64-bit to | 118 // safe to truncate the handle (when passing it from 64-bit to |
118 // 32-bit) or sign-extend the handle (when passing it from 32-bit to | 119 // 32-bit) or sign-extend the handle (when passing it from 32-bit to |
119 // 64-bit)." | 120 // 64-bit)." |
120 python_command.AppendArg("--startup-pipe=" + | 121 python_command.AppendArg("--startup-pipe=" + |
121 base::IntToString(reinterpret_cast<uintptr_t>(child_write))); | 122 base::IntToString(reinterpret_cast<uintptr_t>(child_write))); |
122 | 123 |
123 base::LaunchOptions launch_options; | 124 base::LaunchOptions launch_options; |
124 launch_options.inherit_handles = true; | 125 launch_options.inherit_handles = true; |
125 process_ = base::LaunchProcess(python_command, launch_options); | 126 process_ = base::LaunchProcess(python_command, launch_options); |
126 if (!process_.IsValid()) { | 127 if (!process_.IsValid()) { |
127 LOG(ERROR) << "Failed to launch " << python_command.GetCommandLineString(); | 128 LOG(ERROR) << "Failed to launch " << python_command.GetCommandLineString(); |
| 129 ::CloseHandle(child_write); |
128 return false; | 130 return false; |
129 } | 131 } |
130 | 132 |
| 133 ::CloseHandle(child_write); |
131 return true; | 134 return true; |
132 } | 135 } |
133 | 136 |
134 bool LocalTestServer::WaitToStart() { | 137 bool LocalTestServer::WaitToStart() { |
135 base::win::ScopedHandle read_fd(child_read_fd_.Take()); | 138 base::win::ScopedHandle read_fd(child_read_fd_.Take()); |
136 base::win::ScopedHandle write_fd(child_write_fd_.Take()); | 139 base::win::ScopedHandle write_fd(child_write_fd_.Take()); |
137 | 140 |
138 uint32 server_data_len = 0; | 141 uint32 server_data_len = 0; |
139 if (!ReadData(read_fd.Get(), write_fd.Get(), sizeof(server_data_len), | 142 if (!ReadData(read_fd.Get(), write_fd.Get(), sizeof(server_data_len), |
140 reinterpret_cast<uint8*>(&server_data_len))) { | 143 reinterpret_cast<uint8*>(&server_data_len))) { |
(...skipping 11 matching lines...) Expand all Loading... |
152 if (!ParseServerData(server_data)) { | 155 if (!ParseServerData(server_data)) { |
153 LOG(ERROR) << "Could not parse server_data: " << server_data; | 156 LOG(ERROR) << "Could not parse server_data: " << server_data; |
154 return false; | 157 return false; |
155 } | 158 } |
156 | 159 |
157 return true; | 160 return true; |
158 } | 161 } |
159 | 162 |
160 } // namespace net | 163 } // namespace net |
161 | 164 |
OLD | NEW |