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 // A binary wrapper for QuicClient. Connects to --hostname on | 5 // A binary wrapper for QuicClient. Connects to --hostname on |
6 // --port and requests URLs specified on the command line. | 6 // --port and requests URLs specified on the command line. |
ramant (doing other things)
2013/05/22 22:56:08
nit: consider updating the comment in line#6.
honghaiz
2013/05/23 16:59:08
I revised the comments but is that what you want?
| |
7 // | 7 // |
8 // For example: | 8 // For example: |
9 // quic_client --port 6122 /index.html /favicon.ico | 9 // quic_client --port 6122 /index.html /favicon.ico |
10 | 10 |
11 #include "base/at_exit.h" | 11 #include "base/at_exit.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/strings/string_number_conversions.h" | |
14 #include "net/base/ip_endpoint.h" | 15 #include "net/base/ip_endpoint.h" |
15 #include "net/tools/quic/quic_client.h" | 16 #include "net/tools/quic/quic_client.h" |
16 | 17 |
17 int32 FLAGS_port = 6121; | 18 int32 FLAGS_port = 6121; |
18 std::string FLAGS_address = "127.0.0.1"; | 19 std::string FLAGS_address = "127.0.0.1"; |
19 std::string FLAGS_hostname = "localhost"; | 20 std::string FLAGS_hostname = "localhost"; |
20 | 21 |
21 int main(int argc, char *argv[]) { | 22 int main(int argc, char *argv[]) { |
22 CommandLine::Init(argc, argv); | 23 CommandLine::Init(argc, argv); |
23 | 24 CommandLine* line = CommandLine::ForCurrentProcess(); |
25 if (line->HasSwitch("port")) { | |
26 int port; | |
27 if (base::StringToInt(line->GetSwitchValueASCII("port"), &port)) { | |
28 FLAGS_port = port; | |
29 } | |
30 } | |
31 if (line->HasSwitch("address")) { | |
32 FLAGS_address = line->GetSwitchValueASCII("address"); | |
33 } | |
34 if (line->HasSwitch("hostname")) { | |
35 FLAGS_hostname = line->GetSwitchValueASCII("hostname"); | |
36 } | |
37 LOG(INFO) << "server port: " << FLAGS_port | |
38 << " address: " << FLAGS_address | |
39 << " hostname: " << FLAGS_hostname; | |
24 | 40 |
25 base::AtExitManager exit_manager; | 41 base::AtExitManager exit_manager; |
26 | 42 |
27 net::IPAddressNumber addr; | 43 net::IPAddressNumber addr; |
28 CHECK(net::ParseIPLiteralToNumber(FLAGS_address, &addr)); | 44 CHECK(net::ParseIPLiteralToNumber(FLAGS_address, &addr)); |
29 net::tools::QuicClient client( | 45 net::tools::QuicClient client( |
30 net::IPEndPoint(addr, FLAGS_port), FLAGS_hostname); | 46 net::IPEndPoint(addr, FLAGS_port), FLAGS_hostname); |
31 | 47 |
32 client.Initialize(); | 48 client.Initialize(); |
33 | 49 |
34 if (!client.Connect()) return 1; | 50 if (!client.Connect()) return 1; |
35 | 51 |
36 client.SendRequestsAndWaitForResponse(argc, argv); | 52 client.SendRequestsAndWaitForResponse(argc, argv); |
37 return 0; | 53 return 0; |
38 } | 54 } |
OLD | NEW |