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

Side by Side Diff: net/test/test_server_posix.cc

Issue 3368012: Wait on a pipe for the test server to start up (Closed)
Patch Set: Sigh. Rebase onto trunk. Created 10 years, 3 months 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 unified diff | Download patch
« no previous file with comments | « net/test/test_server.cc ('k') | net/test/test_server_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 10
(...skipping 14 matching lines...) Expand all
25 LOG(ERROR) << "Certificate path " << certificate_path.value() 25 LOG(ERROR) << "Certificate path " << certificate_path.value()
26 << " doesn't exist. Can't launch https server."; 26 << " doesn't exist. Can't launch https server.";
27 return false; 27 return false;
28 } 28 }
29 command_line.push_back("--https=" + certificate_path.value()); 29 command_line.push_back("--https=" + certificate_path.value());
30 } 30 }
31 31
32 if (type_ == TYPE_HTTPS_CLIENT_AUTH) 32 if (type_ == TYPE_HTTPS_CLIENT_AUTH)
33 command_line.push_back("--ssl-client-auth"); 33 command_line.push_back("--ssl-client-auth");
34 34
35 base::file_handle_mapping_vector no_mappings; 35 int pipefd[2];
36 if (!base::LaunchApp(command_line, no_mappings, false, &process_handle_)) { 36 if (pipe(pipefd) != 0) {
37 PLOG(ERROR) << "Could not create pipe.";
38 return false;
39 }
40
41 // Save the read half. The write half is sent to the child.
42 child_fd_ = pipefd[0];
43 child_fd_closer_.reset(&child_fd_);
44 file_util::ScopedFD write_closer(&pipefd[1]);
45 base::file_handle_mapping_vector map_write_fd;
46 map_write_fd.push_back(std::make_pair(pipefd[1], pipefd[1]));
47
48 command_line.push_back("--startup-pipe=" + base::IntToString(pipefd[1]));
49
50 if (!base::LaunchApp(command_line, map_write_fd, false, &process_handle_)) {
37 LOG(ERROR) << "Failed to launch " << command_line[0] << " ..."; 51 LOG(ERROR) << "Failed to launch " << command_line[0] << " ...";
38 return false; 52 return false;
39 } 53 }
40 54
41 return true; 55 return true;
42 } 56 }
43 57
58 bool TestServer::WaitToStart() {
59 char buf[8];
60 ssize_t n = HANDLE_EINTR(read(child_fd_, buf, sizeof(buf)));
61 // We don't need the FD anymore.
62 child_fd_closer_.reset(NULL);
63 return n > 0;
64 }
65
44 bool TestServer::CheckCATrusted() { 66 bool TestServer::CheckCATrusted() {
45 return true; 67 return true;
46 } 68 }
47 69
48 } // namespace net 70 } // namespace net
OLDNEW
« no previous file with comments | « net/test/test_server.cc ('k') | net/test/test_server_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698