OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/test_server.h" | 5 #include "net/test/test_server.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <wincrypt.h> | 8 #include <wincrypt.h> |
9 | 9 |
10 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
| 11 #include "base/bind.h" |
11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
12 #include "base/file_util.h" | 13 #include "base/file_util.h" |
13 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
14 #include "base/path_service.h" | 15 #include "base/path_service.h" |
15 #include "base/string_number_conversions.h" | 16 #include "base/string_number_conversions.h" |
16 #include "base/string_util.h" | 17 #include "base/string_util.h" |
17 #include "base/test/test_timeouts.h" | 18 #include "base/test/test_timeouts.h" |
18 #include "base/threading/thread.h" | 19 #include "base/threading/thread.h" |
19 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
20 #include "base/win/scoped_handle.h" | 21 #include "base/win/scoped_handle.h" |
(...skipping 22 matching lines...) Expand all Loading... |
43 // true if the read was successful. | 44 // true if the read was successful. |
44 bool ReadData(HANDLE read_fd, HANDLE write_fd, | 45 bool ReadData(HANDLE read_fd, HANDLE write_fd, |
45 DWORD bytes_max, uint8* buffer) { | 46 DWORD bytes_max, uint8* buffer) { |
46 base::Thread thread("test_server_watcher"); | 47 base::Thread thread("test_server_watcher"); |
47 if (!thread.Start()) | 48 if (!thread.Start()) |
48 return false; | 49 return false; |
49 | 50 |
50 // Prepare a timeout in case the server fails to start. | 51 // Prepare a timeout in case the server fails to start. |
51 bool unblocked = false; | 52 bool unblocked = false; |
52 thread.message_loop()->PostDelayedTask( | 53 thread.message_loop()->PostDelayedTask( |
53 FROM_HERE, | 54 FROM_HERE, base::Bind(UnblockPipe, write_fd, bytes_max, &unblocked), |
54 NewRunnableFunction(UnblockPipe, write_fd, bytes_max, &unblocked), | |
55 TestTimeouts::action_timeout_ms()); | 55 TestTimeouts::action_timeout_ms()); |
56 | 56 |
57 DWORD bytes_read = 0; | 57 DWORD bytes_read = 0; |
58 while (bytes_read < bytes_max) { | 58 while (bytes_read < bytes_max) { |
59 DWORD num_bytes; | 59 DWORD num_bytes; |
60 if (!ReadFile(read_fd, buffer + bytes_read, bytes_max - bytes_read, | 60 if (!ReadFile(read_fd, buffer + bytes_read, bytes_max - bytes_read, |
61 &num_bytes, NULL)) { | 61 &num_bytes, NULL)) { |
62 PLOG(ERROR) << "ReadFile failed"; | 62 PLOG(ERROR) << "ReadFile failed"; |
63 return false; | 63 return false; |
64 } | 64 } |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 | 172 |
173 if (!ParseServerData(server_data)) { | 173 if (!ParseServerData(server_data)) { |
174 LOG(ERROR) << "Could not parse server_data: " << server_data; | 174 LOG(ERROR) << "Could not parse server_data: " << server_data; |
175 return false; | 175 return false; |
176 } | 176 } |
177 | 177 |
178 return true; | 178 return true; |
179 } | 179 } |
180 | 180 |
181 } // namespace net | 181 } // namespace net |
OLD | NEW |