OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 QuicServer. It listens forever on --port | 5 // A binary wrapper for QuicServer. It listens forever on --port |
6 // (default 6121) until it's killed or ctrl-cd to death. | 6 // (default 6121) until it's killed or ctrl-cd to death. |
7 | 7 |
8 #include <iostream> | 8 #include <iostream> |
9 | 9 |
10 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.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/run_loop.h" | 14 #include "base/run_loop.h" |
15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
16 #include "net/base/ip_endpoint.h" | 16 #include "net/base/ip_endpoint.h" |
17 #include "net/quic/quic_protocol.h" | 17 #include "net/quic/quic_protocol.h" |
18 #include "net/quic/quic_server.h" | |
19 #include "net/tools/quic/quic_in_memory_cache.h" | 18 #include "net/tools/quic/quic_in_memory_cache.h" |
| 19 #include "net/tools/quic/quic_simple_server.h" |
20 | 20 |
21 // The port the quic server will listen on. | 21 // The port the quic server will listen on. |
22 int32 FLAGS_port = 6121; | 22 int32 FLAGS_port = 6121; |
23 | 23 |
24 int main(int argc, char *argv[]) { | 24 int main(int argc, char *argv[]) { |
25 base::AtExitManager exit_manager; | 25 base::AtExitManager exit_manager; |
26 base::MessageLoopForIO message_loop; | 26 base::MessageLoopForIO message_loop; |
27 | 27 |
28 base::CommandLine::Init(argc, argv); | 28 base::CommandLine::Init(argc, argv); |
29 base::CommandLine* line = base::CommandLine::ForCurrentProcess(); | 29 base::CommandLine* line = base::CommandLine::ForCurrentProcess(); |
(...skipping 10 matching lines...) Expand all Loading... |
40 "-h, --help show this help message and exit\n" | 40 "-h, --help show this help message and exit\n" |
41 "--port=<port> specify the port to listen on\n" | 41 "--port=<port> specify the port to listen on\n" |
42 "--quic_in_memory_cache_dir directory containing response data\n" | 42 "--quic_in_memory_cache_dir directory containing response data\n" |
43 " to load\n"; | 43 " to load\n"; |
44 std::cout << help_str; | 44 std::cout << help_str; |
45 exit(0); | 45 exit(0); |
46 } | 46 } |
47 | 47 |
48 if (line->HasSwitch("quic_in_memory_cache_dir")) { | 48 if (line->HasSwitch("quic_in_memory_cache_dir")) { |
49 net::tools::QuicInMemoryCache::GetInstance()->InitializeFromDirectory( | 49 net::tools::QuicInMemoryCache::GetInstance()->InitializeFromDirectory( |
50 line->GetSwitchValueNative("quic_in_memory_cache_dir")); | 50 line->GetSwitchValueASCII("quic_in_memory_cache_dir")); |
51 } | 51 } |
52 | 52 |
53 if (line->HasSwitch("port")) { | 53 if (line->HasSwitch("port")) { |
54 if (!base::StringToInt(line->GetSwitchValueASCII("port"), &FLAGS_port)) { | 54 if (!base::StringToInt(line->GetSwitchValueASCII("port"), &FLAGS_port)) { |
55 LOG(ERROR) << "--port must be an integer\n"; | 55 LOG(ERROR) << "--port must be an integer\n"; |
56 return 1; | 56 return 1; |
57 } | 57 } |
58 } | 58 } |
59 | 59 |
60 net::IPAddressNumber ip; | 60 net::IPAddressNumber ip; |
61 CHECK(net::ParseIPLiteralToNumber("::", &ip)); | 61 CHECK(net::ParseIPLiteralToNumber("::", &ip)); |
62 | 62 |
63 net::QuicConfig config; | 63 net::QuicConfig config; |
64 net::QuicServer server(config, net::QuicSupportedVersions()); | 64 net::tools::QuicSimpleServer server(config, net::QuicSupportedVersions()); |
65 | 65 |
66 int rc = server.Listen(net::IPEndPoint(ip, FLAGS_port)); | 66 int rc = server.Listen(net::IPEndPoint(ip, FLAGS_port)); |
67 if (rc < 0) { | 67 if (rc < 0) { |
68 return 1; | 68 return 1; |
69 } | 69 } |
70 | 70 |
71 base::RunLoop().Run(); | 71 base::RunLoop().Run(); |
72 | 72 |
73 return 0; | 73 return 0; |
74 } | 74 } |
OLD | NEW |