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

Side by Side Diff: net/tools/quic/quic_client_bin.cc

Issue 938853002: quic_client should check return codes when parsing command-line flags. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
« net/quic/quic_server_bin.cc ('K') | « net/quic/quic_server_bin.cc ('k') | no next file » | 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) 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 // A binary wrapper for QuicClient. 5 // A binary wrapper for QuicClient.
6 // Connects to a host using QUIC, sends a request to the provided URL, and 6 // Connects to a host using QUIC, sends a request to the provided URL, and
7 // displays the response. 7 // displays the response.
8 // 8 //
9 // Some usage examples: 9 // Some usage examples:
10 // 10 //
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 cout << help_str; 121 cout << help_str;
122 exit(0); 122 exit(0);
123 } 123 }
124 if (line->HasSwitch("host")) { 124 if (line->HasSwitch("host")) {
125 FLAGS_host = line->GetSwitchValueASCII("host"); 125 FLAGS_host = line->GetSwitchValueASCII("host");
126 } 126 }
127 if (line->HasSwitch("port")) { 127 if (line->HasSwitch("port")) {
128 int port; 128 int port;
129 if (base::StringToInt(line->GetSwitchValueASCII("port"), &port)) { 129 if (base::StringToInt(line->GetSwitchValueASCII("port"), &port)) {
130 FLAGS_port = port; 130 FLAGS_port = port;
131 } else {
132 std::cerr << "--port must be an integer\n";
133 return 1;
Ryan Hamilton 2015/02/18 23:51:13 Early return please: if (!base::StringToInt()) {
dougk 2015/02/19 00:29:19 Done.
131 } 134 }
132 } 135 }
133 if (line->HasSwitch("body")) { 136 if (line->HasSwitch("body")) {
134 FLAGS_body = line->GetSwitchValueASCII("body"); 137 FLAGS_body = line->GetSwitchValueASCII("body");
135 } 138 }
136 if (line->HasSwitch("headers")) { 139 if (line->HasSwitch("headers")) {
137 FLAGS_headers = line->GetSwitchValueASCII("headers"); 140 FLAGS_headers = line->GetSwitchValueASCII("headers");
138 } 141 }
139 if (line->HasSwitch("quiet")) { 142 if (line->HasSwitch("quiet")) {
140 FLAGS_quiet = true; 143 FLAGS_quiet = true;
(...skipping 22 matching lines...) Expand all
163 base::AtExitManager exit_manager; 166 base::AtExitManager exit_manager;
164 167
165 // Determine IP address to connect to from supplied hostname. 168 // Determine IP address to connect to from supplied hostname.
166 net::IPAddressNumber ip_addr; 169 net::IPAddressNumber ip_addr;
167 170
168 // TODO(rtenneti): GURL's doesn't support default_protocol argument, thus 171 // TODO(rtenneti): GURL's doesn't support default_protocol argument, thus
169 // protocol is required in the URL. 172 // protocol is required in the URL.
170 GURL url(urls[0]); 173 GURL url(urls[0]);
171 string host = FLAGS_host; 174 string host = FLAGS_host;
172 // TODO(rtenneti): get ip_addr from hostname by doing host resolution. 175 // TODO(rtenneti): get ip_addr from hostname by doing host resolution.
173 CHECK(!host.empty()); 176 if (host.empty()) {
174 net::ParseIPLiteralToNumber(host, &ip_addr); 177 LOG(ERROR) << "--host must be specified\n";
178 return 1;
179 }
180 if (!net::ParseIPLiteralToNumber(host, &ip_addr)) {
181 LOG(ERROR) << "--host could not be parsed as an IP address\n";
182 return 1;
183 }
175 184
176 string host_port = net::IPAddressToStringWithPort(ip_addr, FLAGS_port); 185 string host_port = net::IPAddressToStringWithPort(ip_addr, FLAGS_port);
177 VLOG(1) << "Resolved " << host << " to " << host_port << endl; 186 VLOG(1) << "Resolved " << host << " to " << host_port << endl;
178 187
179 // Build the client, and try to connect. 188 // Build the client, and try to connect.
180 bool is_https = (FLAGS_port == 443); 189 bool is_https = (FLAGS_port == 443);
181 net::EpollServer epoll_server; 190 net::EpollServer epoll_server;
182 net::QuicServerId server_id(host, FLAGS_port, is_https, 191 net::QuicServerId server_id(host, FLAGS_port, is_https,
183 net::PRIVACY_MODE_DISABLED); 192 net::PRIVACY_MODE_DISABLED);
184 net::QuicVersionVector versions = net::QuicSupportedVersions(); 193 net::QuicVersionVector versions = net::QuicSupportedVersions();
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 return 0; 280 return 0;
272 } else { 281 } else {
273 cout << "Request failed (redirect " << response_code << ")." << endl; 282 cout << "Request failed (redirect " << response_code << ")." << endl;
274 return 1; 283 return 1;
275 } 284 }
276 } else { 285 } else {
277 cerr << "Request failed (" << response_code << ")." << endl; 286 cerr << "Request failed (" << response_code << ")." << endl;
278 return 1; 287 return 1;
279 } 288 }
280 } 289 }
OLDNEW
« net/quic/quic_server_bin.cc ('K') | « net/quic/quic_server_bin.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698