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 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> |
| 9 |
8 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
9 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
10 #include "base/command_line.h" | 12 #include "base/command_line.h" |
11 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
12 #include "net/base/ip_endpoint.h" | 14 #include "net/base/ip_endpoint.h" |
13 #include "net/tools/quic/quic_in_memory_cache.h" | 15 #include "net/tools/quic/quic_in_memory_cache.h" |
14 #include "net/tools/quic/quic_server.h" | 16 #include "net/tools/quic/quic_server.h" |
15 | 17 |
16 // The port the quic server will listen on. | 18 // The port the quic server will listen on. |
17 | 19 |
18 int32 FLAGS_port = 6121; | 20 int32 FLAGS_port = 6121; |
19 | 21 |
20 int main(int argc, char *argv[]) { | 22 int main(int argc, char *argv[]) { |
21 CommandLine::Init(argc, argv); | 23 CommandLine::Init(argc, argv); |
22 CommandLine* line = CommandLine::ForCurrentProcess(); | 24 CommandLine* line = CommandLine::ForCurrentProcess(); |
| 25 if (line->HasSwitch("h") || line->HasSwitch("help")) { |
| 26 const char* help_str = |
| 27 "Usage: quic_server [options]\n" |
| 28 "\n" |
| 29 "Options:\n" |
| 30 "-h, --help show this help message and exit\n" |
| 31 "--port=<port> specify the port to listen on\n" |
| 32 "--quic_in_memory_cache_dir directory containing response data\n" |
| 33 " to load\n"; |
| 34 std::cout << help_str; |
| 35 exit(0); |
| 36 } |
| 37 |
23 if (line->HasSwitch("quic_in_memory_cache_dir")) { | 38 if (line->HasSwitch("quic_in_memory_cache_dir")) { |
24 net::tools::FLAGS_quic_in_memory_cache_dir = | 39 net::tools::FLAGS_quic_in_memory_cache_dir = |
25 line->GetSwitchValueASCII("quic_in_memory_cache_dir"); | 40 line->GetSwitchValueASCII("quic_in_memory_cache_dir"); |
26 } | 41 } |
27 | 42 |
28 if (line->HasSwitch("port")) { | 43 if (line->HasSwitch("port")) { |
29 int port; | 44 int port; |
30 if (base::StringToInt(line->GetSwitchValueASCII("port"), &port)) { | 45 if (base::StringToInt(line->GetSwitchValueASCII("port"), &port)) { |
31 FLAGS_port = port; | 46 FLAGS_port = port; |
32 } | 47 } |
33 } | 48 } |
34 | 49 |
35 base::AtExitManager exit_manager; | 50 base::AtExitManager exit_manager; |
36 | 51 |
37 net::IPAddressNumber ip; | 52 net::IPAddressNumber ip; |
38 CHECK(net::ParseIPLiteralToNumber("::", &ip)); | 53 CHECK(net::ParseIPLiteralToNumber("::", &ip)); |
39 | 54 |
40 net::tools::QuicServer server; | 55 net::tools::QuicServer server; |
41 | 56 |
42 if (!server.Listen(net::IPEndPoint(ip, FLAGS_port))) { | 57 if (!server.Listen(net::IPEndPoint(ip, FLAGS_port))) { |
43 return 1; | 58 return 1; |
44 } | 59 } |
45 | 60 |
46 while (1) { | 61 while (1) { |
47 server.WaitForEvents(); | 62 server.WaitForEvents(); |
48 } | 63 } |
49 | 64 |
50 return 0; | 65 return 0; |
51 } | 66 } |
OLD | NEW |