- add sources.
[platform/framework/web/crosswalk.git] / src / net / tools / quic / quic_server_bin.cc
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
3 // found in the LICENSE file.
4 //
5 // A binary wrapper for QuicServer.  It listens forever on --port
6 // (default 6121) until it's killed or ctrl-cd to death.
7
8 #include <iostream>
9
10 #include "base/at_exit.h"
11 #include "base/basictypes.h"
12 #include "base/command_line.h"
13 #include "base/strings/string_number_conversions.h"
14 #include "net/base/ip_endpoint.h"
15 #include "net/tools/quic/quic_in_memory_cache.h"
16 #include "net/tools/quic/quic_server.h"
17
18 // The port the quic server will listen on.
19
20 int32 FLAGS_port = 6121;
21
22 int main(int argc, char *argv[]) {
23   CommandLine::Init(argc, argv);
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
38   if (line->HasSwitch("quic_in_memory_cache_dir")) {
39     net::tools::FLAGS_quic_in_memory_cache_dir =
40         line->GetSwitchValueASCII("quic_in_memory_cache_dir");
41   }
42
43   if (line->HasSwitch("port")) {
44     int port;
45     if (base::StringToInt(line->GetSwitchValueASCII("port"), &port)) {
46       FLAGS_port = port;
47     }
48   }
49
50   base::AtExitManager exit_manager;
51
52   net::IPAddressNumber ip;
53   CHECK(net::ParseIPLiteralToNumber("::", &ip));
54
55   net::tools::QuicServer server;
56
57   if (!server.Listen(net::IPEndPoint(ip, FLAGS_port))) {
58     return 1;
59   }
60
61   while (1) {
62     server.WaitForEvents();
63   }
64
65   return 0;
66 }