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> | 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/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
15 #include "net/base/ip_endpoint.h" | 16 #include "net/base/ip_endpoint.h" |
16 #include "net/tools/quic/quic_in_memory_cache.h" | 17 #include "net/quic/quic_in_memory_cache.h" |
17 #include "net/tools/quic/quic_server.h" | 18 #include "net/quic/quic_protocol.h" |
| 19 #include "net/quic/quic_server.h" |
| 20 |
| 21 const uint32 kServerInitialFlowControlWindow = 100 * net::kMaxPacketSize; |
18 | 22 |
19 // The port the quic server will listen on. | 23 // The port the quic server will listen on. |
20 | |
21 int32 FLAGS_port = 6121; | 24 int32 FLAGS_port = 6121; |
22 | 25 |
23 int main(int argc, char *argv[]) { | 26 int main(int argc, char *argv[]) { |
24 base::CommandLine::Init(argc, argv); | 27 base::CommandLine::Init(argc, argv); |
25 base::CommandLine* line = base::CommandLine::ForCurrentProcess(); | 28 base::CommandLine* line = base::CommandLine::ForCurrentProcess(); |
26 | 29 |
27 logging::LoggingSettings settings; | 30 logging::LoggingSettings settings; |
28 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | 31 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
29 CHECK(logging::InitLogging(settings)); | 32 CHECK(logging::InitLogging(settings)); |
30 | 33 |
31 if (line->HasSwitch("h") || line->HasSwitch("help")) { | 34 if (line->HasSwitch("h") || line->HasSwitch("help")) { |
32 const char* help_str = | 35 const char* help_str = |
33 "Usage: quic_server [options]\n" | 36 "Usage: quic_server [options]\n" |
34 "\n" | 37 "\n" |
35 "Options:\n" | 38 "Options:\n" |
36 "-h, --help show this help message and exit\n" | 39 "-h, --help show this help message and exit\n" |
37 "--port=<port> specify the port to listen on\n" | 40 "--port=<port> specify the port to listen on\n" |
38 "--quic_in_memory_cache_dir directory containing response data\n" | 41 "--quic_in_memory_cache_dir directory containing response data\n" |
39 " to load\n"; | 42 " to load\n"; |
40 std::cout << help_str; | 43 std::cout << help_str; |
41 exit(0); | 44 exit(0); |
42 } | 45 } |
43 | 46 |
44 if (line->HasSwitch("quic_in_memory_cache_dir")) { | 47 if (line->HasSwitch("quic_in_memory_cache_dir")) { |
45 net::tools::FLAGS_quic_in_memory_cache_dir = | 48 net::g_quic_in_memory_cache_dir = |
46 line->GetSwitchValueASCII("quic_in_memory_cache_dir"); | 49 line->GetSwitchValueNative("quic_in_memory_cache_dir"); |
47 } | 50 } |
48 | 51 |
49 if (line->HasSwitch("port")) { | 52 if (line->HasSwitch("port")) { |
50 int port; | 53 int port; |
51 if (base::StringToInt(line->GetSwitchValueASCII("port"), &port)) { | 54 if (base::StringToInt(line->GetSwitchValueASCII("port"), &port)) { |
52 FLAGS_port = port; | 55 FLAGS_port = port; |
53 } | 56 } |
54 } | 57 } |
55 | 58 |
56 base::AtExitManager exit_manager; | 59 base::AtExitManager exit_manager; |
57 | 60 |
| 61 base::MessageLoopForIO message_loop; |
| 62 |
58 net::IPAddressNumber ip; | 63 net::IPAddressNumber ip; |
59 CHECK(net::ParseIPLiteralToNumber("::", &ip)); | 64 CHECK(net::ParseIPLiteralToNumber("::", &ip)); |
60 | 65 |
61 net::tools::QuicServer server; | 66 net::QuicConfig config; |
| 67 config.SetDefaults(); |
62 | 68 |
63 if (!server.Listen(net::IPEndPoint(ip, FLAGS_port))) { | 69 net::QuicServer server(config, |
64 return 1; | 70 net::QuicSupportedVersions(), |
| 71 kServerInitialFlowControlWindow); |
| 72 |
| 73 int rc = server.Listen(net::IPEndPoint(ip, FLAGS_port)); |
| 74 if (rc < 0) { |
| 75 return -rc; |
65 } | 76 } |
66 | 77 |
67 while (1) { | 78 base::RunLoop().Run(); |
68 server.WaitForEvents(); | |
69 } | |
70 | 79 |
71 return 0; | 80 return 0; |
72 } | 81 } |
OLD | NEW |